DSP原理(一)


CCS FIR 滤波器设计

一、FIR滤波器设计

Matlab 滤波器工具箱

二、Matlab生成信号

fs = 4096;
N = 1024;
n = 0:N-1;
t = n/fs;
f1 = 50;
f2 = 500;
x1 = sin(2*pi*f1*t);
x2 = sin(2*pi*f2*t);
x = x1 + x2;
plot(t,x)

生成原始信号

三、CCS编写滤波程序

#include <stdio.h>
#include <math.h>
#define pi 3.1415926
#define wLow  2*pi*fLow/fs
#define wHight  2*pi*fHight/fs

int fs=4096;
int fLow = 50;
int fHight = 1000;
short x[1024], h[16], y[1024];
const int BL = 16;
const double B[16] = {
  -0.0001494509574467, 0.002115953581256,-0.007992452353463, 0.006817529310208,
    0.02881270922583,  -0.0839591788376,   0.0279713225981,   0.5263836313841,
     0.5263836313841,   0.0279713225981,  -0.0839591788376,  0.02881270922583,
   0.006817529310208,-0.007992452353463, 0.002115953581256,-0.0001494509574467
};
void fir(const short x[restrict], const double h[restrict], short y[restrict],int n, int m)
{
	int i, j;
	int y0;
	for (j = 0; j < m; j++)
	{
		for (i = 0; i < n; i++)
			y0 += x[i + j] * h[i];
		y[j] = y0;
	}
}

int main(void)
{
	int i;
	for(i=0;i<1024;i++)
	{
		x[i] = 1024*sin(wLow*i) + 1024*sin(wHight*i);
	}

	fir(x,B,y,16,1000);
    return 0;
}

四、滤波结果

1、滤波前的波形

CSS查看滤波前波形

2、滤波后的波形

通过CSS查看滤波后波形


文章作者: Liuss
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Liuss !
评论
  目录