ECE 486 Lab Assignments
Running Mean Filters

Implementation of running-mean filters for in which a very long input sequence x[n] can be processed by breaking the input sequence into fixed length blocks. More...

Data Structures

struct  running_mean
 filter structure containing the filter state More...
 

Typedefs

typedef struct running_mean RUNNING_MEAN_T
 filter structure containing the filter state More...
 

Functions

RUNNING_MEAN_Tinit_running_mean (int M, int blocksize)
 running mean filter initialization More...
 
void calc_running_mean (RUNNING_MEAN_T *s, float *x, float *y)
 Calculate a block of output samples of a running meain filter from an input sample block. More...
 
void destroy_running_mean (RUNNING_MEAN_T *s)
 Release memory associated with an #FIR_T. More...
 

Detailed Description

Implementation of running-mean filters for in which a very long input sequence x[n] can be processed by breaking the input sequence into fixed length blocks.

Filter output values are given by

*    y(n) = 1/M*( x[n] + x[n-1] + ... + x[n-M+1] )
* 

Filters are initialized by a single call to init_running_mean(), which allocates and initializes a filter descriptor structure of type RUNNING_MEAN_T

...
RUNNING_MEAN_T *filt;
...
// Allocate memory for inputs x[i] and outputs y[i] of length "blocksize"...
...
filt = init_running_mean(M,blocksize);

Once a filter descriptor is initialized, repeated calls to calc_running_mean() provide the filter outputs, where the input samples are provided in fixed length blocks of "blocksize" samples at a time.

while( ...input sample blocks are available...) {
// fill the vector x[i] with the next "blocksize" samples from the input sequence.
calc_running_mean(filt, x, y);
// do something with the filter output samples y[i].
}

When processing completes, destroy_running_mean() should be called to release any allocated memory.

Note
All input and output vectors (x[i] and y[i]) must be allocated by the caller.
The input and output arrays MAY point to the same location, in which case the input sequence x[i] is replaced by the output sequence y[i] in the calls to calc_running_mean().

Typedef Documentation

◆ RUNNING_MEAN_T

typedef struct running_mean RUNNING_MEAN_T

filter structure containing the filter state

Function Documentation

◆ calc_running_mean()

void calc_running_mean ( RUNNING_MEAN_T s,
float *  x,
float *  y 
)

Calculate a block of output samples of a running meain filter from an input sample block.

Calling calc_running_mean() repeatedly generates the filter output for an arbitrary sequence of input samples. The FIR filter output samples y(n) are given by

*
*                            i=M-1
*              y[n] = (1/M)   sum   x[n-i] 
*                             i=0
* 

For each call, an input block of samples x[i] with length "blocksize" (as specified in init_running_mean() ) is processed to generate the corresponding output samples in the output vector y[i]. In subsequent calls to calc_running_mean(), the new input blocks x[i] are assumed to follow the input blocks provided in the previous calls to calc_running_mean(). As a result, very long input sequences may be processed by breaking the sequence into many fixed-length blocks of "blocksize" samples.

Memory required to store the output vector y[i] must be allocated by the caller.

Note
x and y CAN point to the same location. In this case, the filter output samples will replace the input sample array.
Returns
On return, y[i] contains the calculated output samples. (The contents of the structure *s are also modified to keep track of the filter state.)
See also
init_running_mean()
Parameters
[in,out]s[in,out] Pointer to previously initialized running mean filter structure, as provided by init_running() (and possibly modified by previous calls to calc_running_mean() )
[in]x[in] pointer to the input sample array
[out]y[out] Pointer to an array for storage of output samples

Definition at line 45 of file ece486_running_mean.c.

◆ destroy_running_mean()

void destroy_running_mean ( RUNNING_MEAN_T s)

Release memory associated with an #FIR_T.

Parameters
[in]s[in] Pointer to previously initialized FIR filter structure, provided by init_fir()

Definition at line 75 of file ece486_running_mean.c.

◆ init_running_mean()

RUNNING_MEAN_T* init_running_mean ( int  M,
int  blocksize 
)

running mean filter initialization

Call init_running_mean() to create and initialize a running meain filter structure.

Returns
pointer to an initialized structure of type RUNNING_MEAN_T which may be used to calculate the requested filter outputs.
Parameters
[in]M[in] Number of samples to average for each output sample
[in]blocksize[in] Block size for input sample blocks

Definition at line 21 of file ece486_running_mean.c.

ece486_running_mean.h
FIR filter using fixed-length input sample blocks.
calc_running_mean
void calc_running_mean(RUNNING_MEAN_T *s, float *x_in, float *y_out)
Calculate a block of output samples of a running meain filter from an input sample block.
Definition: ece486_running_mean.c:45
destroy_running_mean
void destroy_running_mean(RUNNING_MEAN_T *s)
Release memory associated with an #FIR_T.
Definition: ece486_running_mean.c:75
init_running_mean
RUNNING_MEAN_T * init_running_mean(int M, int blocksize)
running mean filter initialization
Definition: ece486_running_mean.c:21