source: issm/trunk-jpl/src/m/contrib/chenggong/dataprocessing/npsd.m

Last change on this file was 27966, checked in by Cheng Gong, 17 months ago

remove author names and dates in the script

File size: 722 bytes
Line 
1function [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
11Nx = length(x);
12% fft
13xdft = fft(x);
14xdft = xdft(1:floor(Nx/2+1));
15% power specturm
16psdx = (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
19psdx(2:end-1) = 2*psdx(2:end-1);
20freq = 0:(2*pi)/Nx:pi;
21% normalize(trapzoidal rule)
22intS = trapz(freq, psdx);
23if intS == 0
24 psdx = 1 +psdx;
25 intS = trapz(freq, psdx);
26end
27npsdx = psdx ./ intS;
28
29
30end
Note: See TracBrowser for help on using the repository browser.