Rev | Line | |
---|
[26975] | 1 | function [npsdx, psdx, freq] = npsd(x)
|
---|
| 2 | %npsd - Normalized Power Spectral Density (using fft)
|
---|
| 3 | %
|
---|
| 4 | % x: time series
|
---|
| 5 | %
|
---|
| 6 | % psdx: Power Spectral Density(right half plane, value doubled)
|
---|
| 7 | % freq: frequency(non-negative half)
|
---|
| 8 | %
|
---|
| 9 |
|
---|
| 10 | % length of data
|
---|
| 11 | Nx = length(x);
|
---|
| 12 | % fft
|
---|
| 13 | xdft = fft(x);
|
---|
| 14 | xdft = xdft(1:floor(Nx/2+1));
|
---|
| 15 | % power specturm
|
---|
| 16 | psdx = (1/(2*pi*Nx)) * abs(xdft).^2;
|
---|
| 17 | % In order to conserve the total power, multiply all frequencies that
|
---|
| 18 | % occur in both sets - the positive and negative frequencies — by a factor of 2
|
---|
| 19 | psdx(2:end-1) = 2*psdx(2:end-1);
|
---|
| 20 | freq = 0:(2*pi)/Nx:pi;
|
---|
| 21 | % normalize(trapzoidal rule)
|
---|
| 22 | intS = trapz(freq, psdx);
|
---|
| 23 | if intS == 0
|
---|
| 24 | psdx = 1 +psdx;
|
---|
| 25 | intS = trapz(freq, psdx);
|
---|
| 26 | end
|
---|
| 27 | npsdx = psdx ./ intS;
|
---|
| 28 |
|
---|
| 29 |
|
---|
[27966] | 30 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.