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

Last change on this file since 26975 was 26975, checked in by Cheng Gong, 3 years ago

add post-processing codes

File size: 765 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% Author: Cheng Gong
10% Date: 2021-08-17
11
12% length of data
13Nx = length(x);
14% fft
15xdft = fft(x);
16xdft = xdft(1:floor(Nx/2+1));
17% power specturm
18psdx = (1/(2*pi*Nx)) * abs(xdft).^2;
19% In order to conserve the total power, multiply all frequencies that
20% occur in both sets - the positive and negative frequencies — by a factor of 2
21psdx(2:end-1) = 2*psdx(2:end-1);
22freq = 0:(2*pi)/Nx:pi;
23% normalize(trapzoidal rule)
24intS = trapz(freq, psdx);
25if intS == 0
26 psdx = 1 +psdx;
27 intS = trapz(freq, psdx);
28end
29npsdx = psdx ./ intS;
30
31
32end
Note: See TracBrowser for help on using the repository browser.