void proces_buffer(void) { int i,j; uint32_t *txbuf, *rxbuf; if(tx_proc_buffer == PING) txbuf = dma_tx_buffer_ping; else txbuf = dma_tx_buffer_pong; if(rx_proc_buffer == PING) rxbuf = dma_rx_buffer_ping; else rxbuf = dma_rx_buffer_pong; for (i = 0; i < (DMA_BUFFER_SIZE) ; i++) { y[i] = 0.0; x[k++] = (float32_t)(prbs()); if (k >= N) k = 0; for (j=0 ; j<N ; j++) { y[i] += h[j]*x[k++]; if (k >= N) k = 0; } } for (i=0 ; i<(DMA_BUFFER_SIZE) ; i++){ *txbuf++ = (uint32_t)((((short)(y[i])<<16 & 0xFFFF0000)) + ((short)(y[i]) & 0x0000FFFF)); } tx_buffer_empty = 0; rx_buffer_full = 0; }
void I2S_HANDLER(void) { /****** I2S Interruption Handler *****/ int16_t section; // index for section number float32_t input; // input to each section float32_t wn,yn; // intermediate and output values audio_IN = i2s_rx(); input = (float32_t)(prbs()); adapt_in = input; gpio_set(P2_10, HIGH); // algorithm timing // IIR routine for (section=0 ; section< NUM_SECTIONS ; section++) { wn = input - a[section][1]*w[section][0] - a[section][2]*w[section][1]; yn = b[section][0]*wn + b[section][1]*w[section][0] + b[section][2]*w[section][1]; w[section][1] = w[section][0]; w[section][0] = wn; input = yn; // output of current section is input to next } // IIR output now in yn // could choose from a range of signals to output audio_chL = (int16_t)(error); audio_chR = (int16_t)(adaptfir_out); arm_lms_f32(&S, &adapt_in, &yn, &adaptfir_out, &error, BLOCK_SIZE); gpio_set(P2_10, LOW); audio_OUT = ((audio_chR<<16 & 0xFFFF0000)) + (audio_chL & 0x0000FFFF); //Put the two channels toguether again i2s_tx(audio_OUT); }
void system_path_id(float *pBufADC1, float *pBufADC2, float *pBufDAC) { int i; float forwardPathOutput, inversePriPathOutput; float forwardPathAdaptOutput, priPathAdaptOutput; float errForwardPath, errPriPath; float mu= SYS_ID_LMS_MU; inversePriPathOutput= *pBufADC1; /*读取主声信道的逆向输出数据,来自参考传声器*/ forwardPathOutput= *pBufADC2; /*读取前向信道的输出数据,来自误差传声器*/ /*将伪随机噪声数据分别作为两个自适应滤波器(一个识别前向信道模型,另一个识别主声信道逆向模型)的输入*/ dlyAdaptPriPath[0]= prbs(); dlyAdaptForPath[0]= dlyAdaptPriPath[0]; *pBufDAC= dlyAdaptPriPath[0]; /*将伪随机噪声数据发送DAC*/ forwardPathAdaptOutput= 0.0; priPathAdaptOutput= 0.0; /*分别计算前向信道模型和主声信道逆向模型的输出*/ /*本消声处理程序设定前向信道模型和主声信道逆向模型的阶数相等*/ for(i= 0; i< ORDER_FORWARD_PATH_FILTER +1; i++) { forwardPathAdaptOutput += dlyAdaptForPath[i]*forwardPathCoe[i]; priPathAdaptOutput += dlyAdaptPriPath[i]*inversePrimaryPathCoe[i]; } /*计算误差信号*/ errForwardPath= forwardPathOutput- forwardPathAdaptOutput; errPriPath= inversePriPathOutput- priPathAdaptOutput; /*计算信道模型的权系数*/ for(i= ORDER_FORWARD_PATH_FILTER; i >= 0; i--) { forwardPathCoe[i] = forwardPathCoe[i] + 2*mu*errForwardPath*dlyAdaptForPath[i]; inversePrimaryPathCoe[i]= inversePrimaryPathCoe[i] +2*mu*errPriPath*dlyAdaptPriPath[i]; } /*更新自适应滤波器的延迟线,即输入数据*/ for(i= ORDER_FORWARD_PATH_FILTER; i > 0; i--) { dlyAdaptForPath[i]= dlyAdaptForPath[i-1]; dlyAdaptPriPath[i]= dlyAdaptPriPath[i-1]; } mm= mm +1; if(mm >= 50000) /*当发送的宽带伪随机噪声超过5秒时,系统模型识别过程结束*/ { system_is_identified= TRUE; mm= 0; } }
int main(int argc, char **argv) { init(); while (count <= m) { timer(); prbs(N, p, amp, offset); store_data(); count++; } get_data(); reset(); return EXIT_SUCCESS; }
void proces_buffer(void) { int ii; uint32_t *txbuf, *rxbuf; if(tx_proc_buffer == PING) txbuf = dma_tx_buffer_ping; else txbuf = dma_tx_buffer_pong; if(rx_proc_buffer == PING) rxbuf = dma_rx_buffer_ping; else rxbuf = dma_rx_buffer_pong; for (ii=0 ; ii<(DMA_BUFFER_SIZE) ; ii++){ x[ii] = (float32_t)(prbs()); } arm_fir_f32(&S,x,y,DMA_BUFFER_SIZE); for (ii=0 ; ii<(DMA_BUFFER_SIZE) ; ii++){ *txbuf++ = (((short)(y[ii])<<16 & 0xFFFF0000)) + ((short)(y[ii]) & 0x0000FFFF); } tx_buffer_empty = 0; rx_buffer_full = 0; }