FFT: Detrend not removing 0 Hz component?

1 visualizzazione (ultimi 30 giorni)
Desiree Phillips
Desiree Phillips il 15 Apr 2013
Commentato: Wayne King il 30 Dic 2013
I have a data vector that I am trying to use fft on. I've read in other answers that the 0 Hz component comes from the mean so I need to detrend the data. The following lines should work:
detrend(data,0) or detrend(data,'constant')
but there is no visible change in my output: the 0 Hz component still dominates significantly. If it helps, the vector contains electrical grid frequency values over time. Here is my code:
% FFT Variable Initializations
Fs = 10; % 10 Hz sampling frequency
[nrows,ncols]=size(data); % Data size
NFFT = 2^nextpow2(nrows); % Next power of 2 from nrows of data
% Perform FFT Analysis on each column
linespec = {'r' 'g' 'b' 'c' 'm' 'y' 'k' '-k'};
for i =1:length(linespec)
% Detrend the data
dtr_data = detrend(data(~isnan(data(:,i)),i),'constant');
% Perform FFT on detrended data
fft_data = fft(dtr_data,NFFT)/nrows;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(fft_data(1:NFFT/2+1)),linespec{i})
hold on
end
Thanks in advance for all the help.
  1 Commento
Wayne King
Wayne King il 30 Dic 2013
Can you attach the data, or is it too big? How about just one column.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by