Plotting periodgram/pwelch/other PSD function for mock data

I am developing a 1v peake-to-peak sine wave with a 60hz frequency. I am doing this in order to groundtruth certain methods of measuring sound. I am running into trouble in using and plotting various methods for developing a PSD. I have code below. Running this plots a fine sine wave and the RMS value of the data is .71 (good!). I expect to see a PSD plot with 1v energy at 60hz and no energy outside that band. I'm not getting that and am not sure why. For reference, I am a biologist - this is all greek to me but I'm trying my best. Code:
%%Time specifications:
Fs = 32000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = .5; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 60; % hertz
x = cos(2*pi*Fc*t);
% Plot the signal versus time:
figure;
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
NFFT = 8192; %
NOVERLAP = round(0.75*NFFT);
w = hanning(NFFT);
[sensor_spectrum, freq] = pwelch(x,w,NOVERLAP,NFFT,fs);
figure;
plot (freq, sensor_spectrum );

답변 (1개)

Sarvesh Kale
Sarvesh Kale 2023년 1월 31일
편집: Sarvesh Kale 2023년 1월 31일

1 개 추천

As per my understanding you only expect the PSD plot at 60 Hz and not around it but in the plot you are generating you see a spread in spectrum. You get this spread in spectrum when the step frequency (Fs/N) is not a proper divisor of your target frequency. In your case step frequency is (32000/8192) and frequency of interest is 60 Hz, If this was your problem then try changing the Fs value to 32768 and after trying the above code you will still see an even spread around 60 Hz but it will give you correct magnitude values. We see a spread because we are trying to calculate FFT for a finite windowed time signal, hope this answers your queries

카테고리

도움말 센터File Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

제품

질문:

2023년 1월 29일

편집:

2023년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by