MATLAB 带通滤波器实现及可视化
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;
代码逐句详细解释内容:该函数是用于实现带通滤波器的功能。首先,通过全局变量获取需要滤波的信号x、采样频率Fs、时间轴tl和滤波后的信号x2。然后,获取用户在界面上输入的通带频率和阻带频率,并根据所选滤波器类型(巴特沃斯、矩形、三角、汉明、汉宁、布莱克曼、Kaiser)进行滤波器的设计。滤波器设计完成后,对输入信号进行滤波处理,并在界面上显示滤波后的时域波形图和频谱图,并将滤波后的信号保存到全局变量x2中。
原文地址: http://www.cveoy.top/t/topic/nKsQ 著作权归作者所有。请勿转载和采集!