Search code examples
matlabsignalspsd

Power Spectral Densty in microvolt^2/Hz?


Here is my program for my PSD in microvolt^2/Hz, where W is my data.

Fs=128
x1 =W;
L = length(x1);
NFFT = 2^nextpow2(L); 
f = Fs/2*linspace(0,1,NFFT/2+1);
n = 0:L-1;
pxx1 = pwelch(x1,L);
plot(pxx);

I need to know if my program is right or wrong here in order to built PSD in microvolt^2/Hz.


Solution

  • Using pwelch is indeed the right thing to do to get a power spectral density in units^2 per Hz. You might want to provide a few more arguments to pwelch, however.

    % input is a time series x
    
    fs=128                    % sample rate (Hz)
    bw = 0.1;                 % desired spectrum resolution (Hz)
    nfft = fs/bw;             % length of fft (samples)
    nfft = 2^nextpow2(nfft);  % round to nearest power of 2
    bw = fs / nfft;           % actual resolution
    
    % Estimate the power spectral density
    [Pxx, f] = pwelch(x, hanning(nfft), nfft/2, nfft, fs);
    
    % Plot the results
    loglog(f, Pxx)
    xlabel('frequency [Hz]');
    ylabel('units^2 / Hz');