I get complex numbers when I manipulate an FFT spectrum

조회 수: 3 (최근 30일)
Wolfi
Wolfi 2022년 12월 13일
답변: Star Strider 2022년 12월 13일
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.

답변 (1개)

Star Strider
Star Strider 2022년 12월 13일
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.
.

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by