FFT: Detrend not removing 0 Hz component?

2 次查看(过去 30 天)
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by