MATLAB滤波器设计:带通与带阻巴特沃斯滤波器实现

e小白网址:www.e-xiaobai.com

%% 设计通带为30HZ-60Hz的6阶巴特沃斯带通滤波器
% [filtered_signal,filtb,filta] = bandpass_butterworth(inputsignal,cutoff_freq,Fs,order)
% INPUTS:
% inputsignal = input time series
% cutoff_freqs = filter corner frequencies in the form [f1 f2]
% Fs = data sampling frequency
% order = order of Butterworth filter
% OUTPUTS:
% filtered_signal = the filtered time series
% filtb, filta = filter numerator and denominator (optional)
clear;clc;
t=0:0.005:5;
T=0.005;%时间间隔
Fs=1/T;%采样频率
y1=5*sin(2*pi*10*t)+3*sin(2*pi*40*t)+6*sin(2*pi*80*t);
y2=3*sin(2*pi*40*t);
[filtered_signal,filtb,filta]=bandpass_butterworth(y1,[30 60],Fs,6);
figure(1)
subplot(3,1,1)
plot(t,y1)
title('原始信号')
subplot(3,1,2)
plot(t,filtered_signal)
title('滤波后信号')
subplot(3,1,3)
plot(t,y2)
title('3*sin(2*pi*40*t)')
%滤波器的幅频相频曲线
figure(2)
[h,w] = freqz(filtb,filta,256);
%[h,f] = freqz(filtb,filta,256,Fs);
subplot(2,1,1)
plot(w/pi,20*log10(abs(h)))
%plot(f,20*log10(abs(h)))
xlabel('\times\pi')
%xlabel('Hz')
ylabel('gain(dB)')
subplot(2,1,2)
plot(w/pi,angle(h))
%plot(f,angle(h))
xlabel('\times\pi')
%xlabel('Hz')
ylabel('phase (rad)')

%% 设计阻带为30HZ-60Hz的6阶巴特沃斯带阻滤波器
% [filtered_signal,filtb,filta] = bandstop_butterworth(inputsignal,cutoff_freqs,Fs,order)
% INPUTS:
% inputsignal = input time series
% cutoff_freqs = filter corner frequencies in the form [f1 f2]
% Fs = data sampling frequency
% order = order of Butterworth filter
% OUTPUTS:
% filtered_signal = the filtered time series
% filtb, filta = filter numerator and denominator (optional)
clear;clc;
t=0:0.005:5;
T=0.005;%时间间隔
Fs=1/T;%采样频率
y1=5*sin(2*pi*10*t)+3*sin(2*pi*40*t)+6*sin(2*pi*80*t);
y2=5*sin(2*pi*10*t)+6*sin(2*pi*80*t);
[filtered_signal,filtb,filta]=bandstop_butterworth(y1,[30 60],Fs,6);
figure(1)
subplot(3,1,1)
plot(t,y1)
title('原始信号')
subplot(3,1,2)
plot(t,filtered_signal)
title('滤波后信号')
subplot(3,1,3)
plot(t,y2)
title('5*sin(2*pi*10*t)+6*sin(2*pi*80*t)')
%滤波器的幅频相频曲线
figure(2)
[h,w] = freqz(filtb,filta,256);
%[h,f] = freqz(filtb,filta,256,Fs);
subplot(2,1,1)
plot(w/pi,20*log10(abs(h)))
%plot(f,20*log10(abs(h)))
xlabel('\times\pi')
%xlabel('Hz')
ylabel('gain(dB)')
subplot(2,1,2)
plot(w/pi,angle(h))
%plot(f,angle(h))
xlabel('\times\pi')
%xlabel('Hz')
ylabel('phase (rad)')

注:bandpass_butterworth和bandstop_butterworth函数不为MATLAB自带函数。这两个函数可在e小白官网《MATLAB设计带通和带阻巴特沃斯滤波器》文章中下载。

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空