七颗咖啡豆 发表于 2015-1-7 09:46
代码贴出来
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "math.h"
#define pi 3.14159
#define a 256 //合成信号的采样点数
#define b 32 //h(n)的序列长度
#define c a+b-1 //y(n)的序列长度 =a+b-1
//Uint16 Input[256];
float Sample[a]; //采样后的信号序列
float y1[c]; //输出序列
//窗函数类型:汉宁窗,32阶低通
//截止频率:500Hz
//采样频率:128000Hz
float h=
{ 0.000000000000000 ,
-0.000013777758860 ,
0.000151777363778 ,
0.000847386958184 ,
0.002435227128229 ,
0.005230991441343,
0.009447279018793 ,
0.015146851305749 ,
0.022213255787045 ,
0.030344111481248 ,
0.039069286871622 ,
0.047792710808644 ,
0.055853149149877 ,
0.062596460140636 ,
0.067450035965978 ,
0.069989627660945 ,
0.069989627660945,
0.067450035965978 ,
0.062596460140636 ,
0.055853149149877 ,
0.047792710808644 ,
0.039069286871622 ,
0.030344111481248 ,
0.022213255787045 ,
0.015146851305749 ,
0.009447279018793 ,
0.005230991441343 ,
0.002435227128229 ,
0.000847386958184 ,
0.000151777363778 ,
-0.000013777758860 ,
0.000000000000000
/* 0,0.0006485134778915, 0.002574789225444, 0.005709506486408,
0.009931872420821, 0.01507448912514, 0.02093024026384, 0.02726090869226,
0.03380715986684, 0.04029946500149, 0.04646949558203, 0.05206149892494,
0.05684316398774, 0.06061550768029, 0.06322135360436, 0.06455203566049,
0.06455203566049, 0.06322135360436, 0.06061550768029, 0.05684316398774,
0.05206149892494, 0.04646949558203, 0.04029946500149, 0.03380715986684,
0.02726090869226, 0.02093024026384, 0.01507448912514, 0.009931872420821,
0.005709506486408, 0.002574789225444,0.0006485134778915,0*/
};
/*=============================================================
功能:实现离散线性卷积
算法原理:对位相乘求和法实现卷积
形参:xn(*x所指向的数组长度)、hn(*h所指向的数组长度)为参与
运算的两个卷积序列数组长度
*x、*h为指向两个数组的指针
*y指向输出序列的数组
注意:输出序列长度为xn+hn-1;存放内容为输出数组的 0~(xn+hn-2)。
另外,该函数实现的无符号整型的卷积运算,如果要实现浮点型,需要
将形参的Uint16 hn,Uint16 *x,Uint16 *h,Uint16 *y的Uint16数据格式
改为float或者double型
==============================================================*/
void LinearConvolution(Uint16 xn,Uint16 hn,float *x,float *h,float *y)
{
Uint16 i,j,k,l;
Uint16 yn; //输出序列y的长度
yn=xn+hn-1;
for(i=0;i<yn;i++) y=0; //输出数组初始化
k=yn-1;
for(i=hn-1;i>0;i--) //将*h作为被乘数
{
l=k;
for(j=xn-1;j>0;j--) //数组x[n]的1~(xn-1)与h逐一相乘
{
y[l]+=h*x[j];
l--;
}
y[l]+=x[0]*h;
k--;
}
l=k;
for(j=xn-1;j>0;j--)
{
y[l]+=h[0]*x[j];
l--;
}
y[l]+=x[0]*h[0];
}
void main(void)
{
Uint16 i;
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
for(i=0;i<a;i++) //产生一个a点的三次谐波叠加而成的方波
{
Sample=511*(sin(2*pi*5*i/(a-1))+sin(2*pi*i*5*3/(a-1))/3+sin(2*pi*i*5*5/(a-1))/5)+512;//三个正弦波由5个15个25个包含在256个点的时间中
// DELAY_US(10);+sin(2*pi*i*5*5/(a-1)) +sin(2*pi*i*5*3/(a-1))/4 sin(2*pi*5*i/(a-1))/100+
}
LinearConvolution(a,b,Sample,h,y1);//线性卷积
while(1)
{
// sample=sin(2*pi*5*n/(N-1))+sin(2*pi*15*n/(N-1))/3+sin(2*pi*25*n/(N-1))/5;
/* dly[0]=sample;
yn=0;
for(i=0;i<N;i++) yn+=h*dly;
for(i=N-1;i>0;i--) dly=dly[i-1];
output[n]=yn;
if(n==(N-1)) n=0;
else n++;*/
}
}
//===========================================================================
// No more.
//===========================================================================
|