Mercurial > hg > ltpda
comparison m-toolbox/classes/@mfir/parseFilterParams.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 % PARSEFILTERPARAMS parses the input plist and returns a full plist for designing a standard FIR filter. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: PARSEFILTERPARAMS parses the input plist and returns a full | |
5 % plist for designing a standard FIR filter. Defaults are used | |
6 % for those parameters missing from the input plist. | |
7 % | |
8 % CALL: plo = parseFilterParams(pl) | |
9 % | |
10 % INPUT: 'type' - one of 'highpass', 'lowpass', 'bandpass', 'bandreject'. | |
11 % [default: 'lowpass'] | |
12 % 'gain' - gain of filter [default: 1.0] | |
13 % 'fs' - sample frequency to design for [default: 1 Hz] | |
14 % 'order' - order of filter [default: 64] | |
15 % 'fc' - corner frequencies. This is a two element vector for | |
16 % bandpass and bandreject filters. [default: 0.1 or [0.1 0.25] Hz] | |
17 % 'Win' - a window object to use in the design. [default: Hamming] | |
18 % | |
19 % VERSION: $Id: parseFilterParams.m,v 1.9 2010/10/29 16:09:13 ingo Exp $ | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function plo = parseFilterParams(pl) | |
24 | |
25 plo = plist(); | |
26 | |
27 % type | |
28 type = find(pl, 'type'); | |
29 if isempty(type) | |
30 type = 'lowpass'; | |
31 utils.helper.msg(msg.OPROC2, 'using default type ''lowpass'''); | |
32 end | |
33 plo = append(plo, 'type', type); | |
34 | |
35 % gain | |
36 gain = find(pl, 'gain'); | |
37 if isempty(gain) | |
38 gain = 1.0; | |
39 utils.helper.msg(msg.OPROC2, ['using default gain ' num2str(gain)]); | |
40 end | |
41 plo = append(plo, 'gain', gain); | |
42 | |
43 % order | |
44 order = find(pl, 'order'); | |
45 if isempty(order) | |
46 order = 64; | |
47 utils.helper.msg(msg.OPROC2, ['- using default order ' num2str(order)]); | |
48 end | |
49 if mod(order,2) == 1 | |
50 warning('!!! reseting filter order to even number (+1)') | |
51 order = order + 1; | |
52 end | |
53 plo = append(plo, 'order', order); | |
54 | |
55 % fc | |
56 fc = find(pl, 'fc'); | |
57 if isempty(fc) | |
58 if strcmp(type, 'bandreject') || strcmp(type, 'bandpass') | |
59 fc = [0.1 0.25]; | |
60 else | |
61 fc = 0.1; | |
62 end | |
63 utils.helper.msg(msg.OPROC2, ['- using default fc ' num2str(fc)]); | |
64 end | |
65 plo = append(plo, 'fc', fc); | |
66 | |
67 % fs | |
68 fs = find(pl, 'fs'); | |
69 if isempty(fs) | |
70 fs = 10*max(fc); | |
71 warning([sprintf('!!! no sample rate specified. Designing for fs=%2.2fHz.', fs)... | |
72 sprintf('\nThe filter will be redesigned later when used.')]); | |
73 end | |
74 plo = append(plo, 'fs', fs); | |
75 | |
76 % win | |
77 win = find(pl, 'Win'); | |
78 if isempty(win) | |
79 % then we use the default window | |
80 win = specwin('Hamming', order+1); | |
81 elseif ischar(win) | |
82 if strcmpi(win, 'kaiser') | |
83 win = specwin(win, order+1, win.psll); | |
84 else | |
85 win = specwin(win, order+1); | |
86 end | |
87 end | |
88 if length(win.win) ~= order + 1 | |
89 warning('!!! setting window length to filter order !!!'); | |
90 switch lower(win.type) | |
91 case 'kaiser' | |
92 win = specwin(win.type, order + 1, win.psll); | |
93 otherwise | |
94 win = specwin(win.type, order + 1); | |
95 end | |
96 end | |
97 plo = append(plo, 'Win', win); | |
98 end | |
99 | |
100 |