MATLAB 带通滤波器实现 - GUI 界面交互
function bandpass_pushbutton10_Callback(~, eventdata, handles) % hObject handle to bandpass_pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
global x; global Fs; global tl; global x2;
x1=x;
% fp = [2000,3000];
% fs = [1800,3300];
% Wp = 2fp/Fs;
% Ws = 2fs/Fs;
% if(Wp >= 1)
% Wp = 0.99;
% end
% if(Ws >= 1)
% Ws = 0.99;
% end
fp = get(handles.edit3,'string');
fp = str2double(fp)2;
fs = get(handles.edit4,'string');
fs = str2double(fs)2;
if get(handles.radiobutton1,'value')
[n, Wn]=buttord(Wp,Ws, 2, 15);
[b, a]=butter(n, Wn,'bandpass');
axes(handles.axes3);
[h,w]=freqz(b,a);
plot(w/piFs/2,abs(h));
x1=filter(b,a,x1);
elseif get(handles.radiobutton4,'value')
b2=fir1(30,[fp/Fs fs/Fs],boxcar(31));
axes(handles.axes3);
[h,w]=freqz(b2, 1,512);
plot(w/piFs/2,20log(abs(h)));
x1=fftfilt(b2,x1);
elseif get(handles.radiobutton5,'value')
b2=fir1(30,[fp/Fs fs/Fs], triang(31));
axes(handles.axes3);
[h,w]=freqz(b2, 1,512);
plot(w/piFs/2,20log(abs(h)));
x1=fftfilt(b2,x1);
elseif get(handles.radiobutton6,'value')
b2=fir1(30,[fp/Fs fs/Fs],hamming(31));
axes(handles.axes3);
[h,w]=freqz(b2, 1,512);
plot(w/piFs/2,20log(abs(h)));
x1=fftfilt(b2,x1);
elseif get(handles.radiobutton7,'value')
b2=fir1(30,[fp/Fs fs/Fs],hanning(31));
axes(handles.axes3);
[h,w]=freqz(b2, 1,512);
plot(w/piFs/2,20log(abs(h)));
x1=fftfilt(b2,x1);
elseif get(handles.radiobutton8,'value')
b2=fir1(30,[fp/Fs fs/Fs],blackman(31));
axes(handles.axes3);
[h,w]=freqz(b2, 1,512);
plot(w/piFs/2,20log(abs(h)));
x1=fftfilt(b2,x1);
elseif get(handles.radiobutton9,'value')
b2=fir1(30,[fp/Fs fs/Fs],kaiser(31));
axes(handles.axes3);
[h,w]=freqz(b2, 1,512);
plot(w/piFs/2,20log(abs(h)));
x1=fftfilt(b2,x1);
end;
axes(handles.axes5);
plot(tl,x1);
title('高通滤波器作用下的波形图');
xlabel('鏃堕棿/s');
N=length(x1);
df=Fs/N;
w=[0:df:df(N-1)] - Fs/2; %棰戠巼灏哄害
X=fft(x1);
X=fftshift(X);
axes(handles.axes6);
plot(w,abs(X)/max(abs(X)));
axis([-10000,10000,0,1]);
title('婊ら櫎鍣0鍚庤闊抽璋?');
xlabel('棰戠巼/Hz');
grid on;
x2=x1;
% 该函数实现带通滤波器功能,当用户点击GUI界面上的“带通滤波器”按钮时,就会调用该函数。 % 首先,获取全局变量x、Fs、tl、x2的值。 % 然后,获取GUI界面上用户输入的带通滤波器的通带截止频率和阻带截止频率,并将其转换为数字型变量。 % 接着,根据用户选择的滤波器类型,利用MATLAB内置函数或fir1函数设计滤波器,并绘制其频率响应图。 % 具体而言,当用户选择巴特沃斯滤波器时,调用buttord和butter函数设计滤波器,并绘制其幅频响应图; % 当用户选择其他类型的滤波器时,调用fir1函数设计滤波器,并绘制其幅频响应图。 % 最后,利用filter函数或fftfilt函数对输入信号进行滤波,并将滤波后的信号绘制在GUI界面上的波形图和频谱图中。 % 值得注意的是,该函数中的部分代码被注释掉了,这是因为这部分代码属于一种基于巴特沃斯滤波器的设计方法,与其他滤波器设计方法不同。 % 如果要使用该部分代码,需要取消相应的注释。
原文地址: https://www.cveoy.top/t/topic/nKf7 著作权归作者所有。请勿转载和采集!