📄 conv.c
字号:
#include "stdlib.h"
#include "stdio.h"
#include "typedef.h"
#include "math.h"
#define Length 128
#define Length3 2*Length
unsigned ioport ioport8003;
void Convolveok(
double *Input, // 原始输入数据
double *Impulse, // 冲击响应
double *Output, // 卷积输出结果
Word16 length // 卷积序列长度
)
{
int i,k,p;
double r;
p=0;
for (k=0; k<=length-1; k++)
{
Output[k]=0;
r=0;
for (i=0; i<=p; i++)
{
r=Input[k-i]*Impulse[i];
Output[k] = Output[k]+r;
}
p=p+1;
if (p>length-1) p=length-1;
else p=p;
}
p=length-2;
for (k=length; k<=length+length-1; k++)
{
Output[k]=0;
r=0;
for (i=0; i<=p; i++)
{
r = Input[length-1-i]*Impulse[length-1-p+i];
Output[k] = Output[k]+r;
}
p=p-1;
}
return ;
}
void main()
{
int i,k=0;
double Input[Length] ;
double Impulse[Length] ;
double Output[Length3] ;
int xm;
int *px = (int*)0x3000;
/* 产生随机输入数据以及冲击响应 */
Input[0] = 200;
Impulse[0] = 100 ;
for( i = 1 ; i < Length ; i ++ )
{
if(i < Length/2)
{
Input[i] = 200;
}
else
{
Input[i]=0;
}
}
for( i = 1 ; i < Length ; i ++ )
{
if(i<Length/2)
{
Impulse[i] = 100;
}
else
{
Impulse[i]=0;
}
}
Convolveok( Input, Impulse, Output, Length);
k++;
for(;;)
{
px = (int*)0x3000;
/* 这里可以读取AD数据 */
#if 0
for( i = 0; i < Length; i++)
{
*px++ = ioport8003;
}
#endif
px = (int*)0x3000;
for (i=0; i<Length; i++)
{
xm = *px;
Input[i] = xm;
Impulse[i] = xm;
px++;
}
Convolveok( Input, Impulse, Output, Length);
k++;
}
}
/***********************************************************************
** End of File
***********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -