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;
代码逐句详细解释内容:该函数是MATLAB中GUI界面的一个回调函数,实现了一个带通滤波器的功能。
第一部分定义了全局变量x、Fs、tl、x2,这些变量在整个GUI界面中都可用,x是输入的信号,Fs是采样率,tl是时间轴,x2是经过滤波后的信号。
第二部分获取了用户输入的带通滤波器的参数fp和fs。根据用户选择的滤波器类型,选择对应的滤波器设计方法,如butter、fir1等,并绘制滤波器的频率响应图。然后使用设计好的滤波器对输入信号进行滤波处理,得到经过滤波后的信号x1。
第三部分将经过滤波后的信号x1绘制在GUI界面上,包括时间域波形图和频域幅度谱图。最后将经过滤波后的信号x1赋值给全局变量x2,以供后续处理使用。
整个函数实现了一个带通滤波器的设计和信号滤波的功能,用户可以通过GUI界面输入滤波器参数,选择滤波器类型,并实时查看滤波效果。
原文地址: https://www.cveoy.top/t/topic/nKga 著作权归作者所有。请勿转载和采集!