ECE 486 Lab Assignments
ece486_running_mean.h
Go to the documentation of this file.
1 /*!
2  * @file ece486_running_mean.h
3  *
4  * @brief FIR filter using fixed-length input sample blocks
5  *
6  * @author ECE486 Lab Group ????
7  * @author Your Name
8  *
9  * @date ????
10  *
11  * @defgroup Lab_1 Running Mean Filters
12  * @{
13  *
14  * Implementation of running-mean filters for in which a very long input sequence
15  * x[n] can be processed by breaking the input sequence into fixed length blocks.
16  *
17  * Filter output values are given by
18  * @verbatim
19  * y(n) = 1/M*( x[n] + x[n-1] + ... + x[n-M+1] )
20  * @endverbatim
21  *
22  * Filters are initialized by a single call to init_running_mean(), which allocates
23  * and initializes a filter descriptor structure of type RUNNING_MEAN_T
24  *
25  * @code
26  * #include "ece486_running_mean.h"
27  * ...
28  * RUNNING_MEAN_T *filt;
29  * ...
30  * // Allocate memory for inputs x[i] and outputs y[i] of length "blocksize"...
31  * ...
32  * filt = init_running_mean(M,blocksize);
33  * @endcode
34  *
35  * Once a filter descriptor is initialized, repeated calls to calc_running_mean()
36  * provide the filter outputs, where the input samples are provided in fixed
37  * length blocks of "blocksize" samples at a time.
38  *
39  * @code
40  * while( ...input sample blocks are available...) {
41  * // fill the vector x[i] with the next "blocksize" samples from the input sequence.
42  * calc_running_mean(filt, x, y);
43  * // do something with the filter output samples y[i].
44  * }
45  * @endcode
46  *
47  * When processing completes, destroy_running_mean() should be called to release
48  * any allocated memory.
49  *
50  * @code
51  * destroy_running_mean(filt);
52  * @endcode
53  *
54  * @note
55  * All input and output vectors (x[i] and y[i]) must be allocated by the caller.
56  *
57  * @note
58  * The input and output arrays MAY point to the same location, in which case the
59  * input sequence x[i] is replaced by the output
60  * sequence y[i] in the calls to calc_running_mean().
61  *
62  */
63 
64 
65 #ifndef ECE486_RUNNING_MEAN
66 #define ECE486_RUNNING_MEAN
67 
68 /*
69  * Parameter Structure Definitions
70  */
71 
72 /*!
73  * @brief filter structure containing the filter state
74  *
75  */
76 typedef struct running_mean {
77  int M; // Number of samples to average.
78  int blocksize; // Number of samples per call to calc_running_mean
79  float *history; // Most recent M input samples
81 
82 /*
83  * Function Prototypes
84  */
85 
86 /*!
87  * @brief running mean filter initialization
88  *
89  * Call init_running_mean() to create and initialize a running meain filter structure.
90  *
91  * @returns pointer to an initialized structure of type #RUNNING_MEAN_T which may
92  * be used to calculate the requested filter outputs.
93  */
95  int M, //!< [in] Number of samples to average for each output sample
96  int blocksize //!< [in] Block size for input sample blocks
97 );
98 
99 /*!
100  * @brief Calculate a block of output samples of a running meain filter from an input sample block
101  *
102  * Calling calc_running_mean() repeatedly generates the filter output for an arbitrary sequence
103  * of input samples. The FIR filter output samples y(n) are given by
104  * @verbatim
105  *
106  * i=M-1
107  * y[n] = (1/M) sum x[n-i]
108  * i=0
109  * @endverbatim
110  * For each call, an input block of samples @a x[i] with length "blocksize" (as specified
111  * in init_running_mean() ) is processed to generate the corresponding output samples
112  * in the output vector @a y[i]. In subsequent calls to calc_running_mean(), the
113  * new input blocks @a x[i] are assumed to follow the input blocks provided in
114  * the previous calls to calc_running_mean(). As a result, very long input sequences
115  * may be processed by breaking the sequence into many fixed-length blocks of
116  * "blocksize" samples.
117  *
118  * Memory required to store the output vector @a y[i] must be allocated by the
119  * caller.
120  *
121  * \note
122  * @a x and @a y CAN point to the same location. In this case, the filter output
123  * samples will replace the input sample array.
124  *
125  * @returns On return, y[i] contains the calculated output samples.
126  * (The contents of the structure @a *s are also modified to keep track of the filter state.)
127  *
128  * @sa init_running_mean()
129  */
130 void calc_running_mean(
131  RUNNING_MEAN_T *s, //!< [in,out] Pointer to previously initialized running mean filter structure,
132  //!< as provided by init_running() (and possibly modified by
133  //!< previous calls to calc_running_mean() )
134  float *x, //!< [in] pointer to the input sample array
135  float *y //!< [out] Pointer to an array for storage of output samples
136 );
137 
138 /*!
139  * @brief Release memory associated with an #FIR_T
140  */
142  RUNNING_MEAN_T *s //!< [in] Pointer to previously initialized FIR filter
143  //!< structure, provided by init_fir()
144 );
145 
146 /*! @} end of ece486_running_mean group. */
147 #endif
RUNNING_MEAN_T
struct running_mean RUNNING_MEAN_T
filter structure containing the filter state
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.
Definition: ece486_running_mean.c:45
running_mean::M
int M
Definition: ece486_running_mean.h:77
running_mean
filter structure containing the filter state
Definition: ece486_running_mean.h:76
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
running_mean::blocksize
int blocksize
Definition: ece486_running_mean.h:78
running_mean::history
float * history
Definition: ece486_running_mean.h:79