FIRNarrowBandFilter
Advanced Analysis Library Only
AnalysisLibErrType FIRNarrowBandFilter (double inputArray[], ssize_t numberOfElements, FIRCoefStruct coefinfo, double outputArray[]);
Purpose
Filters the real input sequence using the FIR narrowband filter specified by the coefinfo structure.
The overall filter is a linear-phase FIR filter. This function calculates the delay for the filter using the following equation:
where NG is the number of elements in the model filter array, NI is the number of elements in the image suppressor array, and M is the value of interpolation.
You can design narrowband FIR filters using FIRNarrowBandCoef, and then implement the filtering using FIRNarrowBandFilter. The design and implementation are separate operations, because many narrowband filters require long design times, whereas the actual filtering is very fast and efficient. Keep this in mind when creating your narrowband filtering diagrams.
Example Code
/* Filter a real input signal using an FIR narrowband filter. */
double x[128], *y;
double fs, fbp, fbs, fc, ripple, atten;
int type, n, m;
FIRCoefPtr filterInfo = NULL;
n = 128;
fs = 1;
fbp = 0.01;
fbs = 0.02;
fc = 0.2;
ripple = 0.01;
atten = 60;
type = LOWPASS;
WhiteNoise(n, 1, 17, x);
filterInfo = AllocFIRFilterPtr();
if(filterInfo){
FIRNarrowBandCoef(fs, fbp, fbs, fc, ripple, atten, type, filterInfo);
m = n + (filterInfo->Mtaps-1) * filterInfo->interp + filterInfo->Itaps - 1;
y = (floatnum *) malloc(m * sizeof(floatnum));
if(!y)
return OutOfMemErr;
FIRNarrowBandFilter(x, n, *filterInfo, y);
free(y);
FreeFIRFilterPtr(filterInfo);
}
Parameters
Input | ||
Name | Type | Description |
inputArray | double [] | Array that contains the raw data to filter. |
numberOfElements | ssize_t | Number of elements in inputArray. |
coefinfo | FIRCoefStruct | Pointer to the FIR filter structure that contains the filter coefficients and the internal filter information. The definition of the FIR filter coefficients is as follows: typedef struct { int fltType; // filter type that you use to determine how to filter the data: // LOWPASS (0): Lowpass filter. // HIGHPASS (1): Highpass filter. // BANDPASS (2): Bandpass filter. // BANDSTOP (3): Bandstop filter. // WBLOWPASS (4): Wideband lowpass filter for cutoff frequencies near Nyquist. // WBHIGHPASS (5): Wideband highpass filter for cutoff frequencies near zero. int interp; // Interpolation factor. The model filter is stretched by interp times. int Mtaps; // Size of *Mtaps. double *Mcoef; // Coefficients of the model filter. int Itaps; // Size of *Itaps. double *Itaps; // Coefficients of the filter image suppressor } FIRCoefStruct, *FIRCoefPtr; You must allocate this structure by calling FIRNarrowBandCoef. |
Output | ||
Name | Type | Description |
outputArray | double [] | Array that contains the output of the FIR filtering operation. If the interpolation factor of FIR equals 1, the size of y must be at least numberOfElements + Mtaps – 1. If the interpolation factor of FIR does not equal 1, the size of outputArray must be at least numberOfElements + (Mtaps–1) * interp + Itaps – 1. |
Return Value
Name | Type | Description |
status | AnalysisLibErrType | A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants. |
Additional Information
Library: Advanced Analysis Library
Include file: analysis.h
LabWindows/CVI compatibility: LabWindows/CVI 2012 and later
Example
Refer to analysis\narrowbandfilter.cws for an example of using the FIRNarrowBandFilter function.