Plotting periodgram/pwelch/other PSD function for mock data
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 );
0 comentarios
Respuestas (1)
Sarvesh Kale
el 31 de En. de 2023
Editada: Sarvesh Kale
el 31 de En. de 2023
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
0 comentarios
Ver también
Categorías
Más información sobre Parametric Spectral Estimation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!