comparison m-toolbox/classes/@ao/mlpsd_m.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % MLPSD_M m-file only version of the LPSD algorithm
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: MLPSD_M m-file only version of the LPSD algorithm
5 %
6 % CALL: [S,Sxx,ENBW] = mlpsd_m(x,f,r,m,L,fs,win,order,olap)
7 %
8 % VERSION: $Id: mlpsd_m.m,v 1.9 2011/05/22 22:22:50 mauro Exp $
9 %
10 % HISTORY: 19-05-2007 M Hewitson
11 % Creation
12 %
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15 function varargout = mlpsd_m(varargin)
16
17 import utils.const.*
18
19 utils.helper.msg(msg.PROC1, 'using MATLAB to compute core DFT');
20
21 % Get inputs
22 x = varargin{1};
23 f = varargin{2};
24 r = varargin{3};
25 m = varargin{4};
26 L = varargin{5};
27 fs = varargin{6};
28 win = varargin{7};
29 order = varargin{8};
30 olap = varargin{9};
31
32 twopi = 2.0*pi;
33
34 nx = length(x);
35 nf = length(f);
36 Sxx = zeros(nf,1);
37 S = zeros(nf,1);
38 ENBW = zeros(nf,1);
39
40 disp_each = round(nf/100)*10;
41
42 for jj = 1:nf
43
44 if mod(jj, disp_each) == 0 || jj == 1 || jj == nf
45 utils.helper.msg(msg.PROC1, 'computing frequency %04d of %d: %f Hz', jj, nf, f(jj));
46 end
47
48 % compute DFT exponent and window
49 l = L(jj);
50 switch lower(win.type)
51 case 'kaiser'
52 win = specwin(win.type, l, win.psll);
53 otherwise
54 win = specwin(win.type, l);
55 end
56
57 p = 1i * twopi * m(jj)/l.*[0:l-1];
58 C = win.win .* exp(p);
59 Xolap = (1-olap);
60 % do segments
61 A = 0.0;
62
63 % Compute the number of averages we want here
64 segLen = l;
65 nData = length(x);
66 ovfact = 1 / (1 - olap);
67 davg = (((nData - segLen)) * ovfact) / segLen + 1;
68 navg = round(davg);
69
70 % Compute steps between segments
71 if navg == 1
72 shift = 1;
73 else
74 shift = (nData - segLen) / (navg - 1);
75 end
76 if shift < 1 || isnan(shift)
77 shift = 1;
78 end
79
80 % disp(sprintf('Seglen: %d\t | Shift: %f\t | navs: %d', segLen, shift, navg))
81
82 start = 1.0;
83 for ii = 1:navg
84 % compute start index
85 istart = round (start);
86 start = start + shift;
87
88 % get segment
89 xs = [x(istart:istart+l-1)].';
90
91 % detrend segment
92 switch order
93 case -1
94 % do nothing
95 case 0
96 xs = xs - mean(xs);
97 case 1
98 xs = detrend(xs);
99 otherwise
100 xs = polydetrend(xs, order);
101 end
102
103 % make DFT
104 a = C*xs;
105 A = A + a*conj(a);
106
107 end
108
109 if mod(jj, disp_each) == 0 || jj == 1 || jj == nf
110 utils.helper.msg(msg.PROC2, 'averaged %d segments', navg);
111 end
112
113 A2ns = 2.0*A/navg;
114 S1 = win.ws;
115 S12 = S1*S1;
116 S2 = win.ws2;
117 ENBW(jj) = fs*S2/S12;
118 Sxx(jj) = A2ns/fs/S2;
119 S(jj) = A2ns/S12;
120
121 end % for j=1:nf
122
123 varargout{1} = S;
124 varargout{2} = Sxx;
125 varargout{3} = ENBW;
126
127 end
128