I get complex numbers when I manipulate an FFT spectrum
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Star Strider
2022-12-13
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.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!