Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DSPLIB - Filters

All the filters functions currently supported by the DSP library.

Coefficient Generation

The following functions are using coefficients to operate. These coefficients define the properties of the filter used and must be generated first.
There are different ways to do it:

The following shows how to generate 4th order low-pass filter coefficients using Scilab.

wfir('lp', 4, [fc/fs, 0], 're', [0 0])

Finite Impulse Response Filter

This function computes a real FIR filter using the impulse response of the desire filter onto a fixed-length signal. It returns a signal of a length equals to (size - h_size + 1) elements.
Here is the formula of the FIR filter:

filters_fir_equation.gif
Note
The impulse response of the filter has to be scaled to avoid overflowing values.
All the vectors have to be 32-bit aligned.

Relative functions:


Infinite Impulse Response Filter

This function computes a real IIR filter using the coefficients of the desire filter onto a fixed-length signal. It returns a signal of a length equals to size elements.
Here is the formula of the IIR filter:

filters_iir_equation.gif
Note
The data have to be scaled to avoid overflowing values.
All the vectors have to be 32-bit aligned.

Relative functions:


Partial Infinite Impulse Response Filter

This function computes a real IIR filter using the coefficients of the desire filter onto a fixed-length signal. It returns a signal of a length equals to (size - num_size + 1) elements.
Here is the formula of the IIR filter:

filters_iir_equation.gif
Note
The data have to be scaled to avoid overflowing values.
All the vectors have to be 32-bit aligned.

Relative functions:


Least Mean Square Filter

This function computes an adaptive LMS filter. It returns a (size)-length signal.
Here is the formula of the LMS filter:

filters_lms_equations.gif
Note
The data have to be scaled to avoid overflowing values.
All the vectors have to be 32-bit aligned.
You can change the value of the mu coefficient of the LMS filter by defying DSP_LMS_MU, at the compilation, with the desired value. This value defines mu as follow:
filters_lms_coefficient.gif

Relative functions:


Normalized Least Mean Square Filter

This function computes an adaptive NLMS filter. It returns a (size)-length signal.
Here is the formula of the NLMS filter:

filters_nlms_equations.gif
Note
The data have to be scaled to avoid overflowing values.
All the vectors have to be 32-bit aligned. You can change the value of the mu coefficient of the NLMS filter by defying DSP_NLMS_MU, at the compilation, with the desired value. This value defines mu as follow:
filters_nlms_coefficient.gif

Relative functions:


Interpolation filter

This function performs an interpolation over the input signal. It returns a (vect2_size * interpolation_ratio)-length signal.
Here is the principle of the interpolation:

filters_interpolation.gif
Note
The data have to be scaled to avoid overflowing values.
All the vectors have to be 32-bit aligned.

Relative functions:


Lowpass FIR design

These functions calculate lowpass FIR filter's coefficients.

Note
It does not take care of overflowing values.

Relative functions:


Functions

static void dsp16_filt_fir (dsp16_t *vect1, dsp16_t *vect2, int size, dsp16_t *h, int h_size)
 16 bits fixed point version of the FIR . More...
 
void dsp16_filt_iir (dsp16_t *y, dsp16_t *x, int size, dsp16_t *num, int num_size, dsp16_t *den, int den_size, int num_prediv, int den_prediv)
 16-bit fixed point version of the IIR . More...
 
void dsp16_filt_iirpart (dsp16_t *vect1, dsp16_t *vect2, int size, dsp16_t *num, int num_size, dsp16_t *den, int den_size, int num_prediv, int den_prediv)
 16 bits fixed point version of the IIR . More...
 
void dsp16_filt_interpolation (dsp16_t *vect1, dsp16_t *vect2, int vect2_size, dsp16_t *h, int h_size, int interpolation_ratio)
 This function interpolates a vector. More...
 
void dsp16_filt_interpolation_coefsort (dsp16_t *fir_coefs, int n_tap, int interpolation_ratio)
 This function resort the coefficients of a FIR filter to be used with the function dsp16_filt_interpolation. More...
 
void dsp16_filt_lms (dsp16_t *x, dsp16_t *w, int size, dsp16_t new_x, dsp16_t d, dsp16_t *y, dsp16_t *e)
 16-bit fixed point version of the LMS filter. More...
 
void dsp16_filt_lpfirdesign (dsp16_t *c, int fc, int fs, int order)
 16-bit fixed point version of the low-pass FIR filter design. More...
 
void dsp16_filt_lpfirdesign_windowed_sinc (dsp16_t *c, int fc_hz, int fs_hz, int order)
 16-bit fixed point version of the windowed sinc low-pass FIR filter design. More...
 
void dsp16_filt_nlms (dsp16_t *x, dsp16_t *w, int size, dsp16_t new_x, dsp16_t d, dsp16_t *y, dsp16_t *e)
 16-bit fixed point version of the NLMS filter. More...
 
static void dsp32_filt_fir (dsp32_t *vect1, dsp32_t *vect2, int size, dsp32_t *h, int h_size)
 32 bits fixed point version of the FIR . More...
 
void dsp32_filt_iir (dsp32_t *y, dsp32_t *x, int size, dsp32_t *num, int num_size, dsp32_t *den, int den_size, int num_prediv, int den_prediv)
 32-bit fixed point version of the IIR . More...
 
void dsp32_filt_iirpart (dsp32_t *vect1, dsp32_t *vect2, int size, dsp32_t *num, int num_size, dsp32_t *den, int den_size, int num_prediv, int den_prediv)
 32 bits fixed point version of the IIR . More...
 
void dsp32_filt_lms (dsp32_t *x, dsp32_t *w, int size, dsp32_t new_x, dsp32_t d, dsp32_t *y, dsp32_t *e)
 32-bit fixed point version of the LMS filter. More...
 
void dsp32_filt_nlms (dsp32_t *x, dsp32_t *w, int size, dsp32_t new_x, dsp32_t d, dsp32_t *y, dsp32_t *e)
 32-bit fixed point version of the NLMS filter. More...
 

static void dsp16_filt_fir ( dsp16_t vect1,
dsp16_t vect2,
int  size,
dsp16_t h,
int  h_size 
)
inlinestatic

16 bits fixed point version of the FIR .

Parameters
vect1A pointer on a 16-bit fixed-point vector of (size - h_size + 1) elements corresponding to the output buffer.
vect2A pointer on a 16-bit fixed-point vector of size elements corresponding to the input buffer.
sizeThe length of the input buffer (must be greater or equals to 4).
hA pointer on a 16-bit fixed-point vector of h_size elements corresponding to the buffer containing the impulse response coefficients.
h_sizeThe length of the impulse response of the filter (must be greater than 7)
Warning
Due to its implementation, for the avr32-uc3 optimized version of the FIR, the output buffer (vect1) have to have a length of 4*n elements to avoid overflows.
Note
You need the "Partial Convolution" module

References dsp16_vect_convpart().

Referenced by main().

void dsp16_filt_iir ( dsp16_t y,
dsp16_t x,
int  size,
dsp16_t num,
int  num_size,
dsp16_t den,
int  den_size,
int  num_prediv,
int  den_prediv 
)

16-bit fixed point version of the IIR .

Parameters
yA pointer on a 16-bit fixed-point vector of size elements corresponding to the output buffer. The den_size previous elements correspond to values of old output samples and have to be set to 0 at the initialization (y-1, y-2, ...).
xA pointer on a 16-bit fixed-point vector of size elements corresponding to the input buffer. The num_size previous elements correspond to old samples input samples have to be set to 0 at the initialization (x-1, x-2, ...).
sizeThe length of the input buffer.
numA pointer on a 16-bit fixed-point vector of num_size elements corresponding to the buffer containing the numerator's coefficients of the filter.
num_sizeThe length of the numerator's coefficients of the filter (must be a multiple of 2).
denA pointer on a 16-bit fixed-point vector of den_size elements corresponding to the buffer containing the denominator's coefficients of the filter.
den_sizeThe length of the denominator's coefficients of the filter (must be a multiple of 2).
num_predivThe predivisor used to scale down the numerator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the numerator's coefficients by 2^num_prediv else leave this field to 0.
den_predivThe predivisor used to scale down the denominator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the denominator's coefficients by 2^den_prediv else leave this field to 0.
Warning
Due to its implementation, for the avr32-uc3 optimized version of the IIR, the length of the output buffer (vect1) have to be multiple of 6 in order to avoid overflows.

References DSP16_QB, and n.

Referenced by main().

