Admin Production ni-theme
Current Publication

FIRNarrowBandCoef

LabWindows/CVI

FIRNarrowBandCoef

Advanced Analysis Library Only

AnalysisLibErrType FIRNarrowBandCoef (double samplingFrequency, double passbandBandwidth, double stopbandBandwidth, double centerFrequency, double ripple, double attenuation, int filterType, FIRCoefStruct *filterInformation);

Purpose

Designs a set of filter coefficients to implement a digital interpolated FIR (IFIR) filter.

The parameters you pass to this function cannot have negative values, and they cannot violate the Sampling Theorem.

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.

FIRNarrowBandCoef generates only the filter coefficients; it does not actually perform data filtering. 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.

For more information, refer to Discrete-Time Signal Processing by Oppenheim and Schafer, cited in the Bibliography.

Example Code

/* Generate a random signal and filter it using a designed Narrowband FIR filter. */
double x[128], *y;
double fs, fbp, fbs, fc, ripple, atten;
int type, m;
ssize_t n;
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
samplingFrequency double Sampling frequency in Hertz. This value must be greater than 0.
passbandBandwidth double Passband bandwidth in Hertz.
stopbandBandwidth double Stopband bandwidth in Hertz.
centerFrequency double Center frequency of the filter.
ripple double Ripple in the passband of the filter.

The default value is 0.01.
attenuation double Attenuation in the stopband of the filter in db.

The default value is 60.
filterType int Filter type. filterType must be one of the following values.

Constant Value Description
LOWPASS 0 Designs an FIR narrowband bandstop filter.
HIGHPASS 1 Designs an FIR narrowband highpass filter.
BANDPASS 2 Designs an FIR narrowband bandpass filter.
BANDSTOP 3 Designs an FIR narrowband bandstop filter.
Output
Name Type Description
filterInformation FIRCoefStruct Designed filter coefficients. The definition of the 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;

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 FIRNarrowBandCoef function.