资源简介
IIR滤波器,结合硬件,可完美实现滤波。如果无相应硬件,可修改选项,改为软件导入。
代码片段和文件信息
/********************************************************************************
The programme of the IIR filter (Butterworth type 2 order).
Using INT2 to get the input signal.
Array x is the input signal from A/D the length is 256 32-bit floating point.
Array y the filter output signal the length is 256 32-bit floating point.
Array a and b are the coefficient of the IIR filter the length is 3.
*********************************************************************************/
#pragma CODE_SECTION(vect“vect“)
#include “stdio.h“
#include “math.h“
#define pi 3.1415927
#define IMR *(pmem+0x0000)
#define IFR *(pmem+0x0001)
#define PMST *(pmem+0x001D)
#define SWCR *(pmem+0x002B)
#define SWWSR *(pmem+0x0028)
#define AL *(pmem+0x0008)
#define CLKMD 0x0058 /* clock mode reg*/
#define Len 256
double fsnlpassnlstopnhpassnhstopa[3]b[3]x[Len]y[Len];
void biir2lpdes(double fs double nlpass double nlstop double a[] double b[]);
unsigned int *pmem=0;
ioport unsigned char port8002;
int in_x[Len];
int m = 0;
int intnum = 0;
double xmean=0;
int n=0;
int flag = 0;
int ijpk=0;
double w2w1w0;
void cpu_init()
{
*(unsigned int*)CLKMD=0x0; //switch to DIV mode clkout= 1/2 clkin
while(((*(unsigned int*)CLKMD)&01)!=0);
*(unsigned int*)CLKMD=0x77ff; //switch to PLL
PMST=0x3FA0;
SWWSR=0x7fff;
SWCR=0x0000;
IMR=0;
IFR=IFR;
}
interrupt void int1()
{
in_x[m] = port8002;
in_x[m] &= 0x00FF;
m++;
intnum = m;
if (intnum == Len)
{
intnum = 0;
xmean = 0.0;
for (i=0; i {
xmean = in_x[i] + xmean;
}
xmean = 1.0*xmean/Len;
for (i=0; i {
x[i] = 1.0*(in_x[i] - xmean);
}
for (i=0; i {
w2 = x[i]-a[1]*w1-a[2]*w0;
y[i] = b[0]*w2+b[1]*w1+b[2]*w0;
w0 = w1;
w1 = w2;
}
m=0;
flag = 1;
}
}
void biir2lpdes(double fs double nlpass double nlstop double a[] double b[])
{
int iuv;
double wpompgsat;
wp=nlpass*2*pi;
omp=tan(wp/2.0);
gsa=omp*omp;
for (i=0; i<=2; i++)
{
u=i%2;
v=i-1;
a[i]=gsa*pow(2u)-sqrt(2)*omp*v+pow(-2u);
}
for (i=0; i<=2; i++)
{ u=i%2;
b[i]=gsa*pow(2u);
}
t=a[0];
for (i=0; i<=2; i++)
{ a[i]=a[i]/t;
b[i]=b[i]/t;
}
}
void set_int()
{
asm(“ ssbx intm“);
IMR=IMR|0x0004;
asm(“ rsbx intm“);
}
void main(void)
{
w2=w1=w0=0.0;
cpu_init();
fs = 250000;
nlpass = 0.08;
nlstop = 0.28;
biir2lpdes(fsnlpassnlstopab);
set_int();
for(;;)
{
if (flag == 1)
{
flag = 0; /* set breakpoint here */
}
}
}
void vect()
{
asm(“ .ref _c_int00“);/*pseudoinstruction*/
asm(“ .ref _int1“);
asm(“ b _c_int00“);/* reset */
asm(“ nop“);
asm(“ nop“);
asm(“ rete“);
asm(“ nop“);
asm(“ nop“);
asm(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 529 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\cc_build_Debug.log
文件 6592 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\Debug\Exp-IIR-AD.map
文件 7801 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\Debug\Exp-IIR-AD.obj
文件 12739 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\Debug\Exp-IIR-AD.out
文件 363 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\Debug.lkf
文件 363 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\Debug.lkv
文件 1407 2005-07-18 08:39 exp03_cpu2\Exp-IIR-AD\Exp-IIR-AD.paf
文件 933 2005-07-18 08:38 exp03_cpu2\Exp-IIR-AD\Exp-IIR-AD.pjt
文件 5326 2005-07-18 08:37 exp03_cpu2\Exp-IIR-AD.c
文件 401 2004-03-03 09:29 exp03_cpu2\Exp-IIR-AD.cmd
文件 2744 2002-07-29 22:38 exp03_cpu2\math.h
文件 8397 2002-01-25 10:42 exp03_cpu2\MMRegs.h
文件 154882 1999-08-24 10:51 exp03_cpu2\RTS.LIB
文件 114 2001-10-06 20:15 exp03_cpu2\TYPEDEF.H
目录 0 2009-05-13 18:32 exp03_cpu2\Exp-IIR-AD\Debug
目录 0 2009-05-13 18:32 exp03_cpu2\Exp-IIR-AD
目录 0 2009-05-13 18:32 exp03_cpu2
----------- --------- ---------- ----- ----
202591 17
- 上一篇:c语言实现字典顺序排序
- 下一篇:又一个douglas道格拉斯VC++算法
评论
共有 条评论