Mercurial > hg > ltpda
comparison m-toolbox/classes/@mfir/fromAO.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 % create FIR filter from magnitude of input AO/fsdata | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: mfirFromAO | |
5 % | |
6 % DESCRIPTION: create FIR filter from magnitude of input AO/fsdata | |
7 % | |
8 % CALL: f = mfirFromAO(a, pli, version, algoname) | |
9 % | |
10 % PARAMETER: a: Analysis object | |
11 % pli: Parameter list object | |
12 % version: cvs version string | |
13 % algoname: The m-file name (use the mfilename command) | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 function filt = fromAO(filt, pli) | |
18 | |
19 import utils.const.* | |
20 | |
21 VERSION = '$Id: fromAO.m,v 1.25 2011/08/15 11:37:04 hewitson Exp $'; | |
22 ii = mfir.getInfo('mfir', 'From AO'); | |
23 % Set the method version string in the minfo object | |
24 ii.setMversion([VERSION '-->' ii.mversion]); | |
25 | |
26 % Add default values | |
27 pl = applyDefaults(ii.plists, pli); | |
28 | |
29 % Get parameters | |
30 a = find(pl, 'AO'); | |
31 N = find(pl, 'N'); | |
32 win = find(pl, 'Win'); | |
33 method = find(pl, 'method'); | |
34 | |
35 if ischar(win) | |
36 name = win; | |
37 wlen = pl.find('length'); | |
38 % if the plist contains a window length (like history plists do), use | |
39 % it; otherwise use the filter order N. | |
40 if isempty(wlen) | |
41 wlen = N; | |
42 end | |
43 | |
44 if strcmpi(name, 'kaiser') | |
45 psll = pl.find('psll'); | |
46 win = specwin(name, wlen, psll); | |
47 else | |
48 win = specwin(name, wlen); | |
49 end | |
50 end | |
51 | |
52 % Check that a.data is a fsdata object | |
53 if ~isa(a.data, 'fsdata') | |
54 error('### Please use an analysis object with a fsdata data object to create a mfir object.'); | |
55 end | |
56 | |
57 fs = a.data.fs; | |
58 f = a.data.getX; | |
59 xx = abs(a.data.getY); | |
60 | |
61 ffm = f/(fs/2); | |
62 switch lower(method) | |
63 case 'frequency-sampling' | |
64 % check window | |
65 if ischar(win) | |
66 if strcmpi(win, 'kaiser') | |
67 win = specwin(win, N+1, win.psll); | |
68 else | |
69 win = specwin(win, N+1); | |
70 end | |
71 end | |
72 | |
73 if length(win.win) ~= N+1 | |
74 warning('!!! resizing window function to match desired filter order.'); | |
75 if strcmpi(win.type, 'Kaiser') | |
76 win = specwin(win.type, N+1, win.psll); | |
77 else | |
78 win = specwin(win.type, N+1); | |
79 end | |
80 end | |
81 utils.helper.msg(msg.OPROC2, 'designing filter using frequency-sampling method [help fir2]'); | |
82 mtaps = fir2(N, ffm, xx, win.win); | |
83 case 'least-squares' | |
84 error('### this design method is not working properly yet.'); | |
85 if mod(length(ffm),2) | |
86 ffm = ffm(1:end-1); | |
87 xx = xx(1:end-1); | |
88 end | |
89 utils.helper.msg(msg.OPROC2, 'designing filter using least-squares method [help firls]'); | |
90 mtaps = firls(N, ffm, xx); | |
91 case 'parks-mcclellan' | |
92 error('### this design method is not working properly yet.'); | |
93 utils.helper.msg(msg.OPROC2, 'designing filter using Parks-McClellan method [help firpm]'); | |
94 mtaps = firpm(N, ffm, xx); | |
95 otherwise | |
96 error('### unknown filter design method.'); | |
97 end | |
98 | |
99 % Make mfir object | |
100 filt.fs = fs; | |
101 filt.a = mtaps; | |
102 filt.gd = (filt.ntaps+1)/2; | |
103 filt.histout = zeros(1,filt.ntaps-1); | |
104 | |
105 % Override some properties of the input plist | |
106 if isempty(pl.find('name')) | |
107 pl.pset('name', sprintf('fir(%s)', a.name)); | |
108 end | |
109 if isempty(pl.find('description')) | |
110 pl.pset('description', a.description); | |
111 end | |
112 | |
113 % Add history | |
114 pl.remove('AO'); % because the input AO goes in the history | |
115 filt.addHistory(ii, pl, [], a.hist); | |
116 | |
117 % Set object properties | |
118 filt.setObjectProperties(pl); | |
119 | |
120 end % function f = mfirFromAO(a, pli, version, algoname) |