comparison m-toolbox/classes/@miir/filload.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 function f = filload(filename)
2
3 % Load a LISO *_iir.fil file to get the filter taps and return a
4 % miir type object.
5 %
6 % M Hewitson 11-02-07
7 %
8 % $Id: filload.m,v 1.4 2008/08/08 12:12:04 hewitson Exp $
9 %
10
11 delims = ' \n';
12 in = fopen(filename, 'rt');
13
14 name = filename(1:end-4);
15
16 if(in < 0)
17 error(['can not open file ' filename]);
18 end
19 lbuffer = fgets(in);
20 n = 1;
21 nacoeffs = 0;
22 nbcoeffs = 0;
23 filt.a = [];
24 filt.b = [];
25 norminst = '';
26
27 while (lbuffer > 0)
28 if(length(lbuffer) > 1)
29 % read the first token on this line
30 [token, r] = strtok (lbuffer, delims);
31
32 % Get fs
33 if(strcmp(token, 'iir'))
34 [token, r] = strtok (r, delims); % value
35 fs = str2double(token);
36 end
37
38 % Get a coeffs
39 if(token(1) == 'a')
40 [token, r] = strtok (r, delims); % value
41 nacoeffs = nacoeffs+1;
42 filt.a(nacoeffs) = str2double(token);
43 end
44 % Get b coeffs
45 if(token(1) == 'b')
46 [token, r] = strtok (r, delims); % value
47 nbcoeffs = nbcoeffs+1;
48 filt.b(nbcoeffs) = str2double(token);
49 end
50 end
51
52 n = n + 1;
53 lbuffer = fgets(in);
54 end
55 fclose(in);
56
57 if(nacoeffs > nbcoeffs)
58 error('## unstable filter: nacoeffs > nbcoeffs');
59 end
60
61 if(nacoeffs < nbcoeffs)
62 filt.a = [filt.a zeros(1,(nbcoeffs-nacoeffs))];
63 end
64
65 ncoeffs = nbcoeffs;
66
67 f.name = name;
68 f.fs = fs;
69 f.a = filt.a;
70 f.b = filt.b;
71 f.ntaps = ncoeffs;
72 f.gain = 1;
73 f.histin = zeros(1, f.ntaps-1);
74 f.histout = zeros(1, f.ntaps-1);
75 end
76
77