DSP实验报告材料 高通滤波器

  • 格式:doc
  • 大小:251.00 KB
  • 文档页数:17

高通滤波器设计报告

学号:172030085

: 徐 军

一、实验目的:

1、了解FIR滤波器的原理及使用方法;

2、了解使用Matlab语言设计FIR滤波器的方法;

3、了解用DSP来实现FIR滤波器的设计及编程方法;

4、熟悉在CCS环境下对FIR滤波器的调试方法。

二、实验要求:

设计一个FIR高通滤波器,输入信号是频率为25Hz,50Hz的合成等幅信号,要求滤去25Hz信号成分,保留50Hz的信号成分。

三、实验设计:

本实验要求滤去25Hz的信号成分,保留50Hz的信号,根据耐特斯特准侧,采样频率需要大于最高频率的2倍,即设计的采样频率至少为100Hz的高通滤波器。先在MATLAB中验证设计思路,将得到的滤波器参数调用到DSP程序中,这样可以简化编译汇编连接的过程。然后通过图形仿真查看滤波前后的波形和频谱图。

四、实验步骤:

1、 滤波器的MATLAB语言设计

2、 在MATLAB中确定滤波器的各种参数

3、 滤波器的程序设计

4、 在CCS环境下调试程序

5、 比较滤波前后的效果、观测滤波前后的波形

五、实验程序及结果:

(1)MATLAB程序:

main.m

f1=50;%信号频率Hz

f2=25;%信号频率Hz

fs=1000;%采样频率Hz

N=200;%采样点数

t=(0:N-1)/fs;%采样时间s

signal1=sin(2*pi*f1*t);

signal2=sin(2*pi*f2*t);

y=signal1+signal2;

%%原始信号时域波形图

figure(1);

plot(y);

%%axis([ 0 100 -2.5 2.5]);

hold on;

plot(signal1,'r');

legend('被污染的信号','理想信号');

%%原始信号频谱图

fy=fftshift(fft(y));

f=linspace(-fs/2,fs/2,N);

figure(2);

plot(f,abs(fy));

title('原始信号频谱');

xlabel('f/Hz');

ylabel('幅度');

axis([ 0 100 0 150]);

%%滤波后的时域波形图

figure(3);

Hd = high;

output=filter(Hd,y);

plot(output);

title('滤波后的波形');

%%滤波后的频域波形图

fy=fftshift(fft(output));

f=linspace(-fs/2,fs/2,N);

figure(4);

plot(f,abs(fy));

title('滤波后信号频谱');

xlabel('f/Hz');

ylabel('幅度');

axis([ 0 100 0 150]);

high.m

function Hd = high

%HIGH Returns a discrete-time filter object.

% MATLAB Code

% Generated by MATLAB(R) 8.3 and the Signal Processing Toolbox 6.21.

% Generated on: 12-Jul-2018 09:57:59

% Equiripple Highpass filter designed using the FIRPM function.

% All frequency values are in Hz.

Fs = 1000; % Sampling Frequency

Fstop = 25; % Stopband Frequency

Fpass = 50; % Passband Frequency

Dstop = 0.0001; % Stopband Attenuation

Dpass = 0.057501127785; % Passband Ripple

dens = 20; % Density Factor [N, Fo, Ao, W] = firpmord([Fstop,

Fpass]/(Fs/2), [0 1], [Dstop, Dpass]);

b = firpm(N, Fo, Ao, W, {dens});

Hd = dfilt.dffir(b);

实验结果:

Matlab环境下的滤波前后的时域波形:

滤波前的时域信号(左),滤波后的时域信号(右)

Matlab环境下的滤波前后的频谱图形:

滤波前的频域信号(左),滤波后的频域信号(右)

(2)DSP在CCS下的程序:

源程序:

#include

#include

#include

#include

#include

#include"fdacoefs.h"

#define pi 3.14159

#define N 30

#define length 256

long yn;

int input[length];

int output[length];

void main()

{

int m, n;

int *x;

for(n=0;n<=length-1;n++)

{

input[n]=0;

output[n]=0;

}

for(n=0;n<=length-1;n++)

input[n]=50*sin(2*pi*n*25/200)+50*sin(2*pi*n*50/200);

for(n=0;n<=length-1;n++)

{

x=&input[n];

yn=0;

for(m=0; m <= N-1; m++)

yn+= B[m]*(*x++)+*x;

output[n] = yn>>15;

}

while (1);

}

fdacoefes.h如下:

/*

* Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool

* Generated by MATLAB(R) 9.0 and the Signal Processing Toolbox 7.2.

* Generated on: 27-Jul-2016 11:32:00

*/

/*

* Discrete-Time FIR Filter (real)

* -------------------------------

* Filter Structure : Direct-Form FIR

* Filter Length : 43

* Stable : Yes

* Linear Phase : Yes (Type 1)

*/

/* General type conversion for MATLAB generated C-code */

#include "tmwtypes.h"

/*

* Expected path to tmwtypes.h

* D:\Program Files\MATLAB\R2016a\extern\include\tmwtypes.h

*/

/*

* Warning - Filter coefficients were truncated to fit specified data type.

* The resulting response may not match generated theoretical response.

* Use the Filter Design & Analysis Tool to design accurate

* int16 filter coefficients.

*/

const int BL = 29;

const int16_T B[29] = {

-106, 390, -296, -338, , 619, 281, -782, -1127,

335, 2277, 1564, -3308, -9698, 20109, -9698, -3308, 1564,

2277, 335, -1127, -782, 281, 619, , -338, -296,

390, -106

};

(3)滤波器的仿真测试

新建工程并编译成功后会在“工程所在目录/debeg”文件夹下产生sheji2.out文件,在CCS软件的Run→Load→Load Program里打开这个.out文件,单击OK。

查看滤波效果:

1) 选择菜单栏上的Tools→Graph→Dual Time选项,弹出对话框,按照下图所示设置时域波形参数。

2) 选择菜单栏上的Tools→Graph→FFT Magnitude选项,弹出对话框,按照下图所示设置频域波形参数。