I want to realize the LMS(least mean square) algorithm on xCORE-200 MC audio. Actually, my goal is to make an ANC headphone based on XMOS processor. Now I have managed to collect the noise signal and the error signal by microphones. And I tried to use the xCORE-200 DSP library. I created a new LMS function named "dsp_adaptive_new_lms" based on the original function: dsp_adaptive_lms in the library as follows:

The original: which can be seen in the "app_adaptive" from the example AN00209

Code: Select all

`int32_t dsp_adaptive_lms`

(

int32_t source_sample,

int32_t reference_sample,

int32_t* error_sample,

const int32_t* filter_coeffs,

int32_t* state_data,

const int32_t num_taps,

const int32_t mu,

const int32_t q_format

) {

int32_t output_sample, mu_err;

// Output signal y[n] is computed via standard FIR filter:

// y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[N-1] * x[n-N+1]

output_sample = dsp_filters_fir( source_sample, filter_coeffs, state_data, num_taps, q_format );

// Error equals difference between reference and filter output:

// e[n] = d[n] - y[n]

*error_sample = reference_sample - output_sample;

// FIR filter coefficients b[k] are updated on a sample-by-sample basis:

// b[k] = b[k] + mu_err * x[n-k] --- where mu_err = e[n] * mu

mu_err = dsp_math_multiply( *error_sample, mu, q_format );

dsp_vector_muls_addv( state_data, mu_err, (int32_t*) filter_coeffs, (int32_t*) filter_coeffs, num_taps, q_format );

return output_sample;

}

my version:

Code: Select all

`int32_t dsp_adaptive_new_lms`

(

int32_t source_sample,

//int32_t reference_sample,

int32_t* error_sample,

const int32_t* filter_coeffs,

int32_t* state_data,

const int32_t num_taps,

const int32_t mu,

const int32_t q_format

) {

int32_t output_sample, mu_err;

// Output signal y[n] is computed via standard FIR filter:

// y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[N-1] * x[n-N+1]

output_sample = dsp_filters_fir( source_sample, filter_coeffs, state_data, num_taps, q_format );

output_sample = - output_sample; //changed , reverse, and my "error example" is from the mic, not calculated as the original shows

// FIR filter coefficients b[k] are updated on a sample-by-sample basis:

// b[k] = b[k] + mu_err * x[n-k] --- where mu_err = e[n] * mu

//changed ,I tried to add an "if" condition.

//if(fabs(F31(*error_sample))!=0){

mu_err = dsp_math_multiply( *error_sample, mu, q_format );

// dsp_vector_muls_addv( state_data, mu_err, (int32_t*) filter_coeffs, (int32_t*) filter_coeffs, num_taps, q_format );

// }

return output_sample;

}

If I annotate the dsp_vector_muls_addv function, i.e. just apply a FIR filter to the source example and then reverse it, everything is OK, I can view the noise and error signal through xSCOPE (as follows)and the microphones work fine.

However, if I let the yellow line of code in, everything seems to be stopped, I can see no signals but 2 horizontal lines as follows:

In addition , I can hear a buzz at the beginning of the running. And I can't figure out the reason. The dsp_vector_muls_addv function is the core part of the algorithm with the purpose of adjusting the coefficients of the FIR filter, without which the WHOLE project would be a failure.

Thank you very much!!!!

cjf