I get complex numbers when I manipulate an FFT spectrum

3 views (last 30 days)
I have generated data in a FFT spectrum with this code. I want to filter out the fundamental frequency (set it to near 0) to then display the current oscillation without the fundamental oscillation.
The problem is that after reducing the values to 1e-15 (to be able to neglect them) I get complex values in the back transformation. Decreasing or increasing the range of values gives the same result.
Now the question would be whether it is at all possible to implement my project, or what must be done so that it works.
T = 250000;
f = 1/T
L = length(FILE00000132.MessNameSprung2);
VoltageL1 = FILE00000132.MessNameSprung2; %Current
YFFT = fft(CurrentL1);
P2 = abs(YFFT/L);
P1 = P2(1:L/2+1);
P1(2:length(P1)-1) = 2*P1(2:length(P1)-1);
f = T * (0:(L/2))/L;
plot(f,P1)
xlim([0 1000])
loglog(f,P1)
%YIFFT1 = ifft(YFFT)
YFFT(2:100) = 1e-15;
YFFT(356866:356966) =1e-15 %Set the values to 1e-15 to be able to neglect them
P2 = abs(YFFT/L);
P1 = P2(1:L/2+1);
P1(2:length(P1)-1) = 2*P1(2:length(P1)-1);
plot(f , P1 )
xlim([0 500])
loglog(f,P1)
YIFFT = ifft(Y); %Resulting in complex numbers
plot(f,YIFFT)
I have already read similar contributions to the FFT, but have not yet found what I was looking for with my problem.

Answers (1)

Star Strider
Star Strider on 13 Dec 2022
The easiest way to do this is with a bandstop or notch filter in the time domain.
If you must do it in the frequency domain, first use the fftshift function, and then zero-out the corresponding signal at the positive and negative frequencies. Then use ifftshift on that result, and calculate the ifft from it. That should work. There may still be imaginary values after that, however they should be vanishingly small, so you can just ignore them using the real function.
.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!