2022 05月14日
作者: 小白哥
  • 浏览: 1641
  • 收藏:0
  • 点赞:2
MATLAB设计带通和带阻巴特沃斯滤波器
%% 设计通带为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)')

1.jpg

1.jpg

%% 设计阻带为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)')

1.jpg

1.jpg

注:bandpass_butterworth和bandstop_butterworth函数不为MATLAB自带函数。

bandpass_butterworth和bandstop_butterworth.rar



  

发表评论

评论列表


没有评论

筛选

文章分类

热门文章

企业招聘网址

2023-12-07  浏览:2998次

BC1.2协议介绍

2023-06-14  浏览:2897次

USB2.0速度识别

2023-10-23  浏览:1331次