void dsp16_filt_iirpart ( dsp16_t vect1,
dsp16_t vect2,
int  size,
dsp16_t num,
int  num_size,
dsp16_t den,
int  den_size,
int  num_prediv,
int  den_prediv 
)

16 bits fixed point version of the IIR .

Parameters
vect1A pointer on a 16-bit fixed-point vector of (size - num_size + 1) elements corresponding to the output buffer.
vect2A pointer on a 16-bit fixed-point vector of size elements corresponding to the input buffer.
sizeThe length of the input buffer.
numA pointer on a 16-bit fixed-point vector of num_size elements corresponding to the buffer containing the numerator's coefficients of the filter.
num_sizeThe length of the numerator's coefficients of the filter.
denA pointer on a 16-bit fixed-point vector of den_size elements corresponding to the buffer containing the denominator's coefficients of the filter.
den_sizeThe length of the denominator's coefficients of the filter.
num_predivThe predivisor used to scale down the numerator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the numerator's coefficients by 2^num_prediv else leave this field to 0.
den_predivThe predivisor used to scale down the denominator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the denominator's coefficients by 2^den_prediv else leave this field to 0.
Warning
Due to its implementation, for the avr32-uc3 optimized version of the IIR, the length of the output buffer (vect1) have to be multiple of 6 in order to avoid overflows.

References DSP16_QB, and n.

Referenced by main().

void dsp16_filt_interpolation ( dsp16_t vect1,
dsp16_t vect2,
int  vect2_size,
dsp16_t h,
int  h_size,
int  interpolation_ratio 
)

This function interpolates a vector.

Parameters
vect1A pointer on a 16-bit fixed-point vector where to store the result. It must be of a size (in sample) equals to the size of the input buffer multiplied by the interpolation factor.
vect2A pointer on a 16-bit fixed-point vector containig the input samples.
vect2_sizeThe size of the input buffer.
hA pointer on a 16-bit fixed-point vector which contains the coefficients of the filter. These coefficients must be reorder with the function dsp16_filt_interpolation_coefsort before being used.
h_sizeThe size of this buffer.
interpolation_ratioThe interpolation factor desired for this interpolation.

References DSP16_INTREPOLATION_FILTER_FUNCTION_NAME, DSP16_INTREPOLATION_NO_LOOP_FILTER_FUNCTION_NAME, LOOP_UNROLL, LOOP_UNROLL_PLUS_ONE, MREPEAT(), vect1, and vect2.

void dsp16_filt_interpolation_coefsort ( dsp16_t fir_coefs,
int  n_tap,
int  interpolation_ratio 
)

This function resort the coefficients of a FIR filter to be used with the function dsp16_filt_interpolation.

Parameters
fir_coefsA pointer on a 16-bit fixed-point vector where the coefficients are stored.
n_tapThe number of tap of this filter.
interpolation_ratioThe interpolation factor of the interpolation to perform with this filter.

References get_new_index().

Referenced by dsp16_resampling_setup().

void dsp16_filt_lms ( dsp16_t x,
dsp16_t w,
int  size,
dsp16_t  new_x,
dsp16_t  d,
dsp16_t y,
dsp16_t e 
)

16-bit fixed point version of the LMS filter.

Parameters
xA pointer on a 16-bit fixed-point vector of (size) elements that acts as a circular buffer, filled with the input samples. Its elements have to be initialized to zero and then you just need to reinject this vector each time you call this functions without filling any of its values.
wA pointer on a 16-bit fixed-point vector of size elements corresponding to the coefficients of the filter. Just initialize its elements to zero and after several iterations, this buffer will be filled with the actual coefficients of the filter.
sizeThe length of the circular buffer (x) and of the coefficient's buffer (w). It must be a multiple of 4.
new_xA 16-bit fixed-point value which contains a new input sample signal.
dA 16-bit fixed-point value which contains the current sample of the reference's signal.
yA pointer on a 16-bit fixed-point value corresponding to the current sample of the output signal.
eA pointer on a 16-bit fixed-point value corresponding to the current sample of the output error signal.

References DSP16_QB, DSP_LMS_MU, i, new_x, temp, and y.

Referenced by main().

void dsp16_filt_lpfirdesign ( dsp16_t c,
int  fc,
int  fs,
int  order 
)

16-bit fixed point version of the low-pass FIR filter design.

Parameters
cA pointer on a 16-bit fixed-point vector of "order" size, used to store the coefficients of the filter designed.
fcCutoff frequency of the low-pass filter.
fsSample rate of the signal to filter.
orderOrder of the filter to design.

