필터 지우기
필터 지우기

wny fft does't work with different signal?

조회 수: 3 (최근 30일)
nirwana
nirwana 2023년 8월 22일
답변: Star Strider 2023년 8월 22일
I am using fft to extract freq content in my two type of time series. First, time series (file sig_fft.txt) look good and showing some speaktral peak. but unfortunately for second time series (event.txt) no single spectral appear. I even using IFFT as checking wheater fft result can get back the original signal. For me seems FFT is work well. But I still wonder why my FFT having strange result on second one. Can anyone explain why ? Or do I make something wrong in my coding?
Second thing, I wonder about the amplitude on freq domain, does it shoul be the same in the time domain? I read several literature taht it relates to power which is square of amplitude, but why some coding that i found abot fft using 2*abs(fft_result)?
please help this beginner to get more about fft
here modification the code and time series that I use
%PERFORM FFT of data TO GET FREQ CONTENT
data=load("event.txt");
n=length(data(:,1));
srate=1000; %sampling rate
nyq=srate/2;
dataX=fft(data(:,2))/n;
hz=linspace(0,nyq,floor(n/2)+1);
figure (1)
subplot(211)
plot(data(:,1),data(:,2))
xlabel('Time(sec)'), ylabel('Amplitude')
subplot(212)
plot(hz,2*abs(dataX(1:length(hz))),'-r'), xlabel('Freq(Hz)')
%set(gca,'XLim',[0 2],'YLim',[0 100])
%Perform IFFT TO CONSTRUCT ORIGINAL SIGNAL
recon_data=ifft(dataX)*n;
figure(2)
subplot(211)
plot(data(:,1),data(:,2)), xlabel('Time(sec)')
legend('original data')
title('inverse fourier transform')
subplot(212)
plot(data(:,1),real(recon_data),'-r')
legend('reconstruction data')

채택된 답변

Star Strider
Star Strider 2023년 8월 22일
Thbere is a farily significant D-C or constant offset in ‘data(:,2)’ and that hides all the spectral peaks of lower magnitudes.
The eassiest way to avoid this is to subtract the D-C offset value (that is actually the mean value of the signal) before calculating the fft:
dataX=fft(data(:,2)-mean(data(:,2)))/n;
that I did here. The spectral peak at about 225 Hz becomes visible. There is nothing wrong with your code (that I can see).
Second thing, I wonder about the amplitude on freq domain, does it shoul be the same in the time domain?
It will be close, however the energy in the signal is distributed over a wide spectrum, so it will rarely be exactly the same. There is also the problem that the fft may not calculate a frequency at exactly the frequency of a particular signal component, so that energy may be spread over a short range of adjacent frequuencies.
Try this —
%PERFORM FFT of data TO GET FREQ CONTENT
data=load("event.txt");
n=length(data(:,1));
srate=1000; %sampling rate
nyq=srate/2;
dataX=fft(data(:,2)-mean(data(:,2)))/n;
hz=linspace(0,nyq,floor(n/2)+1);
figure (1)
subplot(211)
plot(data(:,1),data(:,2))
xlabel('Time(sec)'), ylabel('Amplitude')
subplot(212)
plot(hz,2*abs(dataX(1:length(hz))),'-r'), xlabel('Freq(Hz)')
%set(gca,'XLim',[0 2],'YLim',[0 100])
%Perform IFFT TO CONSTRUCT ORIGINAL SIGNAL
recon_data=ifft(dataX)*n;
figure(2)
subplot(211)
plot(data(:,1),data(:,2)), xlabel('Time(sec)')
legend('original data')
title('inverse fourier transform')
subplot(212)
plot(data(:,1),real(recon_data),'-r')
legend('reconstruction data')
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by