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!