Sharp peak at 0hz for FFT

Hi,
I am using the FFT example and I am getting a sharp peak at 0hz. I have tried removing the DC component by subtracting the mean, however I still get this large peak. The signal is a 600hz signal, I am sampling at 5khz. Does anyone have any suggestions on how to remove this?
Here is my code:
Fs = 5000; % Sampling frequency
T = 1/Fs; % Sampling period
L = length(Y); % Length of signal
t = (0:L-1)*T; % Time vector
t2 = flipud(rot90(t));
y2 = Y + 2*randn(size(t2));
y3 = fft(y2);
y3 = y3 - mean(y3);
y3 = detrend(y3,'constant');
P2 = abs(y3/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
%Plot time-domain signal
subplot(3,1,1);
plot(t, Y);
ylabel('Amplitude'); xlabel('Time (secs)');
axis tight;
title('Noisy Input Signal');
subplot(3,1,2);
plot(1000*t(1:1000),y2(1:1000))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')
subplot(3,1,3);
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
Thanks!
Mike

1 件のコメント

Walter Roberson
Walter Roberson 2018 年 5 月 25 日
Your third plot has the x axis starting about -500 or so. The command you used is plot(f,P1) . You set f = Fs*(0:(L/2))/L; which cannot have any negative values, and you do not do any xlim(). So it is not clear why you would have negative x values?
This tends to cast doubt that what you plotted is the same as what is in your code, so until this is cleared up it does not seem worth while to debug the code you posted.

サインインしてコメントする。

回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 5 月 25 日

1 投票

You need to subtract the mean value from time domain signal, not the frequency domain signal. Add the line
y2 = Y + 2*randn(size(t2));
y2 = y2 - mean(y2);
and delete the line
y3 = y3 - mean(y3);

2 件のコメント

Michael Ratterman
Michael Ratterman 2018 年 5 月 25 日
That was it, thanks so much!
Ameer Hamza
Ameer Hamza 2018 年 5 月 25 日
You are welcome.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

質問済み:

2018 年 5 月 25 日

コメント済み:

2018 年 5 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by