博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【通信】基于matlab FIR与IIR滤波器低通、高通、带通设计【含Matlab源码 360期】
阅读量:131 次
发布时间:2019-02-27

本文共 5979 字,大约阅读时间需要 19 分钟。

一、简介

1 设计原理

在这里插入图片描述
1.1 滤波器概念
在这里插入图片描述
1.2 数字滤波器的系统函数和差分方程
在这里插入图片描述
1.3 数字滤波器结构的表示
在这里插入图片描述
在这里插入图片描述
1.4 数字滤波器的分类
在这里插入图片描述
在这里插入图片描述
2.1 IIR滤波器与FIR滤波器的分析比较
在这里插入图片描述
2.2 FIR滤波器的原理

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
3 FIR滤波器的仿真步骤
在这里插入图片描述
在这里插入图片描述

二、源代码

function varargout = nain1(varargin)% NAIN1 MATLAB code for nain1.fig%      NAIN1, by itself, creates a new NAIN1 or raises the existing%      singleton*.%%      H = NAIN1 returns the handle to a new NAIN1 or the handle to%      the existing singleton*.%%      NAIN1('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in NAIN1.M with the given input arguments.%%      NAIN1('Property','Value',...) creates a new NAIN1 or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before nain1_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to nain1_OpeningFcn via varargin.%%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one%      instance to run (singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help nain1% Last Modified by GUIDE v2.5 07-Jan-2020 15:57:07% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @nain1_OpeningFcn, ...                   'gui_OutputFcn',  @nain1_OutputFcn, ...                   'gui_LayoutFcn',  [] , ...                   'gui_Callback',   []);if nargin && ischar(varargin{
1}) gui_State.gui_Callback = str2func(varargin{
1});endif nargout [varargout{
1:nargout}] = gui_mainfcn(gui_State, varargin{
:});else gui_mainfcn(gui_State, varargin{
:});end% End initialization code - DO NOT EDIT% --- Executes just before nain1 is made visible.function nain1_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to nain1 (see VARARGIN)% Choose default command line output for nain1handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes nain1 wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = nain1_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout{
1} = handles.output;% --- Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)Fs = 1500;t = 1:1/Fs:6;t=t(1:5000);%写入chirp.wav文件[pyr1,fs]=audioread('1.wav');%声音读取pyr=pyr1(1:5000);n=length(pyr);pyr1=fft(pyr,n); %快速傅里叶变换f=Fs*(0:n/2 - 1)/n;noise1=0.1*sin(20*pi*t);%低频噪声x1=pyr+noise1;%加低频噪声信号n=length(t); %画出加噪之后,其时域频域S=abs(fft(pyr));%原始信号傅里叶变换y1=abs(fft(x1));%原始信号傅里叶变换handles.axes1;subplot(121);plot(pyr);xlabel('时间');ylabel('幅度');title('原始信号波形'); %绘出时域波subplot(122)plot(S((1:length(S)/2)));xlabel('频率');ylabel('幅度');title('原始信号频谱');%% IIR频率变换法%% 双线性变换法% 2.1低通Rp=3;%通带最大衰减dBRs=10;%阻带最小衰减dBWp=1000;%通带截止频率Ws=1200;%阻带截止频率[N,wn]=buttord(Wp,Ws,Rp,Rs,'s');[b,a,k]=buttap(N);[A,B,C,D]=zp2ss(b,a,k);[A,B,C,D]=lp2lp(A,B,C,D,wn);%type='底通';[b,a]=ss2tf(A,B,C,D);[b21,a21]=bilinear(b,a,Fs);[h21,w21]=freqz(b21,a21); %根据参数求出频率响应x21=filter(b21,a21,x1); % 进行低通滤波y21=abs(fft(x21)); % 对滤波后信号做len点FFT变换%2.3 切比雪夫I型滤波器 高通Rp2=2;%通带最大衰减dBRs2=20;%阻带最小衰减dBWp2=3000;%通带截止频率Ws2=3200;%阻带截止频率[N,wn]=cheb1ord(Wp2,Ws2,Rp2,Rs2,'s');%求模拟的低通滤波器阶数和截止频率[b,a,k]=cheb1ap(N,Rp2); %求S域的频率响应的参数[A,B,C,D]=zp2ss(b,a,k);%阻带截止频率[A,B,C,D]=lp2hp(A,B,C,D,wn);%type='高通';[b,a]=ss2tf(A,B,C,D);%状态方程向传递函数转变[b23,a23]=bilinear(b,a,Fs);%利用双线性变换实现S域到Z域转换[h23,w23]=freqz(b23,a23);x23=filter(b23,a23,x1); % 进行稿通滤波y23=abs(fft(x23)); % 对滤波后信号做len点FFT变换% 带通滤波器Rp3=1;Rs3=100;Wp1=1200;Ws1=1000;Wp2=3000;Ws2=3200;Wp3=[Wp1,Wp2];Ws3=[Ws1,Ws2];%wp和ws分别是通带和阻带的频率(截止频率)。当wp和ws为二元矢量时,为带通或带阻滤波器,这时求出的Wn也是二元矢量;当wp和ws为一元矢量时,为低通或高通滤波器:当wp
ws时为高通滤波器。%wp和ws为二元矢量Wp3=[1200 3000]; %设置通带频率Ws3=[1000 3200]; %设置阻带频率Rp3=1; %设置通带波纹系数Rs3=20; %设置阻带波纹系数 [N,wn]=buttord(Wp3,Ws3,Rp3,Rs3,'s');[b,a,k]=buttap(N);[A,B,C,D]=zp2ss(b,a,k);Wn=Wp2-Wp1;Wo=sqrt(Wp2*Wp1);[A,B,C,D]=lp2bp(A,B,C,D,Wo,Wn);% type='带通';[num22,den22]=ss2tf(A,B,C,D);% [b,a]=impinvar(num23,den23,Fs);[b22,a22]=bilinear(num22,den22,Fs);%双线性变换实现S域到Z域的转换[h22,w22]=freqz(b22,a22); %根据参数求出频率响应x22=filter(b22,a22,x1); % 进行低通滤波y22=abs(fft(x22)); % 对滤波后信号做len点FFT变换%% FIR窗函数% 3.1 低通滤波器%该函数采用hanning窗实现低通滤波fp=1000;%通带截止频率fs=2000;%阻带起始频率FS=8000;wp=2*pi*fp/FS;%将模拟通带截止频率转换为数字滤波器频率ws=2*pi*fs/FS;%将模拟阻带起始频率转换为数字滤波器频率wn=(wp+ws)/2/pi;%标准化的截止频率响应Bt=ws-wp;N0=ceil(6.2*pi/Bt);%滤波器长度N=N0+mod(N0+1,2);%设计加窗函数fir1[b31,a31]=fir1(N-1,wn,hanning(N));[h31,w31]=freqz(b31,a31,FS); %得到频率响应x31=filter(b31,a31,x1); % 进行低通滤波y31=abs(fft(x31)); % 对滤波后信号做len点FFT变换% 3.2 通带滤波Fs=8000;fp1=1200;%通带下限截止频率fp2=3000;%通带上限截止频率fs1=1000;fs2=3200;wp1=2*pi*fp1/Fs;%将通带下限截止频率转换为数字滤波器频率wp2=2*pi*fp2/Fs;%将通带上限截止频率转换为数字滤波器频率ws1=2*pi*fs1/Fs;%将通带下限截止频率转换为数字滤波器频率ws2=2*pi*fs2/Fs;%将通带上限截止频率转换为数字滤波器频率Bt=wp1-ws1;N0=ceil(6.2*pi/Bt);N=N0+mod(N0+1,2);wn=[(wp1+ws1)/2/pi,(wp2+ws2)/2/pi];%设计加窗函数fir1[b32,a32]=fir1(N-1,wn,'bandpass',hanning(N));%求滤波器的幅频响应[h32,w32]=freqz(b32,a32,FS);x32=filter(b32,a32,x1);y32=abs(fft(x32)); % 对滤波后信号做len点FFT变换

三、运行结果

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、备注

完整代码或者代写添加QQ 1564658423

往期回顾>>>>>>

转载地址:http://xkqf.baihongyu.com/

你可能感兴趣的文章