Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to remove DC for windowed FFT for spectral analysis?

Status
Not open for further replies.

qslazio

Full Member level 3
Full Member level 3
Joined
May 23, 2004
Messages
175
Helped
18
Reputation
36
Reaction score
7
Trophy points
1,298
Activity points
1,420
Folks,

Since windowed FFT of a signal with DC offset will produce the shape of the FFT of the window function around DC bins, which may mask out the interested signals at those bins, I'd like to remove DC component "during" FFT analysis.

My question is whether to remove the DC offset of the signal "before" or "after" the windowing. My understanding is to remove the DC before windowing otherwise aliasing due to windowing of the DC offset will still be there although DC bin is cleared indeed.

However, I have 2 example signals (i.e. as linked below) indicates inconsistent choices.

For "signal1.csv", it seems to be better to remove DC after windowing. For "signal2.csv", it seems to be better to remove DC before windowing.

The most interesting thing is that for "signal1.csv", the DC bin level of FFT with removing DC before windowing is much bigger than the FFT with DC offset!!

Anyone can explain how to do this correctly? Thanks!!!

FFT Plots:

signal1.jpg: https://docs.google.com/open?id=0B48Rh8E6owAkNjBvQkNXaXN1S3c
signal1.jpg

signal2.jpg: https://docs.google.com/open?id=0B48Rh8E6owAkc3Z3dVVqLUQ5OVE
signal2.jpg


Raw Data:

signal1.csv: https://docs.google.com/open?id=0B48Rh8E6owAkVXZkUENFV2ZJTEU

signal2.csv: https://docs.google.com/open?id=0B48Rh8E6owAkeGNtcWNOaGluZ0E

Matlab code:

test.m: https://docs.google.com/open?id=0B48Rh8E6owAkenNBOFV3ZUVmWEk



Code in "test.m" is posted here

clear

% better to remove DC after windowing
data = load('signal1.csv');

% better to remove DC before windowing
%data = load('signal2.csv');

signal = data(1:8192,2);
win = hanning(8192,'periodic');
wsignal = signal.*win;

% FFT with DC component
wfft = fft(wsignal)/8192;

% FFT without DC component after windowing
wfft_nowdc = fft(wsignal-mean(wsignal))/8192;

% FFT without DC component before windowing
wfft_nodc = fft((signal-mean(signal)).*win)/8192;

figure(1);
hold on;

plot(20*log10(abs(wfft)), 'b+', 'LineWidth',2);
plot(20*log10(abs(wfft_nowdc)), 'r', 'LineWidth',2);
plot(20*log10(abs(wfft_nodc)), 'g', 'LineWidth',2);

legend('original','remove DC after windowing','remove DC before windowing');
grid on;
 
Last edited:

Hi qslazio,

When you perform fft of a given set of data (windowed or not), removing the mean value affects only the result at bin 0 of the fft; all the other remain the same.
We see this in the red plot of both figures: it is coincident with the blue "+" except at the first bin.

Now, if you remove the mean value before windowing, that doesn't guarantee that the mean is 0 after windowing. Think for example in the vector [-1 2 -1] : it has not dc content, but it does have after windowing.
Then, it is normal that the green plots have a nonzero value at bin 0.

I hope it is clear.

Regards

Z
 
Hi zorro,

Thank you very much for your help.

I agree your statement about DC. Then my question goes to how to correctly remove DC for spectral analysis using window. It looks like I have to drop more bins anyway (i.e. 2 for hanning window and more for other window), otherwise SNR calculated will not be consistent if signal changes. And why people bother detrending the signal before FFT or PSD estimation if those bins have to be drop out anyway?


Regards,
qslazio
 
Last edited:

Hi qslazio,

One must deal with the fact that that windowing "contaminates" the bins because of widening the main lobe. (In the case of Hann window, it happens only with the two adjacent bins.) This is the cost of drastically reduce side lobes.

Frequently the signal has a dc added to it that is not part of the signal itself (e.g. an offset), perhaps very important, and you need to avoid its contamination to adjacent bins. So, the best yiou can do is remove the dc signal before windowing.
Doing so, you don't avoid that the useful signal "contaminates" the dc bin. At least, you know that it is an artifact of the method an can ignore it.

Suggestion: see what happens with a signal consisting of dc plus a complex exponential component that has exactly a whole cycle in the vector being analyzed. See the result with: a) not remove mean value; b) remove mean before windowing; c) remove mean after windowing.

Best regards

Z
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top