Table of Contents

NAME

QccFilter - generic data structure for FIR filtering of signals

SYNOPSIS

#include "libQccPack.h"

int QccFilterInitialize(QccFilter *filter);
int QccFilterAlloc(QccFilter *filter);
void QccFilterFree(QccFilter *filter);
int QccFilterCopy(QccFilter *filter1, const QccFilter *filter2);
int QccFilterReversal(const QccFilter *filter1, QccFilter *filter2);
int QccFilterAlternateSignFlip(QccFilter *filter);
intQccFilterRead(FILE*"infile, QccFilter *filter);
int QccFilterWrite(FILE *outfile, const QccFilter *filter);
int QccFilterPrint(const QccFilter *filter);

DESCRIPTION

QccPack provides the QccFilter data structure to specify FIR filters for one-dimensional signals. The QccFilter structure contains filter coefficients, as well as information on the filters causality. These coefficients then are used in routines like QccFilterVector(3) and QccFilterMultiRateFilterVector(3) to filter signals using time-domain convolution.

DATA STRUCTURE

The QccFilter data structure is defined as:

typedef struct
{
int causality;
int length;
QccVector coefficients;
} QccFilter;

The fields of QccFilter are as follows:

causality
The causality of the filter, that is, how the filter coefficients are arranged with respect to the time-domain origin. Possible values are QCCFILTER_CAUSAL, QCCFILTER_ANTICAUSAL, QCCFILTER_SYMMETRICWHOLE, and QCCFILTER_SYMMETRICHALF.
length
The number of coefficients in the filter.
coefficients
A vector of the filter coefficients.

Suppose that length is N. If causality is QCCFILTER_CAUSAL, then the coefficients, h[n], of the length-N causal FIR filter in coefficients are in the order:

h[0] h[1] h[2] ... h[N-1]
If causality is QCCFILTER_ANTICAUSAL, then the coefficients, h[n], of the length-N anti-causal FIR filter in coefficients are in the order:
h[N-1] h[N-2] ... h[1] h[0]
If causality is QCCFILTER_SYMMETRICWHOLE, then the coefficients, h[n], of the length-(2N-1) whole-sample symmetric FIR filter in coefficients are in the order:
h[0] h[1] h[2] ... h[N-1]
That is, only the right half of the filter coefficients are stored for a whole-sample symmetric filter. If causality is QCCFILTER_SYMMETRICHALF, then the coefficients, h[n], of the length-2N half-sample symmetric FIR filter in coefficients are in the order:
h[0] h[1] h[2] ... h[N-1]
That is, only the right half of the filter coefficients are stored for a half-sample symmetric filter.

FILE FORMAT

For reading and reading QccFilter structures, QccPack uses the following file format. The file is in ASCII with no magic number. The file consists of the following information:

c
d
f0
f1
.
.
.

where c is filter->causality, d is filter->length, and the fi are the filter coefficients, filter->coefficients.

ROUTINES

QccFilterInitialize() should be called before any use of a QccFilter structure. QccFilterInitialize() initializes the fields of filter to the following values:

casuality: QCCFILTER_CAUSAL
length: 0
coefficients: NULL

QccFilterAlloc() Alloctates storage space for the filters coefficients. filter->length must give a nonzero filter length. The appropriate amount of storage space is allocated by calling QccVectorAlloc(3) , with a pointer to the vector returned as filter->coefficients.

QccFilterFree() frees space previously allocated by QccFilterAlloc().

QccFilterCopy() copies filter2 to filter1. If filter1 has not been allocated prior to calling QccFilterCopy() (as is evidenced by a NULL filter1->coefficients pointer), then QccFilterAlloc() is called to allocate space for filter1 with the same size as filter2. Otherwise (non-NULL filter1->coefficients pointer), it is assumed that sufficient space as already been allocated to filter1.

QccFilterReversal() creates the time reversal of filter2, storing the resulting time-reversed filter in filter1. Sufficient storage space for the coefficients of filter1 must be allocated prior to calling QccFilterReversal(). For example, if filter2 is a length-N causal filter, QccFilterReversal() produces a length-N anti-causal filter, which is returned as filter1.

QccFilterAlternateSignFlip() changes the sign of every other coefficient in filter. For example, if filter is a length-N (N even) casual filter

h[0] h[1] h[2] ... h[N-3] h[N-2] h[n-1],
then, after QccFilterAlternateSignFlip() returns, filter is
-h[0] h[1] -h[2] ... h[N-3] -h[N-2] h[N-1].

QccFilterRead() reads the filter structure from the file pointed to by infile which must be already opened for reading via a call to QccFileOpen(3) .

QccFilterWrite() writes the filter structure to the file pointed to by outfile which must be already opened for writing via a call to QccFileOpen(3) .

QccFilterPrint() prints a formated list of the filter coefficients of filter to stdout.

RETURN VALUE

Each of these routines (except QccFilterFree()) return 0 upon successful completion, 1 on error.

SEE ALSO

QccFilterVector(3) , QccFilterMultiRateFilterVector(3) , QccFilterMatrixSeparable(3) , QccPack(3)

AUTHOR

Copyright (C) 1997-2021 James E. Fowler


Table of Contents



Get QccPack at SourceForge.net. Fast, secure and Free Open Source software downloads