The following shows how to generate 4th order low-pass filter coefficients using Scilab.
wfir('lp', 4, [fc/fs, 0], 're', [0 0])
Typedefs | |
typedef void(* | dsp16_win_fct_t )(dsp16_t *window_data, int size) |
This type defines a pointer on a function that generates a window. | |
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 . | |
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 . | |
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 . | |
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. | |
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. | |
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. | |
void | dsp16_filt_lpfirdesign (dsp16_t *c, int fc, int fs, int order, dsp16_win_fct_t dsp16_win_fct, dsp_filt_design_options_t options) |
16-bit fixed point version of the low-pass FIR filter design. | |
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. | |
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 . | |
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 . | |
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 . | |
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. | |
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. |
typedef void(* dsp16_win_fct_t)(dsp16_t *window_data, int size) |
This type defines a pointer on a function that generates a window.
window_data | A pointer on a 16-bit fixed-point vector to store the window data. | |
size | The size in elements of the "window_data" buffer. |
Definition at line 397 of file dsp_filtering.h.
static void dsp16_filt_fir | ( | dsp16_t * | vect1, | |
dsp16_t * | vect2, | |||
int | size, | |||
dsp16_t * | h, | |||
int | h_size | |||
) | [inline, static] |
16 bits fixed point version of the FIR .
vect1 | A pointer on a 16-bit fixed-point vector of (size - h_size + 1) elements corresponding to the output buffer. | |
vect2 | A pointer on a 16-bit fixed-point vector of size elements corresponding to the input buffer. | |
size | The length of the input buffer (must be greater or equals to 4). | |
h | A pointer on a 16-bit fixed-point vector of h_size elements corresponding to the buffer containing the impulse response coefficients. | |
h_size | The length of the impulse response of the filter (must be greater than 7) |
Definition at line 114 of file dsp_filtering.h.
References dsp16_vect_convpart().
Referenced by dac_reload_callback().
00114 { dsp16_vect_convpart(vect1, vect2, size, h, h_size); };
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 .
y | A 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, ...). | |
x | A 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 intput samples have to be set to 0 at the initialization (x-1, x-2, ...). | |
size | The length of the input buffer. | |
num | A 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_size | The length of the numerator's coefficients of the filter (must be a multiple of 2). | |
den | A 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_size | The length of the denominator's coefficients of the filter (must be a multiple of 2). | |
num_prediv | The 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_prediv | The 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. |
Definition at line 56 of file filt_dsp16_iir.c.
References DSP16_QB.
00057 { 00058 int n, m; 00059 S32 sum1, sum2; 00060 dsp16_t *px, *py; 00061 00062 num_prediv = DSP16_QB - num_prediv; 00063 den_prediv = DSP16_QB - den_prediv; 00064 00065 for(n=0; n<size; n++) 00066 { 00067 sum1 = 0; 00068 sum2 = 0; 00069 px = &x[n]; 00070 for(m=0; m<num_size; m++) 00071 sum1 += ((S32) num[m] * (S32) px[-m]); 00072 py = &y[n-1]; 00073 for(m=0; m<den_size; m++) 00074 sum2 += ((S32) den[m] * (S32) py[-m]); 00075 00076 sum1 >>= num_prediv; 00077 sum2 >>= den_prediv; 00078 00079 y[n] = sum1 - sum2; 00080 } 00081 }
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 .
vect1 | A pointer on a 16-bit fixed-point vector of (size - num_size + 1) elements corresponding to the output buffer. | |
vect2 | A pointer on a 16-bit fixed-point vector of size elements corresponding to the input buffer. | |
size | The length of the input buffer. | |
num | A 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_size | The length of the numerator's coefficients of the filter. | |
den | A 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_size | The length of the denominator's coefficients of the filter. | |
num_prediv | The 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_prediv | The 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. |
Definition at line 54 of file filt_dsp16_iirpart.c.
References DSP16_QB.
00055 { 00056 int n, m; 00057 S32 sum1, sum2; 00058 dsp16_t *px, *py; 00059 00060 num_prediv = DSP16_QB - num_prediv; 00061 den_prediv = DSP16_QB - den_prediv; 00062 00063 // Compute the first den_size elements 00064 // to initialize the vect1 00065 for(n=0; n<den_size; n++) 00066 { 00067 sum1 = 0; 00068 sum2 = 0; 00069 px = &x[n+num_size-1]; 00070 for(m=0; m<num_size; m++) 00071 sum1 += (S32) num[m] * (S32) px[-m]; 00072 py = &y[n-1]; 00073 for(m=0; m<n; m++) 00074 sum2 += (S32) den[m] * (S32) py[-m]; 00075 00076 sum1 >>= num_prediv; 00077 sum2 >>= den_prediv; 00078 00079 y[n] = sum1 - sum2; 00080 } 00081 00082 for(; n<=(size-num_size); n++) 00083 { 00084 sum1 = 0; 00085 sum2 = 0; 00086 px = &x[n+num_size-1]; 00087 for(m=0; m<num_size; m++) 00088 sum1 += (S32) num[m] * (S32) x[-m]; 00089 py = &y[n-1]; 00090 for(m=0; m<den_size; m++) 00091 sum2 += (S32) den[m] * (S32) y[-m]; 00092 00093 sum1 >>= num_prediv; 00094 sum2 >>= den_prediv; 00095 00096 y[n] = sum1 - sum2; 00097 } 00098 }
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.
vect1 | A 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. | |
vect2 | A pointer on a 16-bit fixed-point vector containig the input samples. | |
vect2_size | The size of the input buffer. | |
h | A 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_size | The size of this buffer. | |
interpolation_ratio | The interpolation factor desired for this interpolation. |
Definition at line 190 of file dsp16_filt_interpolation.c.
References DSP16_INTREPOLATION_FILTER_FUNCTION_NAME, DSP16_INTREPOLATION_NO_LOOP_FILTER_FUNCTION_NAME, LOOP_UNROLL, and LOOP_UNROLL_PLUS_ONE.
00191 { 00192 int n_tap; 00193 typedef void (*interpolation_kernel_opti_t)(dsp16_t *, dsp16_t *, int, dsp16_t *, int, int); 00194 static const interpolation_kernel_opti_t interpolation_end_kernel_opti[] = { 00195 MREPEAT(LOOP_UNROLL, DSP16_INTREPOLATION_FILTER_FUNCTION_NAME, ) 00196 }; 00197 static const interpolation_kernel_opti_t interpolation_no_loop_end_kernel_opti[] = { 00198 MREPEAT(LOOP_UNROLL_PLUS_ONE, DSP16_INTREPOLATION_NO_LOOP_FILTER_FUNCTION_NAME, ) 00199 }; 00200 00201 n_tap = h_size / interpolation_ratio; 00202 00203 if (n_tap <= LOOP_UNROLL) 00204 interpolation_no_loop_end_kernel_opti[n_tap](vect1, vect2, vect2_size, h, h_size, interpolation_ratio); 00205 else 00206 interpolation_end_kernel_opti[n_tap%LOOP_UNROLL](vect1, vect2, vect2_size, h, h_size, interpolation_ratio); 00207 }
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.
fir_coefs | A pointer on a 16-bit fixed-point vector where the coefficients are stored. | |
n_tap | The number of tap of this filter. | |
interpolation_ratio | The interpolation factor of the interpolation to perform with this filter. |
Definition at line 58 of file dsp16_filt_interpolation_coefsort.c.
References get_new_index().
Referenced by dsp16_resampling_setup().
00059 { 00060 int start_index, new_index, cur_index; 00061 int temp1, temp2; 00062 int size; 00063 00064 size = n_tap * interpolation_ratio; 00065 00066 // Uses the LSB of each data as a marker. 00067 // This will avoid a lot of computation time 00068 // or memory requierment. 00069 for(temp1=1; temp1<size-1; temp1++) 00070 fir_coefs[temp1] &= 0xFFFE; 00071 00072 for(start_index = 1; start_index < size - 1; start_index++) 00073 { 00074 // If marker set, means item already proceeded. 00075 if (fir_coefs[start_index] & 0x0001) 00076 continue; 00077 00078 new_index = start_index + 1; 00079 cur_index = start_index; 00080 temp1 = fir_coefs[cur_index]; 00081 00082 while(start_index != new_index) 00083 { 00084 new_index = get_new_index(cur_index, n_tap, interpolation_ratio); 00085 temp2 = fir_coefs[new_index]; 00086 fir_coefs[new_index] = temp1 | 0x0001; 00087 temp1 = temp2; 00088 cur_index = new_index; 00089 } 00090 } 00091 }
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.
x | A 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 whithout filling any of its values. | |
w | A 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. | |
size | The length of the circular buffer (x) and of the coefficient's buffer (w). It must be a multiple of 4. | |
new_x | A 16-bit fixed-point value which contains a new input sample signal. | |
d | A 16-bit fixed-point value which contains the current sample of the reference's signal. | |
y | A pointer on a 16-bit fixed-point value corresponding to the current sample of the output signal. | |
e | A pointer on a 16-bit fixed-point value corresponding to the current sample of the output error signal. |
Definition at line 56 of file filt_dsp16_lms.c.
References DSP16_QB, and DSP_LMS_MU.
00057 { 00058 int i; 00059 S32 temp; 00060 00061 x[0] = new_x; 00062 00063 temp = 0; 00064 // Performed a FIR 00065 for(i=0; i<size; i+=4) 00066 { 00067 temp += (((S32) w[i])*((S32) x[i])); 00068 temp += (((S32) w[i+1])*((S32) x[i+1])); 00069 temp += (((S32) w[i+2])*((S32) x[i+2])); 00070 temp += (((S32) w[i+3])*((S32) x[i+4])); 00071 } 00072 *y = temp >> (DSP16_QB); 00073 00074 // Error calculation 00075 *e = d - *y; 00076 00077 // Refresh the w coefficients 00078 for(i=0; i<size; i+=4) 00079 { 00080 w[i] += ((((S32) *e)*((S32) x[i]))) >> (DSP_LMS_MU - 1 + DSP16_QB); 00081 w[i+1] += ((((S32) *e)*((S32) x[i+1]))) >> (DSP_LMS_MU - 1 + DSP16_QB); 00082 w[i+2] += ((((S32) *e)*((S32) x[i+2]))) >> (DSP_LMS_MU - 1 + DSP16_QB); 00083 w[i+3] += ((((S32) *e)*((S32) x[i+3]))) >> (DSP_LMS_MU - 1 + DSP16_QB); 00084 } 00085 00086 // Shift the circular buffer 00087 for(i=size-1; i>0; i-=4) 00088 { 00089 x[i] = x[i-1]; 00090 x[i-1] = x[i-2]; 00091 x[i-2] = x[i-3]; 00092 x[i-3] = x[i-4]; 00093 } 00094 }
void dsp16_filt_lpfirdesign | ( | dsp16_t * | c, | |
int | fc, | |||
int | fs, | |||
int | order, | |||
dsp16_win_fct_t | dsp16_win_fct, | |||
dsp_filt_design_options_t | options | |||
) |
16-bit fixed point version of the low-pass FIR filter design.
c | A pointer on a 16-bit fixed-point vector of "order" size, used to store the coefficients of the filter designed. | |
fc | Cutoff frequency of the low-pass filter. | |
fs | Sample rate of the signal to filter. | |
order | Order of the filter to design. | |
dsp16_win_fct | A window to apply to the coefficients. If this parameter is NULL, then no window is applied. | |
options | Specific options for the design. |
Definition at line 68 of file filt_dsp16_lpfirdesign.c.
References CST_PI, DSP16_MUL_TO_DSP32, dsp16_op_abs(), dsp16_op_div(), dsp16_op_mul(), DSP16_Q, DSP16_QB, dsp16_vect_max(), dsp16_vect_min(), DSP32_DIV_TO_DSP16, dsp32_op_sin(), DSP_FILT_DESIGN_OPTIONS_NORMALIZE, DSP_Q, and Max.
Referenced by dsp16_resampling_setup().
00069 { 00070 S32 n_fc; 00071 S32 s32_temp1; 00072 S32 s32_temp2; 00073 dsp16_t dsp16_temp; 00074 int num, i; 00075 dsp32_t dsp32_temp; 00076 dsp16_t norm; 00077 00078 if (!order) 00079 return; 00080 // Calculate normalized cutoff frequency mulitplied by 2 00081 n_fc = (((S32) fc) << (DSP16_QB + 1)) / fs; 00082 num = order / 2 + 1; 00083 00084 if (options == DSP_FILT_DESIGN_OPTIONS_NORMALIZE) 00085 { 00086 // Calculate ideal lowpass filter impulse response coefficients: 00087 c[0] = (n_fc / 2); 00088 00089 for(i=1; i<order; i++) 00090 { 00091 s32_temp1 = (S32) DSP_Q(32 - DSP16_QB, DSP16_QB, (double) i + 1.) / num; 00092 s32_temp2 = (S32) DSP_Q(32 - DSP16_QB, DSP16_QB, CST_PI * ((double) i + 1.)) / num; 00093 s32_temp2 >>= 1; 00094 dsp32_temp = dsp32_op_sin(DSP16_MUL_TO_DSP32(s32_temp1, n_fc)); 00095 dsp16_temp = DSP32_DIV_TO_DSP16(dsp32_temp, s32_temp2); 00096 c[i] = dsp16_temp; 00097 } 00098 00099 norm = dsp16_op_abs(dsp16_vect_max(c, order)); 00100 norm = Max(norm, dsp16_op_abs(dsp16_vect_min(c, order))); 00101 00102 // Create the window or fills the buffer with ones 00103 if (dsp16_win_fct) 00104 dsp16_win_fct(c, order); 00105 else 00106 { 00107 for(i=0; i<order; i++) 00108 c[i] = DSP16_Q(1.); 00109 } 00110 00111 c[0] = dsp16_op_div(dsp16_op_mul(c[0], n_fc), norm); 00112 for(i=1; i<order; i++) 00113 { 00114 s32_temp1 = (S32) DSP_Q(32 - DSP16_QB, DSP16_QB, (double) i + 1.) / num; 00115 s32_temp2 = (S32) DSP_Q(32 - DSP16_QB, DSP16_QB, CST_PI * ((double) i + 1.)); 00116 s32_temp2 = (((S64) s32_temp2) * norm) >> DSP16_QB; 00117 s32_temp2 = s32_temp2 / num + 1; 00118 dsp32_temp = dsp32_op_sin(DSP16_MUL_TO_DSP32(s32_temp1, n_fc)); 00119 dsp16_temp = DSP32_DIV_TO_DSP16(dsp32_temp, s32_temp2); 00120 c[i] = dsp16_op_mul(c[i], dsp16_temp); 00121 } 00122 } 00123 else 00124 { 00125 // Create the window or fills the buffer with ones 00126 if (dsp16_win_fct) 00127 dsp16_win_fct(c, order); 00128 else 00129 { 00130 for(i=0; i<order; i++) 00131 c[i] = DSP16_Q(1.); 00132 } 00133 c[0] = dsp16_op_mul(c[0], n_fc); 00134 for(i=1; i<order; i++) 00135 { 00136 s32_temp1 = (S32) DSP_Q(32 - DSP16_QB, DSP16_QB, (double) i + 1.) / num; 00137 s32_temp2 = (S32) DSP_Q(32 - DSP16_QB, DSP16_QB, CST_PI * ((double) i + 1.)) / num; 00138 dsp32_temp = dsp32_op_sin(DSP16_MUL_TO_DSP32(s32_temp1, n_fc)); 00139 dsp16_temp = DSP32_DIV_TO_DSP16(dsp32_temp, s32_temp2); 00140 c[i] = dsp16_op_mul(c[i], dsp16_temp); 00141 } 00142 } 00143 }
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.
x | A 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 whithout filling any of its values. | |
w | A 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. | |
size | The length of the circular buffer (x) and of the coefficient's buffer (w). It must be a multiple of 4. | |
new_x | A 16-bit fixed-point value which contains a new input sample signal. | |
d | A 16-bit fixed-point value which contains the current sample of the reference's signal. | |
y | A pointer on a 16-bit fixed-point value corresponding to the current sample of the output signal. | |
e | A pointer on a 16-bit fixed-point value corresponding to the current sample of the output error signal. |
Definition at line 55 of file filt_dsp16_nlms.c.
References DSP16_QB, and DSP_NLMS_MU.
Referenced by dsp16_echo_cancellation_compute().
00056 { 00057 int i; 00058 static S32 normalization = 0; 00059 S32 temp; 00060 00061 x[0] = new_x; 00062 00063 temp = 0; 00064 // Performed a FIR 00065 for(i=0; i<size; i+=4) 00066 { 00067 temp += (((S32) w[i])*((S32) x[i])); 00068 temp += (((S32) w[i+1])*((S32) x[i+1])); 00069 temp += (((S32) w[i+2])*((S32) x[i+2])); 00070 temp += (((S32) w[i+3])*((S32) x[i+3])); 00071 } 00072 *y = temp >> (DSP16_QB); 00073 00074 // Error calculation 00075 *e = d - *y; 00076 00077 // Update the normalization coefficient 00078 normalization += ((((S32) new_x)*((S32) new_x))) >> (DSP16_QB); 00079 00080 00081 if (!normalization) 00082 normalization = 1; 00083 00084 #if !(DSP_OPTIMIZATION & DSP_OPTI_ACCURACY) 00085 temp = ((S32) *e << DSP16_QB)/normalization; 00086 if (temp > 0x7FFF) 00087 temp = 0x7FFF; 00088 else if (temp < -0x8000) 00089 temp = -0x8000; 00090 #endif 00091 00092 // Refresh the w coefficients 00093 for(i=0; i<size; i+=4) 00094 { 00095 #if (DSP_OPTIMIZATION & DSP_OPTI_ACCURACY) 00096 w[i] += ((((((S32) *e)*((S32) x[i])))/normalization) >> (DSP_NLMS_MU - 1)); 00097 w[i+1] += ((((((S32) *e)*((S32) x[i+1])))/normalization) >> (DSP_NLMS_MU - 1)); 00098 w[i+2] += ((((((S32) *e)*((S32) x[i+2])))/normalization) >> (DSP_NLMS_MU - 1)); 00099 w[i+3] += ((((((S32) *e)*((S32) x[i+3])))/normalization) >> (DSP_NLMS_MU - 1)); 00100 #else 00101 w[i] += (temp*((S32) x[i])) >> (DSP_NLMS_MU - 1 + DSP16_QB); 00102 w[i+1] += (temp*((S32) x[i+1])) >> (DSP_NLMS_MU - 1 + DSP16_QB); 00103 w[i+2] += (temp*((S32) x[i+2])) >> (DSP_NLMS_MU - 1 + DSP16_QB); 00104 w[i+3] += (temp*((S32) x[i+3])) >> (DSP_NLMS_MU - 1 + DSP16_QB); 00105 #endif 00106 } 00107 00108 // Update the normalization coefficient 00109 normalization -= ((((S32) x[size-1])*((S32) x[size-1]))) >> (DSP16_QB); 00110 00111 // Shift the circular buffer 00112 for(i=size-1; i>0; i-=4) 00113 { 00114 x[i] = x[i-1]; 00115 x[i-1] = x[i-2]; 00116 x[i-2] = x[i-3]; 00117 x[i-3] = x[i-4]; 00118 } 00119 }
static void dsp32_filt_fir | ( | dsp32_t * | vect1, | |
dsp32_t * | vect2, | |||
int | size, | |||
dsp32_t * | h, | |||
int | h_size | |||
) | [inline, static] |
32 bits fixed point version of the FIR .
vect1 | A pointer on a 32-bit fixed-point vector of (size - h_size + 1) elements corresponding to the output buffer. | |
vect2 | A pointer on a 32-bit fixed-point vector of size elements corresponding to the input buffer. | |
size | The length of the input buffer (must be greater or equals to 4). | |
h | A pointer on a 32-bit fixed-point vector of h_size elements corresponding to the buffer containing the impulse response coefficients. | |
h_size | The length of the impulse response of the filter (must be greater than 7) |
Definition at line 124 of file dsp_filtering.h.
References dsp32_vect_convpart().
00124 { dsp32_vect_convpart(vect1, vect2, size, h, h_size); };
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 .
y | A 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, ...). | |
x | A 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 intput samples have to be set to 0 at the initialization (x-1, x-2, ...). | |
size | The length of the input buffer. | |
num | A 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_size | The length of the numerator's coefficients of the filter (must be a multiple of 2). | |
den | A 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_size | The length of the denominator's coefficients of the filter (must be a multiple of 2). | |
num_prediv | The 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_prediv | The 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. |
Definition at line 56 of file filt_dsp32_iir.c.
References DSP32_QB.
00057 { 00058 int n, m; 00059 S64 sum1, sum2; 00060 dsp32_t *px, *py; 00061 00062 num_prediv = DSP32_QB - num_prediv; 00063 den_prediv = DSP32_QB - den_prediv; 00064 00065 for(n=0; n<size; n++) 00066 { 00067 sum1 = 0; 00068 sum2 = 0; 00069 px = &x[n]; 00070 for(m=0; m<num_size; m++) 00071 sum1 += ((S64) num[m] * (S64) px[-m]); 00072 py = &y[n-1]; 00073 for(m=0; m<den_size; m++) 00074 sum2 += ((S64) den[m] * (S64) py[-m]); 00075 00076 sum1 >>= num_prediv; 00077 sum2 >>= den_prediv; 00078 00079 y[n] = sum1 - sum2; 00080 } 00081 }
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 .
vect1 | A pointer on a 32-bit fixed-point vector of (size - num_size + 1) elements corresponding to the output buffer. | |
vect2 | A pointer on a 32-bit fixed-point vector of size elements corresponding to the input buffer. | |
size | The length of the input buffer. | |
num | A 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_size | The length of the numerator's coefficients of the filter. | |
den | A 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_size | The length of the denominator's coefficients of the filter. | |
num_prediv | The 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_prediv | The 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. |
Definition at line 54 of file filt_dsp32_iirpart.c.
References DSP32_QB.
00055 { 00056 int n, m; 00057 S64 sum1, sum2; 00058 dsp32_t *px, *py; 00059 00060 num_prediv = DSP32_QB - num_prediv; 00061 den_prediv = DSP32_QB - den_prediv; 00062 00063 // Compute the first den_size elements 00064 // to initialize the vect1 00065 for(n=0; n<den_size; n++) 00066 { 00067 sum1 = 0; 00068 sum2 = 0; 00069 00070 px = &x[n+num_size-1]; 00071 for(m=0; m<num_size; m++) 00072 sum1 += ((S64) num[m])*((S64) px[-m]); 00073 py = &y[n-1]; 00074 for(m=0; m<n; m++) 00075 sum2 += ((S64) den[m])*((S64) py[-m]); 00076 00077 sum1 >>= num_prediv; 00078 sum2 >>= den_prediv; 00079 00080 y[n] = sum1 - sum2; 00081 } 00082 00083 for(; n<=(size-num_size); n++) 00084 { 00085 sum1 = 0; 00086 sum2 = 0; 00087 00088 px = &x[n+num_size-1]; 00089 for(m=0; m<num_size; m++) 00090 sum1 += ((S64) num[m])*((S64) px[-m]); 00091 py = &y[n-1]; 00092 for(m=0; m<den_size; m++) 00093 sum2 += ((S64) den[m])*((S64) py[-m]); 00094 00095 sum1 >>= num_prediv; 00096 sum2 >>= den_prediv; 00097 00098 y[n] = sum1 - sum2; 00099 } 00100 }
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.
x | A 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 whithout filling any of its values. | |
w | A 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. | |
size | The length of the circular buffer (x) and of the coefficient's buffer (w). | |
new_x | A 32-bit fixed-point value which contains a new input sample signal. | |
d | A 32-bit fixed-point value which contains the current sample of the reference's signal. | |
y | A pointer on a 32-bit fixed-point value corresponding to the current sample of the output signal. | |
e | A pointer on a 32-bit fixed-point value corresponding to the current sample of the output error signal. |
Definition at line 56 of file filt_dsp32_lms.c.
References DSP32_QB, and DSP_LMS_MU.
00057 { 00058 int i; 00059 S64 temp; 00060 00061 x[0] = new_x; 00062 00063 temp = 0; 00064 // Performed a FIR 00065 for(i=0; i<size; i+=4) 00066 { 00067 temp += (((S64) w[i])*((S64) x[i])); 00068 temp += (((S64) w[i+1])*((S64) x[i+1])); 00069 temp += (((S64) w[i+2])*((S64) x[i+2])); 00070 temp += (((S64) w[i+3])*((S64) x[i+4])); 00071 } 00072 *y = temp >> (DSP32_QB); 00073 00074 // Error calculation 00075 *e = d - *y; 00076 00077 // Refresh the w coefficients 00078 for(i=0; i<size; i+=4) 00079 { 00080 w[i] += ((((S64) *e)*((S64) x[i]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00081 w[i+1] += ((((S64) *e)*((S64) x[i+1]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00082 w[i+2] += ((((S64) *e)*((S64) x[i+2]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00083 w[i+3] += ((((S64) *e)*((S64) x[i+3]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00084 } 00085 00086 // Shift the circular buffer 00087 for(i=size-1; i>0; i-=4) 00088 { 00089 x[i] = x[i-1]; 00090 x[i-1] = x[i-2]; 00091 x[i-2] = x[i-3]; 00092 x[i-3] = x[i-4]; 00093 } 00094 }
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.
x | A 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 whithout filling any of its values. | |
w | A 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. | |
size | The length of the circular buffer (x) and of the coefficient's buffer (w). | |
new_x | A 32-bit fixed-point value which contains a new input sample signal. | |
d | A 32-bit fixed-point value which contains the current sample of the reference's signal. | |
y | A pointer on a 32-bit fixed-point value corresponding to the current sample of the output signal. | |
e | A pointer on a 32-bit fixed-point value corresponding to the current sample of the output error signal. |
Definition at line 55 of file filt_dsp32_nlms.c.
References DSP32_QB, and DSP_NLMS_MU.
Referenced by dsp32_echo_cancellation_compute().
00056 { 00057 int i; 00058 static S64 normalization = 0; 00059 S64 temp; 00060 00061 x[0] = new_x; 00062 00063 temp = 0; 00064 // Performed a FIR 00065 for(i=0; i<size; i+=4) 00066 { 00067 temp += (((S64) w[i])*((S64) x[i])); 00068 temp += (((S64) w[i+1])*((S64) x[i+1])); 00069 temp += (((S64) w[i+2])*((S64) x[i+2])); 00070 temp += (((S64) w[i+3])*((S64) x[i+3])); 00071 } 00072 *y = temp >> (DSP32_QB); 00073 00074 // Error calculation 00075 *e = d - *y; 00076 00077 // Update the normalization coefficient 00078 normalization += ((((S64) new_x)*((S64) new_x))) >> (DSP32_QB); 00079 00080 #if !(DSP_OPTIMIZATION & DSP_OPTI_ACCURACY) 00081 temp = (((S64) *e) << DSP32_QB)/normalization; 00082 00083 if (temp > ((S64) 0x7FFFFFFF)) 00084 temp = (S64) 0x7FFFFFFF; 00085 else if (temp < -((S64) 0x80000000)) 00086 temp = -((S64) 0x80000000); 00087 #endif 00088 00089 if (!normalization) 00090 normalization = 1; 00091 00092 // Refresh the w coefficients 00093 for(i=0; i<size; i+=4) 00094 { 00095 #if (DSP_OPTIMIZATION & DSP_OPTI_ACCURACY) 00096 w[i] += (((((S64) *e)*((S64) x[i])))/normalization) >> (DSP_NLMS_MU - 1); 00097 w[i+1] += (((((S64) *e)*((S64) x[i+1])))/normalization) >> (DSP_NLMS_MU - 1); 00098 w[i+2] += (((((S64) *e)*((S64) x[i+2])))/normalization) >> (DSP_NLMS_MU - 1); 00099 w[i+3] += (((((S64) *e)*((S64) x[i+3])))/normalization) >> (DSP_NLMS_MU - 1); 00100 #else 00101 w[i] += ((temp*((S64) x[i])) >> (DSP_NLMS_MU - 1 + DSP32_QB)); 00102 w[i+1] += ((temp*((S64) x[i+1])) >> (DSP_NLMS_MU - 1 + DSP32_QB)); 00103 w[i+2] += ((temp*((S64) x[i+2])) >> (DSP_NLMS_MU - 1 + DSP32_QB)); 00104 w[i+3] += ((temp*((S64) x[i+3])) >> (DSP_NLMS_MU - 1 + DSP32_QB)); 00105 #endif 00106 } 00107 00108 // Update the normalization coefficient 00109 normalization -= ((((S64) x[size-1])*((S64) x[size-1]))) >> (DSP32_QB); 00110 00111 // Shift the circular buffer 00112 for(i=size-1; i>0; i-=4) 00113 { 00114 x[i] = x[i-1]; 00115 x[i-1] = x[i-2]; 00116 x[i-2] = x[i-3]; 00117 x[i-3] = x[i-4]; 00118 } 00119 }