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 commentaire

Walter Roberson
Walter Roberson le 25 Mai 2018
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.

Connectez-vous pour commenter.

Réponses (1)

Ameer Hamza
Ameer Hamza le 25 Mai 2018

1 vote

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 commentaires

Michael Ratterman
Michael Ratterman le 25 Mai 2018
That was it, thanks so much!
Ameer Hamza
Ameer Hamza le 25 Mai 2018
You are welcome.

Connectez-vous pour commenter.

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by