Classes for signal processessing. More...
Classes | |
struct | fir_t |
FIR filter structure. More... | |
struct | sos_t |
second order section structure More... | |
struct | iir_t |
IIR filter structure. More... | |
Functions | |
void | free_iir_filter (iir_t *) |
iir_t * | init_iir_filter (double c[][6], double, int) |
double | iir_filter (iir_t *, double) |
filter data with an iir filter | |
void | set_iir_initial_values (iir_t *, double) |
double | fir_filter (fir_t *, double) |
fir_t * | init_fir_filter (double *, int) |
void | free_fir_filter (fir_t *) |
Classes for signal processessing.
double fir_filter | ( | fir_t * | pf, | |
double | val | |||
) |
filter a data value with an fir filter
pf | a pointer to an fir filter | |
val | the data value to be filtered |
void free_fir_filter | ( | fir_t * | f | ) |
free an fir filter
f | a pointer to an fir filter |
void free_iir_filter | ( | iir_t * | filt | ) |
free memory associated with an iir filter
filt | a pointer to an iir filter |
double iir_filter | ( | iir_t * | f, | |
double | xin | |||
) |
filter data with an iir filter
f | a pointer to an iir filter | |
xin | the data value to be filtered |
fir_t* init_fir_filter | ( | double * | b, | |
int | ord | |||
) |
create an fir filter
b | an array of filter coefficients | |
ord | the filter order |
iir_t* init_iir_filter | ( | double | coef[][6], | |
double | gain, | |||
int | nsects | |||
) |
create an iir filter
coef | a two dimensional array of second order section coefficients | |
gain | the filter gain associated with the second order section representation | |
nsects | the number of second order sections |
--------------------------------------------------------------- function writesos(b,a,filtername,filename) if (nargin < 3) disp('usage: writesos(b,a,filtername,filename)'); return end if (nargin < 4) fid=1; else fid=fopen(filename,'w'); end [sos g] = tf2sos(b,a); [nsects ncol]=size(sos); fprintf(fid,['iir_t *init_' filtername '()\n']); fprintf(fid,'{ double coeff[][6]= {\n'); for i=1:nsects fprintf(fid,' '); fprintf(fid,' {%.15g, %.15g, %.15g, %.15g, %.15g, %.15g}',sos(i,:)); if (i ~= nsects) fprintf(fid,','); end fprintf(fid,'\n'); end fprintf(fid,' };\n'); fprintf(fid,' double gain=%.15g;\n',g); fprintf(fid,' iir_t *f;\n\n'); fprintf(fid,' f=init_iir_filter(coeff, gain, %d);\n\n',nsects); fprintf(fid,' return f;\n'); fprintf(fid,'}\n'); if (fid ~= 1) fclose(fid); end ---------------------------------------------------------------
[b a] = butter(5,0.1);
writesos(b,a,'myLowPassFilter')
iir_t *init_myLowPassFilter() { double coeff[][6]= { {1, 0.998743271944812, 0, 1, -0.726542528005698, 0}, {1, 2.00203542892064, 1.00203701235769, 1, -1.52169042607194, 0.599999999999708}, {1, 1.99922129913454, 0.999222880053167, 1, -1.7363101655347, 0.825664548620679} }; double gain=5.97957803700113e-05; iir_t *f; f=init_iir_filter(coeff, gain, 3); return f; }
void set_iir_initial_values | ( | iir_t * | f, | |
double | x | |||
) |
set the output of an iir filter to an initial value
f | a pointer to an iir filter | |
x | the initial value |