FFT using excel data

42 ビュー (過去 30 日間)
P Sahir
P Sahir 2020 年 3 月 31 日
コメント済み: dpb 2020 年 4 月 1 日
I have a excel file which has time and amplitude. I have used fft to convert it into frequency domain. After converting, I am getting a big vertical line at zero frequency. Why is it so? How to rectify it?
The code I have used is as follows:
data = xlsread('C:\Users\psahi\Desktop\New Microsoft Excel Worksheet.xlsx');
time = data(:,1);
amp = data(:,2);
L = length(amp);
Ts = mean(diff(time));
Fs = 1/Ts;
NFFT = 2^nextpow2(L);
Y = fft(amp,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)));

回答 (1 件)

dpb
dpb 2020 年 3 月 31 日
編集済み: dpb 2020 年 3 月 31 日
0Hz is the DC component...if your signal is not zero mean, then the mean will be the DC component.
To eliminate it, subtract the mean before taking FFT.
Your power normalization doubles the computed DC, however, by multiplying the whole one-sided frequency region by two; there are only one DC and one Fmax bins not two so all the energy in those two bins is already there prior to accounting for the rest of the energy being split between positive/negative frequency.
As shown in the example at doc fft, use
P2 = abs(Y/NFFT);
P1 = P2(1:NFFT/2+1);
P1(2:end-1) = 2*P1(2:end-1);
or code to the equivalent instead of
2*abs(Y(1:NFFT/2+1))
  4 件のコメント
dpb
dpb 2020 年 4 月 1 日
Using the example from doc fft w/o noise so values are easily compared to exact known values visually, observe the results from:
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); % Noise-free signal two components
Y = fft(S);P2 = abs(Y/L); % FFT, 2-Sided PSD
P1 = P2(1:L/2+1); % 1-Sided PSD
P1(2:end-1) = 2*P1(2:end-1); % Normalization; don't double DC, Fmax
plot(f,P1) % Visualize; note peaks 0.7, 1.0
hold on
S=S+1; % Add a DC component to signal
Y = fft(S);P2 = abs(Y/L); % Repeat analysis as above identically...
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
plot(f,P1,'r:') % Plot so see difference...
ylim([0 1.05]) % arrange axes away from origin
xlim([-5 500]) % and peak a little for clarity
legend('Zero Mean','1.0 DC') % identify which is which
results in the following figure. NB: the DC component doesn't alter the two real peaks but shows up at 0 Hz as expected...
Now, remove the DC first...
figure
plot(f,P1) % PSD w/ the DC component
xlim([-5 500])
ylim([0 1.05])
hold on
Y = fft(S-mean(S));P2 = abs(Y/L); % Now subtract the mean() before FFT to remove DC
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
plot(f,P1,'r:'); % Again add on top
plot(f(1),P1(1),'*','MarkerSize',10); % Mark the DC component uniquely
legend('1.0 DC','Mean Subtracted')
which results in
which shows the DC component has been removed from the FFT/PSD by having subtracted the mean of the time signal first leaving the other components unaltered. Just simply has to be...
Noise will add some other artifacts and signals that aren't aligned precisely on the center of an FFT bin will cause spreading of the peaks, but this illustrates the basic effect.
dpb
dpb 2020 年 4 月 1 日
You've not shown time signal but if you don't have a stationary signal, you may find detrending or other baseline-normalization techniques useful first as well as or instead of just removing the mean.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by