Effacer les filtres
Effacer les filtres

FFT: Detrend not removing 0 Hz component?

2 vues (au cours des 30 derniers jours)
Desiree Phillips
Desiree Phillips le 15 Avr 2013
Commenté : Wayne King le 30 Déc 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 commentaire
Wayne King
Wayne King le 30 Déc 2013
Can you attach the data, or is it too big? How about just one column.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by