How to use pspectrum() function

36 次查看(过去 30 天)
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.

采纳的回答

Madhav Thakker
Madhav Thakker 2020-9-18
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by