comparison m-toolbox/test/LTPDA_training/topic5/TrainigSession_T5_Ex03.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 % Training session Topic 5 exercise 03
2 %
3 % Generation of noise with given psd
4 %
5 % 1) Load fsdata object from file
6 % 2) Fit psd of test data with zDomainFit
7 % 3) Genarate noise from fitted model
8 % 4) Fit psd of test data with curvefit
9 % 5) Genarate noise from fitted model
10 % 6) Compare results
11 %
12 % L FERRAIOLI 22-02-09
13 %
14 % $Id: TrainigSession_T5_Ex03.m,v 1.3 2009/02/25 18:18:45 luigi Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 %% 1) load fsdata
19
20 % load test noise AO from file
21 tn = ao(plist('filename', 'topic5\T5_Ex03_TestNoise.xml'));
22 tn.setName;
23
24 %% 2) Fitting psd of test data with zDomainFit
25
26 %% 2.1) We try to identify a proper model for the psd of loaded data
27
28 % making psd ot test data - we need some average otherwise the fitting
29 % algorithm is not able to run correctly
30 tnxx1 = tn.psd(plist('Nfft',2000));
31
32 % Removing first bins
33 tnxx1r = split(tnxx1,plist('split_type', 'frequencies', 'frequencies', [2e-3 5e-1]));
34 iplot(tnxx1r)
35
36 % finding proper weights for noisy data
37 stnxx = smoother(tnxx1r);
38 wgh = 1./(abs(stnxx.data.y));
39
40 %% 2.2) Fitting
41
42 plfit1 = plist('FS',1,... % Sampling frequency for the model filters
43 'AutoSearch','on',... % Automatically search for a good model
44 'StartPolesOpt','c1',... % Define the properties of the starting poles - complex distributed in the unitary circle
45 'maxiter',50,... % maximum number of iteration per model order
46 'minorder',10,... % minimum model order
47 'maxorder',45,... % maximum model order
48 'weights',wgh,... % assign externally calculated weights
49 'ResLogDiff',[],... % Residuals log difference (no need to assign this parameter for the moment)
50 'ResFlat',0.77,... % Rsiduals spectral flatness
51 'RMSE',5,... % Root Mean Squared Error Variation
52 'Plot','on',... % set the plot on or off
53 'ForceStability','off',... % we do not need a stable filter
54 'CheckProgress','off'); % display fitting progress on the command window
55
56 % Do the fit
57 [param1,fmod1] = zDomainFit(tnxx1r,plfit1);
58
59 %% 3) Generating noise from model psd
60
61 % noisegen1D is a noise coloring tool. It accept as input a white noise
62 % time series and output a colored noise time series with one sided psd
63 % matching the model specifiend into the parameters
64
65 % Generate white noise
66 a1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 1, 'nsecs', 10000,'yunits','m'));
67
68 plng = plist(...
69 'model', abs(fmod1), ... % model for colored noise psd
70 'MaxIter', 50, ... % maximum number of fit iteration per model order
71 'PoleType', 2, ... % generates complex poles distributed in the unitary circle
72 'MinOrder', 20, ... % minimum model order
73 'MaxOrder', 50, ... % maximum model order
74 'Weights', 2, ... % weight with 1/abs(model)
75 'Plot', false,... % on to show the plot
76 'Disp', false,... % on to display fit progress on the command window
77 'RMSEVar', 7,... % Root Mean Squared Error Variation
78 'FitTolerance', 2); % Residuals log difference
79
80 ac1 = noisegen1D(a1, plng);
81
82 %% 4) Checking results
83
84 % Calculating psd of generated data
85 acxx1 = ac1.psd(plist('Nfft',2000));
86
87 % Comparing with starting data
88 iplot(tnxx1,acxx1)
89