Increasing value over time of Power of a audio signal

31 views (last 30 days)
Hi everyone, i have an audio signal and the power of the same signal increases over time (with more samples) so i have a very big value of the power and a wrong power spectrum if i use this code
% Lunghezza del segnale e trasformata FFT
m = length(xn); % lunghezza del segnale originale
Unrecognized function or variable 'xn'.
y = fft(xn, m); % calcolo della FFT del segnale
% Vettore delle frequenze
f = (0:m-1) * (fs / m); % frequenze associate ai campioni FFT
% Calcolo dello spettro di potenza normalizzato
power = abs(y).^2 / m; % spettro di potenza normalizzato
% Plot dello spettro di potenza
figure;
plot(f(1:floor(m/2)), power(1:floor(m/2))); % plottiamo solo la metà positiva
xlabel('Frequency (Hz)');
ylabel('Power');
title('Power Spectrum of Signal');
But if i use the function pspectrum or the signal analyzer app i have different results much smaller
[p, f] = pspectrum(xn, fsn, 'power'); % Calcola la potenza spettrale e la frequenza
plot(f, p); % Plotta la potenza spettrale in funzione della frequenza
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
title('Power Spectrum of Signal');
same plot for pspectrum and signal analyzer so i think it s correct, why i have that error with power over 160 db/hz? i need to calculate the power myself cause i need the values for a model thank you

Accepted Answer

William Rose
William Rose on 14 Nov 2024 at 17:22
You say "I need to calculate the power myself cause i need the values for a model".
The first plot you provided has the vertical axis label cut off, so I am not sure how it differs from the second plot. Normalization of the power spectrum depends on several choices, including whether you want the power spectrum or the power spectral density, one-sided versus two-sided, winodw choice and possible adjustment for windowing, etc. See here for a discussion of these choices, and how to get results from fft() that match the results from other matlab approaches to estimating the spectrum. The second plot you show uses pspectrum() to compute the spectrum. pspectrum() makes a lot of decisions based on the length of the time-domain sequence, etc. See here for details. It will be a lot of work to write your own code that gives the same output as pspectrum.
If you want to compute the power yourself, then do it by a consistent and clear method, the same way every time. The values you obtain will work with the model you develop.
  5 Comments
Alex Kouroupis
Alex Kouroupis on 15 Nov 2024 at 8:43
Thank you very much for the answer apreccieated. So is it safe to get the power of a signal with pspectrum() function? I need to do some clssifications of a signal and i use power and energy as featues (with others), if i put more samples in as frequencyresolution will i get a better pspectrum to see near frequencies? also how many samples does pspectrum() use? can t find the default prametres of the fucntion. Thank you veryyyyy very much
William Rose
William Rose on 16 Nov 2024 at 7:12
If you want signal power for classificaiton purposes, why not just compute the variance of the time domain signal?
I suspect that if you are consistent in your use of pspectrum() with various signals, then the outpout from pspectrum() will work just as well for classificaiton as if you used abs(fft()/N).^2 or cpsd() or some other approach.
pspectrum() uses as many samples as you pass to it. It appears, from the spectra produced by pspectrum(x,fs,'power'), that it pads with zeros. I agree that it is not obvious from the documentation.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!