文章目录
前言
本文主要大致介绍基于MATLAB的FIR滤波器设计方法。
提示:以下是本篇文章正文内容,下面案例可供参考
一、FIR滤波器参数
采样频率:1000Hz
通带截止频率:150Hz
阻带截至频率:200Hz
二、设计步骤
1.命令框中输入filterDesigner调用滤波器设计工具
2.设置滤波器参数
3.设计滤波器
4.生成MATLAB代码
代码如下(示例):
% function Hd = filter2
%FILTER2 返回离散时间滤波器对象。
% MATLAB Code
% Generated by MATLAB(R) 9.10 and DSP System Toolbox 9.12.
% Generated on: 31-Dec-2022 08:47:26
% Equiripple Lowpass filter designed using the FIRPM function.
% All frequency values are in Hz.
Fs = 1000; % Sampling Frequency
Fpass = 150; % Passband Frequency
Fstop = 200; % Stopband Frequency
Dpass = 0.057501127785; % Passband Ripple
Dstop = 0.0001; % Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs/2), [1 0], [Dpass, Dstop]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);
% [EOF]
5.运行滤波器文件,Hd即为设计好的滤波器
6.测试设计好的滤波器
测试代码如下:
% 滤波器测试文件
% 随机生成50个数
y1 = rand(50, 1);
y2 = filter(Hd,y1);
subplot(211)
plot(y1);
title("未滤波前图像");
subplot(212)
plot(y2);
title("滤波后图像");
总结
本文主要大致介绍了利用MATLAB的滤波器设计工具filterDesigner进行FIR滤波器设计的基本方法,具体的操作还需根据具体的设计要求而定,文章中存在一定的不足之处,望读者包容与指正。