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 Exchange에서 Fourier 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