References CST_PI, DSP16_MUL_TO_DSP32, dsp16_op_mul(), DSP16_Q, DSP16_QB, DSP32_DIV_TO_DSP16, dsp32_op_sin(), DSP_Q, i, and num.

void dsp16_filt_lpfirdesign_windowed_sinc ( dsp16_t c,
int  fc_hz,
int  fs_hz,
int  order 
)

16-bit fixed point version of the windowed sinc low-pass FIR filter design.

Parameters
cA pointer on a 16-bit fixed-point vector of "order" size, used to store the coefficients of the filter designed.
fcCutoff frequency of the low-pass filter.
fsSample rate of the signal to filter.
orderOrder of the filter to design.

16-bit fixed point version of the windowed sinc low-pass FIR filter design.

k is chosen so that coef(order/2+1) equals 1.

fc = f_hz / fs_hz; for i=0:(order-1), if (i - order/2) <> 0, cst = sin(2 * pi * fc * (i - order/2)) / (i - order/2); coef(i+1) = k * cst * (0.42 - 0.5 * cos(2 * pi * i / order) + 0.08 * cos(4 * pi * i / order)); end end coef(order/2+1) = k * 2 * pi * fc;

References CST_PI, dsp16_op_cos(), dsp16_op_mul(), dsp16_op_sin(), DSP16_Q, DSP16_QB, DSP_Q, and i.

void dsp16_filt_nlms ( dsp16_t x,
dsp16_t w,
int  size,
dsp16_t  new_x,
dsp16_t  d,
dsp16_t y,
dsp16_t e 
)

16-bit fixed point version of the NLMS filter.

Parameters
xA pointer on a 16-bit fixed-point vector of (size) elements that acts as a circular buffer, filled with the input samples. Its elements have to be initialized to zero and then you just need to reinject this vector each time you call this functions without filling any of its values.
wA pointer on a 16-bit fixed-point vector of size elements corresponding to the coefficients of the filter. Just initialize its elements to zero and after several iterations, this buffer will be filled with the actual coefficients of the filter.
sizeThe length of the circular buffer (x) and of the coefficient's buffer (w). It must be a multiple of 4.
new_xA 16-bit fixed-point value which contains a new input sample signal.
dA 16-bit fixed-point value which contains the current sample of the reference's signal.
yA pointer on a 16-bit fixed-point value corresponding to the current sample of the output signal.
eA pointer on a 16-bit fixed-point value corresponding to the current sample of the output error signal.

References DSP16_QB, DSP_NLMS_MU, i, new_x, temp, and y.

Referenced by main().

static void dsp32_filt_fir ( dsp32_t vect1,
dsp32_t vect2,
int  size,
dsp32_t h,
int  h_size 
)
inlinestatic

32 bits fixed point version of the FIR .

Parameters
vect1A pointer on a 32-bit fixed-point vector of (size - h_size + 1) elements corresponding to the output buffer.
vect2A pointer on a 32-bit fixed-point vector of size elements corresponding to the input buffer.
sizeThe length of the input buffer (must be greater or equals to 4).
hA pointer on a 32-bit fixed-point vector of h_size elements corresponding to the buffer containing the impulse response coefficients.
h_sizeThe length of the impulse response of the filter (must be greater than 7)
Note
You need the "Partial Convolution" module

References dsp32_vect_convpart().

Referenced by main().

void dsp32_filt_iir ( dsp32_t y,
dsp32_t x,
int  size,
dsp32_t num,
int  num_size,
dsp32_t den,
int  den_size,
int  num_prediv,
int  den_prediv 
)

32-bit fixed point version of the IIR .

