MATLAB Answers

How to use pspectrum() function

107 views (last 30 days)
Hello,
I want to create a power spectrum vs frequency plot of an audio signal I have. I tried using the following code:
[speech, f1] = audioread('outputTSNRcut.wav');
[noise, f2] = audioread('input2noise.wav');
[speechInput,fspeech] = pspectrum(speech, f1);
[noiseInput, fnoise] = pspectrum(noise, f2);
fig1 = figure;
plot(fspeech, abs(speechInput), 'b');
xlabel('Frequency (Hz)');
ylabel('Power Spectrum (dB)');
title('Speech Spectral Density');
fig2 = figure;
plot(fnoise, abs(noiseInput), 'r');
xlabel('Frequency (Hz)');
ylabel('Power Spectrum (dB)');
title('Noise Spectral Density');
which produced the following power spectrum plot:
The problem is that the audio is a speech recording, thus I'm expecting the power spectrum to be somwhere around 20 - 40 dB, perhaps more, but certintly not under 1 dB! I'm not sure what have I done wrong, I tried to follow exactly the pspectrum documantation. I'd appreciate it if someone could correct me.
Thank you.

Accepted Answer

Madhav Thakker
Madhav Thakker on 18 Sep 2020
Hi Elinor, the ppsptectrum function does not return the output directly in dB to be plotted. According to the documentation,
For the plot, the function converts p to dB using 10*log10(p)
  • You can use ppspectrum with no output arguments to plot the spectral estimate in the current window.
ppspectrum(speech, f1);
  • Another way is to manually convert p to dB.
Hope this helps.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!