# FFT matlab: wrong 0Hz frequency

Status
Not open for further replies.

#### roujhan

##### Newbie level 2 Hello

I want to use fft in MATLAB to analize some exprimental data saved as an excell file attached here as a doc file.
my code:

N=length(x);
F=[-N/2:N/2-1]/N;
X = abs(fft(x-mean(x),N))
X = fftshift(X);
plot(F,X)

But it plots a graph with a large 0Hz wrong component, my true frequency is about 395Hz and it is not shown in the plotted graph.
Please tell me what is wrong.

Any help would be appreciated.

#### JoannesPaulus I do not see the large 0Hz component... did you zoom in? There are two tones (-fo and fo) in my plot. You also need to set the frequency axis according to your sampling frequency and length of the capture, not just F=[-N/2:N/2-1]/N;

#### fcfusion

##### Full Member level 4 The 0 Hz component shows probably because your signal has an average value different of zero.

#### roujhan

##### Newbie level 2 fcfusion said:
The 0 Hz component shows probably because your signal has an average value different of zero.

But I subtract the mean value.

#### albbg Hi,

I tryed to analyze your data. You didn't specify the sampling time, however if the time data are in seconds I assume it is 4 us.
What I can see in the FFT is a large peak at roughly 500 Hz and other low amplitude peaks. No DC is present. There is no need to subctrat the mean value since it is already 0 (very close to).
Did you zoom the FFT window in a region close to the DC ? Possibly you saw the two peaks (-500 Hz, 500 Hz) very close one each other confusing them for a single peak.

I used this code (actually is Scilab code but it is very similar to Matlab):

========================================

Res = 50; // refers the power to 50 ohms resistors

f=(-(N/2-1) N/2))/(N*tsamp); // N number of samples, tsamp sampling time

val = abs(fft(x));
val = fftshift(val);

val = val./length(f);
val = val./sqrt(2); // recover the amplitude from peak to RMS

PmW = 1000*val.^2/Res; // power in mW
PdBm = 10*log10(PmW); // power in dBm

==========================================

you can plot both PmW or PdBm versus f. Plotting dBm you will see more in detail the floor and the low amplitude peaks.

Status
Not open for further replies.