Parameters
yA pointer on a 32-bit fixed-point vector of size elements corresponding to the output buffer. The den_size previous elements correspond to values of old output samples and have to be set to 0 at the initialization (y-1, y-2, ...).
xA pointer on a 32-bit fixed-point vector of size elements corresponding to the input buffer. The num_size previous elements correspond to old samples input samples have to be set to 0 at the initialization (x-1, x-2, ...).
sizeThe length of the input buffer.
numA pointer on a 32-bit fixed-point vector of num_size elements corresponding to the buffer containing the numerator's coefficients of the filter.
num_sizeThe length of the numerator's coefficients of the filter (must be a multiple of 2).
denA pointer on a 32-bit fixed-point vector of den_size elements corresponding to the buffer containing the denominator's coefficients of the filter.
den_sizeThe length of the denominator's coefficients of the filter (must be a multiple of 2).
num_predivThe predivisor used to scale down the numerator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the numerator's coefficients by 2^num_prediv else leave this field to 0.
den_predivThe predivisor used to scale down the denominator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the denominator's coefficients by 2^den_prediv else leave this field to 0.
Warning
Due to its implementation, for the avr32-uc3 optimized version of the IIR, the length of the output buffer (vect1) have to be multiple of 6 in order to avoid overflows.

References DSP32_QB, and n.

Referenced by main().

void dsp32_filt_iirpart ( dsp32_t vect1,
dsp32_t vect2,
int  size,
dsp32_t num,
int  num_size,
dsp32_t den,
int  den_size,
int  num_prediv,
int  den_prediv 
)

32 bits fixed point version of the IIR .

Parameters
vect1A pointer on a 32-bit fixed-point vector of (size - num_size + 1) elements corresponding to the output buffer.
vect2A pointer on a 32-bit fixed-point vector of size elements corresponding to the input buffer.
sizeThe length of the input buffer.
numA pointer on a 32-bit fixed-point vector of num_size elements corresponding to the buffer containing the numerator's coefficients of the filter.
num_sizeThe length of the numerator's coefficients of the filter.
denA pointer on a 32-bit fixed-point vector of den_size elements corresponding to the buffer containing the denominator's coefficients of the filter.
den_sizeThe length of the denominator's coefficients of the filter.
num_predivThe predivisor used to scale down the numerator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the numerator's coefficients by 2^num_prediv else leave this field to 0.
den_predivThe predivisor used to scale down the denominator's coefficients of the filter in order to avoid overflow values. So when you use this feature, you have to prescale manually the denominator's coefficients by 2^den_prediv else leave this field to 0.

References DSP32_QB, and n.

Referenced by main().

void dsp32_filt_lms ( dsp32_t x,
dsp32_t w,
int  size,
dsp32_t  new_x,
dsp32_t  d,
dsp32_t y,
dsp32_t e 
)

32-bit fixed point version of the LMS filter.

Parameters
xA pointer on a 32-bit fixed-point vector of (size) elements that acts as a circular buffer, filled with the input samples. Its elements have to be initialized to zero and then you just need to reinject this vector each time you call this functions without filling any of its values.
wA pointer on a 32-bit fixed-point vector of size elements corresponding to the coefficients of the filter. Just initialize its elements to zero and after several iterations, this buffer will be filled with the actual coefficients of the filter.
sizeThe length of the circular buffer (x) and of the coefficient's buffer (w).
new_xA 32-bit fixed-point value which contains a new input sample signal.
dA 32-bit fixed-point value which contains the current sample of the reference's signal.
yA pointer on a 32-bit fixed-point value corresponding to the current sample of the output signal.
eA pointer on a 32-bit fixed-point value corresponding to the current sample of the output error signal.

References DSP32_QB, DSP_LMS_MU, i, new_x, temp, and y.

Referenced by main().

void dsp32_filt_nlms ( dsp32_t x,
dsp32_t w,
int  size,
dsp32_t  new_x,
dsp32_t  d,
dsp32_t y,
dsp32_t e 
)

32-bit fixed point version of the NLMS filter.

Parameters
xA pointer on a 32-bit fixed-point vector of (size) elements that acts as a circular buffer, filled with the input samples. Its elements have to be initialized to zero and then you just need to reinject this vector each time you call this functions without filling any of its values.
wA pointer on a 32-bit fixed-point vector of size elements corresponding to the coefficients of the filter. Just initialize its elements to zero and after several iterations, this buffer will be filled with the actual coefficients of the filter.
sizeThe length of the circular buffer (x) and of the coefficient's buffer (w).
new_xA 32-bit fixed-point value which contains a new input sample signal.
dA 32-bit fixed-point value which contains the current sample of the reference's signal.
yA pointer on a 32-bit fixed-point value corresponding to the current sample of the output signal.
eA pointer on a 32-bit fixed-point value corresponding to the current sample of the output error signal.

References DSP32_QB, DSP_NLMS_MU, i, new_x, temp, and y.

Referenced by main().