我现在用的是5502开发板做语音信号自适应算法,程序运行的过程中,输入数组一直有数据输入,但是进入算法计算部分,却没有数据输出了,查看了一下算法的各个数组,lms_w数组始终为0,不知道程序的问题出在哪里了,这个算法之前在28335开发板上面运行没有问题,有声音输出,不知道为什么换了个开发板就不行了。。。还想请各位大神帮忙看一下!!!感激!!!程序如果不加算法,直接接输入输出是没有问题的,能输出期望的声音。
这是读取数据进算法程序部分代码:
void processBuffer(void)
{
Uint32 addr;
static Int16 pingPong=PING;
int output;
for ( i=0;i<LMS_M;i++ ){ h[i]=0;}
while(DMA_FGETH(hDmaRcv,DMACCR,ENDPROG)){
;
}
if(pingPong==PING)
{
addr=((Uint32)gBufferRcvPong)<<1;
DMA_RSETH(hDmaRcv,DMACDSAL,addr&0xffff);
DMA_RSETH(hDmaRcv,DMACDSAU,(addr>>16)&0xffff);
pingPong=PONG;
}
else
{
addr=((Uint32)gBufferRcvPing)<<1;
DMA_RSETH(hDmaRcv,DMACDSAL,addr&0xffff);
DMA_RSETH(hDmaRcv,DMACDSAU,(addr>>16)&0xffff);
pingPong=PING;
}
DMA_FSETH(hDmaRcv,DMACCR,ENDPROG,1);
DMA_FSETH(hDmaXmt,DMACCR,ENDPROG,1);
if(pingPong==PONG)
{
for(i=0;i<(BUFFSIZE/2);i++)
{
gBufferRcvPingleft[i]=gBufferRcvPing[2*i];
gBufferRcvPingright[i]=gBufferRcvPing[2*i+1];
}
for(i=0;i<(BUFFSIZE/2);i++){
if(i<LMS_M)
{
for(j=0;j<=i;j++)
{
lms_x[j]=gBufferRcvPingleft[i-j];
lms_error[j]=gBufferRcvPingright[i-j];
}
}
else
{
for(j=0;j<LMS_M;j++)
{
lms_x[j]=gBufferRcvPingleft[i-j];
lms_error[j]=gBufferRcvPingright[i-j];
}
}
lms_param_in.d=lms_x[i];
lms_param_in.error=&lms_error[0];
lms_param_in.x_ptr=&lms_x[0];
lms_param_in.length_x=LMS_M;
LMS_Gradient_Instantaneous_Estimates(&lms_param_in, &lms_param_out);
gBufferXmtPing[i] =lms_param_out.y;
}
}
addr=((Uint32)gBufferXmtPing)<<1;
DMA_RSETH(hDmaXmt,DMACSSAL,addr&0xffff);
DMA_RSETH(hDmaXmt,DMACSSAU,(addr>>16)&0xffff);
}
else
{
for(i=0;i<(BUFFSIZE/2);i++)
{
gBufferRcvPongleft[i]=gBufferRcvPong[2*i];
gBufferRcvPongright[i]=gBufferRcvPong[2*i+1];}
for(i=0;i<(BUFFSIZE/2);i++){
if(i<LMS_M)
{
for(j=0;j<=i;j++)
{
lms_x[j]=gBufferRcvPongleft[i-j];
lms_error[j]=gBufferRcvPongright[i-j];
}
}
else
{
for(j=0;j<LMS_M;j++)
{
lms_x[j]=gBufferRcvPongleft[i-j];
lms_error[j]=gBufferRcvPongright[i-j];
}
}
lms_param_in.d=lms_x[i];
lms_param_in.error=&lms_error[0];
lms_param_in.x_ptr=&lms_x[0];
lms_param_in.length_x=LMS_M;
LMS_Gradient_Instantaneous_Estimates(&lms_param_in, &lms_param_out);
gBufferXmtPong[i] =lms_param_out.y;
}
addr=((Uint32)gBufferXmtPong)<<1;
DMA_RSETH(hDmaXmt,DMACSSAL,addr&0xffff);
DMA_RSETH(hDmaXmt,DMACSSAU,(addr>>16)&0xffff);
}
DMA_start(hDmaXmt);
DMA_start(hDmaRcv);
}
这部分是算法部分代码:
#include <dotp.h>
#include <string.h>
#include "LMS.h"
#include "math.h"
#pragma DATA_ALIGN(lms_x, 8)
float lms_x[LMS_M];
#pragma DATA_ALIGN(lms_error, 8)
float lms_error[LMS_M];
#pragma DATA_ALIGN(lms_w_forward, 8)
float lms_w_forward[LMS_M]; //用于存储未来一时刻滤波系数向量w(k+1)
#pragma DATA_ALIGN(lms_w, 8)
float lms_w[LMS_M]; //用于存储当前时刻滤波系数矢量w(k)
float a=2,b=0.000000000000025;
Adaptive_Filter_In lms_param_in;
Adaptive_Filter_Out lms_param_out;
void LMS_Gradient_Instantaneous_Estimates(Adaptive_Filter_In *lms_in, Adaptive_Filter_Out* lms_out)
{
int i;
static int FIR_order;
static unsigned char First_in_flag = 1;
static float *w_ptr, *w_forward_ptr, *Temp_w_ptr;
static float *x_ptr,*error;
float temp,yy=0;
if(First_in_flag)
{
First_in_flag = 0;
FIR_order = lms_in->length_x;
memset((void *)lms_w_forward, 0, FIR_order*4);
memset((void *)lms_w, 0, FIR_order*4);
w_forward_ptr = lms_w_forward;
w_ptr = lms_w;
x_ptr = lms_in->x_ptr;
error = lms_in->error;
}
for(i=0; i<FIR_order; i++)
{
yy+=x_ptr[i]*w_ptr[i];
lms_out->y =yy;
}
temp = b*(lms_in->d - lms_out->y); //仿真用的语句
for(i=0; i<FIR_order; i++)
{
w_forward_ptr[i] = w_ptr[i] +temp*x_ptr[i];
}
Temp_w_ptr = w_forward_ptr; //新旧滤波系数矢量指针交换
w_forward_ptr = w_ptr;
w_ptr = Temp_w_ptr;
}
算法包含的头文件:
#ifndef ADAPTIVE_FITLER_H_
#define ADAPTIVE_FITLER_H_
typedef struct
{
float *x_ptr;
int length_x;
float d,*error;
}Adaptive_Filter_In;
typedef struct
{
float y;
}Adaptive_Filter_Out;
#endif /* ADAPTIVE_FITLER_H_ */
#ifndef LMS_H_
#define LMS_H_
#include "Adaptive_filter.h"
#define LMS_M 16
extern float lms_x[LMS_M];
extern float lms_error[LMS_M];
extern Adaptive_Filter_In lms_param_in;
extern Adaptive_Filter_Out lms_param_out;
extern void LMS_Gradient_Instantaneous_Estimates(Adaptive_Filter_In *lms_in, Adaptive_Filter_Out* lms_out);
#endif |