📄 filter.c
字号:
/*********************************************************************************
* MCPSB.C v1.00 测试MCBSP同步串口测试的主程序 *
* 版权(c) 2003- 北京合众达电子技术有限责任公司 *
* 设计者: 段立锋 *
**********************************************************************************/
#include "type.h"
#include "codec.h"
#include "sysreg.h"
#include "mcbsp54.h"
#include "memory.h"
#include "math.h"
#include "stdio.h"
#include "tms320.h"
#include "dsplib.h"
//实验操控:
//选择SAMPLELONG 有三个选择,1、2、3。其中1代表256。2代表512。 3代表1024。
//注意,本实验和ad实验、fft实验,
//都需要通过液晶和键盘在信号发生器的设置里面修改参数以生成所需要信号。
//观察数组:dataleft为原始输入数组;filter_result为滤波后数组。
#define SAMPLELONG 3
unsigned int SampleLong;
////////////////////////////////////////////
#define GAINLOWEST 0x0 //代表-34.5DB,每增加一,增加1.5DB
#define ADSAMPL44K 0x23 //采样率为44k
////////////////////////////////////////////
#define NX 0x400
#define NH 0x010
#define NBIQ 0x04
//////////////////////////////////////////////
DATA filter_result[1024];
#pragma DATA_SECTION (fircoef,".fircoef")
DATA fircoef[NH];
float fcoeff[NH]=
{
0.0044 , 0.0086 , 0.0205 , 0.0411 , 0.0685, 0.0978 ,
0.1225 , 0.1366, 0.1366, 0.1225 , 0.0978 , 0.0685,
0.0411 , 0.0205, 0.0086 , 0.0044
} ;//0--2000,fs=44k
#pragma DATA_SECTION (firdbuf,".firdbuf")
DATA firdbuf[NH];
DATA *fdp=firdbuf;
short oflag = 0;
/////////////////////
HANDLE codec_command =0;
HANDLE codec_data=0;
DATA dataleft[2048];
unsigned int dataright[2048];
///////////////////////////////////////////////
unsigned int i= 0;
/******************************************************************************************/
void delay(int period);
/******************************************************************************************/
main()
{
/*设置系统时钟*/
sys_clk(CLK160);
/*打开codec数据接口*/
codec_data = codec_open(CODEC_DATA);
/*打开codec命令接口*/
codec_command = codec_open(CODEC_COMMAND);
/*配置系统存储器*/
memory_set(0x80);
#if SAMPLELONG==1
SampleLong =256;
#endif
#if SAMPLELONG==2
SampleLong =512;
#endif
#if SAMPLELONG==3
SampleLong =1024;
#endif
/*AD前向增益调整*/
codec_lineain_gain(codec_command, GAINLOWEST);
/*AD采样率*/
codec_sample_rate(codec_command, ADSAMPL44K);
/*系数转换为q15格式,清转换buffer*/
fltoq15(fcoeff,fircoef,NH);
for (i=0;i<1024;i++) filter_result[i] =0; // clear output buffer (optional)
for (i=0; i<NH; i++) firdbuf[i] = 0; // clear delay buffer (a must)
fdp = &firdbuf[0];
delay(2000);
//主循环
for(;;)
{
/*启动AD采样*/
for(i = 0;i<SampleLong;i++)
{
/* Wait for sample from handset */
while (!MCBSP_RRDY(CODEC_DATA)) {};
/* Read sample from and write back to handset codec */
/*左通路数据*/
dataleft[i] = *(volatile u16*)DRR1_ADDR(CODEC_DATA);
/* Wait for sample from handset */
while (!MCBSP_RRDY(CODEC_DATA)) {};
/*右通路数据*/
dataright[i] = *(volatile u16*)DRR1_ADDR(CODEC_DATA);
}
/*fir滤波处理*/
oflag=fir(dataleft, fircoef, filter_result, &fdp, NH,NX);
i=0;
}
}
/*********************************************************************************/
void delay(int period)
{
int i, j;
for(i=0; i<period; i++)
{
for(j=0; j<0x1000; j++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -