SourceForge.net Logo timeSeries: timeSeries Class Library

Signal processessing

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_tinit_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_tinit_fir_filter (double *, int)
void free_fir_filter (fir_t *)

Detailed Description

Classes for signal processessing.


Function Documentation

double fir_filter ( fir_t pf,
double  val 
)

filter a data value with an fir filter

Parameters:
pf a pointer to an fir filter
val the data value to be filtered
Returns:
the filtered data
void free_fir_filter ( fir_t f  ) 

free an fir filter

Parameters:
f a pointer to an fir filter
void free_iir_filter ( iir_t filt  ) 

free memory associated with an iir filter

Parameters:
filt a pointer to an iir filter
double iir_filter ( iir_t f,
double  xin 
)

filter data with an iir filter

Parameters:
f a pointer to an iir filter
xin the data value to be filtered
Returns:
the filtered value
fir_t* init_fir_filter ( double *  b,
int  ord 
)

create an fir filter

Parameters:
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

Parameters:
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
usage
call init_iir_filter with an nsects x 6 array of doubles as filter coefficients. Assuming that you have created a filter in MATLAB and obtained transfer function coefficients, the following m-code will generate the appropriate declaration:
---------------------------------------------------------------
    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
---------------------------------------------------------------
Example
Example: 5th order low-pass butterworth filter with break frequency at 10% of the Nyquist frequency
Save the m-code above into a file called writesos.m. Then execute these commands in matlab:
[b a] = butter(5,0.1);
writesos(b,a,'myLowPassFilter')
Matlab outputs the following text in the command window:
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;
}
Call this function to initialize your filter.
Adding a 4th parameter to the writesos call allows output to a text file instead of the matlab console. writesos(b,a,'myLowPassFilter','butter.c') for example, write the init call to the file butter.c.
void set_iir_initial_values ( iir_t f,
double  x 
)

set the output of an iir filter to an initial value

Parameters:
f a pointer to an iir filter
x the initial value
Generated on Tue Mar 16 15:10:52 2010 for timeSeries by  doxygen 1.6.3