Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/mlpsd_mex.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_MEX calls the ltpda_dft.mex to compute the DFT part of the LPSD algorithm | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: MLPSD_MEX calls the ltpda_dft.mex to compute the DFT part of the | |
5 % LPSD algorithm | |
6 % | |
7 % CALL: [S,Sxx,ENBW] = mlpsd_mex(x,f,r,m,L,fs,win,order,olap) | |
8 % | |
9 % VERSION: $Id: mlpsd_mex.m,v 1.13 2011/05/22 22:22:50 mauro Exp $ | |
10 % | |
11 % HISTORY: 19-05-2007 M Hewitson | |
12 % Creation | |
13 % | |
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
15 | |
16 function varargout = mlpsd_mex(varargin) | |
17 | |
18 import utils.const.* | |
19 | |
20 utils.helper.msg(msg.PROC1, 'using ltpda_dft.mex to compute core DFT'); | |
21 | |
22 % Get inputs | |
23 x = varargin{1}; | |
24 f = varargin{2}; | |
25 r = varargin{3}; | |
26 m = varargin{4}; | |
27 L = varargin{5}; | |
28 fs = varargin{6}; | |
29 win = varargin{7}; | |
30 order = varargin{8}; | |
31 olap = varargin{9}; | |
32 Lmin = varargin{10}; | |
33 | |
34 twopi = 2.0*pi; | |
35 nf = length(f); | |
36 Sxx = zeros(nf,1); | |
37 S = zeros(nf,1); | |
38 ENBW = zeros(nf,1); | |
39 devxx = zeros(nf,1); | |
40 dev = zeros(nf,1); | |
41 | |
42 disp_each = round(nf/100)*10; | |
43 | |
44 winType = win.type; | |
45 winPsll = win.psll; | |
46 | |
47 minReached = 0; | |
48 | |
49 for jj = 1:nf | |
50 | |
51 if mod(jj, disp_each) == 0 || jj == 1 || jj == nf | |
52 utils.helper.msg(msg.PROC1, 'computing frequency %04d of %d: %f Hz', jj, nf, f(jj)); | |
53 end | |
54 | |
55 % compute DFT exponent and window | |
56 l = L(jj); | |
57 | |
58 % Check if we need to update the window values | |
59 % - once we reach Lmin, the window values don't change. | |
60 if ~minReached | |
61 switch lower(winType) | |
62 case 'kaiser' | |
63 win = specwin(winType, l, winPsll); | |
64 otherwise | |
65 win = specwin(winType, l); | |
66 end | |
67 if l == Lmin | |
68 minReached = 1; | |
69 end | |
70 end | |
71 | |
72 p = 1i * twopi * m(jj)/l.*(0:l-1); | |
73 C = win.win .* exp(p); | |
74 | |
75 % Core DFT part in C-mex file | |
76 [A, B,nsegs] = ltpda_dft(x, l, C, olap, order); | |
77 | |
78 if mod(jj, disp_each) == 0 || jj == 1 || jj == nf | |
79 utils.helper.msg(msg.PROC2, 'averaged %d segments', nsegs); | |
80 end | |
81 | |
82 A2ns = 2.0*A; | |
83 B2ns = 4.0*B/nsegs; | |
84 S1 = win.ws; | |
85 S12 = S1*S1; | |
86 S2 = win.ws2; | |
87 ENBW(jj) = fs*S2/S12; | |
88 % scale asd/psd | |
89 Sxx(jj) = A2ns/fs/S2; | |
90 S(jj) = A2ns/S12; | |
91 % scale sqrt(variance) | |
92 devxx(jj) = sqrt(B2ns/fs^2/S2^2); | |
93 dev(jj) = sqrt(B2ns/S12^2); | |
94 | |
95 end | |
96 | |
97 varargout{1} = S; | |
98 varargout{2} = Sxx; | |
99 varargout{3} = dev; | |
100 varargout{4} = devxx; | |
101 varargout{5} = ENBW; | |
102 end | |
103 |