How to use pspectrum() function

39 visualizaciones (últimos 30 días)
Elinor Ginzburg
Elinor Ginzburg el 15 de Sept. de 2020
Respondida: Madhav Thakker el 18 de Sept. de 2020
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.

Respuesta aceptada

Madhav Thakker
Madhav Thakker el 18 de Sept. de 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.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by