📄 guide.m
字号:
% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%-------------------------------------------------------------%%得到输入信号的信号频率,幅值global freq_main;global abs_main;global freq_noise1;global abs_noise1;global freq_noise2;global abs_noise2;global freq_sampling;global main_signal;global noise1_signal;global noise2_signal;freq_main = str2double(get(handles.edit1, 'String')); %读主信号频率值abs_main = str2double(get(handles.edit2, 'String')); %读主信号幅值freq_noise1 = str2double(get(handles.edit3, 'String')); %读噪声1信号频率值abs_noise1 = str2double(get(handles.edit4, 'String')); %读噪声1信号幅值freq_noise2 = str2double(get(handles.edit5, 'String')); %读噪声2信号频率值abs_noise2 = str2double(get(handles.edit6, 'String')); %读噪声2信号幅值freq_sampling = str2double(get(handles.edit7, 'String')); %读采样频率%---------------------------------------------------------------------%求出叠加信号allglobal all;N=freq_sampling; %设定采样点数n=0:N-1; %表示信号时间值main_signal=abs_main*cos(2*pi*freq_main*n/N); %表主信号幅度值noise1_signal =abs_noise1*cos(2*pi*freq_noise1*n/N); %表noise1信号幅度值noise2_signal =abs_noise2*cos(2*pi*freq_noise2*n/N); %表noise1信号幅度值all=main_signal+noise1_signal+noise2_signal;%------------------------------------------------------------------------%global filter_iir_fir;global filter_type;global iir_type;global fir_type;global wp1;global wp2;global ws1;global ws2;global rp;global rs;global wp;global ws;global filtered_signal; global a;global b;global n2;global filtertype;filter_iir_fir = get(handles.popupmenu1, 'String');filter_type = get(handles.popupmenu2, 'String');iir_type = get(handles.popupmenu3, 'String');fir_type = get(handles.popupmenu4, 'String');wp1 = str2double(get(handles.edit11, 'String'));wp2 = str2double(get(handles.edit12, 'String'));ws1 = str2double(get(handles.edit13, 'String'));ws2 = str2double(get(handles.edit14, 'String'));rp = str2double(get(handles.edit15, 'String'));rs = str2double(get(handles.edit16, 'String'));wp =[wp1,wp2];ws =[ws1,ws2];n2 =str2double(get(handles.edit17, 'String'));filter_iir_fir=get(handles.popupmenu1,'value');switch filter_iir_fir %滤波类型选择fir iircase 1 %滤波器选中iir filter_type=get(handles.popupmenu2,'value'); switch filter_type %滤波器类型选择lp hp bp bs case 1 %滤波器选中iir中的lp,以下为3种iir方式 %set(handles.edit12,'visible','off'); %set(handles.edit14,'visible','off'); iir_type=get(handles.popupmenu3,'value'); switch iir_type %iir滤波器类型选择 butter,cheby1,cheby2 case 1 %iir_lp_butter滤波器 [nn,wn]=buttord(2*wp1/freq_sampling,2*ws1/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =butter(nn,wn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes2作为画板 cla; %清空画板 plot(n/N,filtered_signal); %画输出的波形 hold on; xlabel('t/s'); ylabel('filtered_signal'); title('butterworth lowpass filter'); case 2 [nn,wn]=cheb1ord(2*wp1/freq_sampling,2*ws1/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =cheby1(nn,rp,wn,'low'); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby1 lowpass filter'); case 3 [nn,wn]=cheb2ord(2*wp1/freq_sampling,2*ws1/freq_sampling,rp,rs); [b,a] =cheby2(nn,rp,wn,'low'); set(handles.edit18,'string',nn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby2 lowpass filter'); end case 2 %选中iir中的hp %set(handles.edit12,'visible','off'); %set(handles.edit14,'visible','off'); iir_type=get(handles.popupmenu3,'value'); switch iir_type %iir滤波器类型选择 butter,cheby1,cheby2 case 1 [nn,wn]=buttord(2*wp1/freq_sampling,2*ws1/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =butter(nn,wn,'high'); set(handles.edit18,'string',nn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes2作为画板 cla; %清空画板 plot(n/N,filtered_signal); %画输出的波形 hold on; xlabel('t/s'); ylabel('filtered_signal'); title('butterworth highpass filter'); case 2 [nn,wn]=cheb1ord(2*wp1/freq_sampling,2*ws1/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =cheby1(nn,rp,wn,'high'); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby1 highpass filter'); case 3 [nn,wn]=cheb2ord(2*wp1/freq_sampling,2*ws1/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =cheby2(nn,rp,wn,'high'); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby2 highpass filter'); end case 3 %选中iir中的bp %set(handles.edit12,'visible','off'); %set(handles.edit14,'visible','off'); iir_type=get(handles.popupmenu3,'value'); switch iir_type %iir滤波器类型选择 butter,cheby1,cheby2 case 1 [nn,wn]=buttord(2*wp/freq_sampling,2*ws/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =butter(nn,wn); set(handles.edit18,'string',nn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes2作为画板 cla; %清空画板 plot(n/N,filtered_signal); %画输出的波形 hold on; xlabel('t/s'); ylabel('filtered_signal'); title('butterworth bandpass filter'); case 2 [nn,wn]=cheb1ord(2*wp/freq_sampling,2*ws/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =cheby1(nn,rp,wn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby1 bandpass filter'); case 3 [nn,wn]=cheb2ord(2*wp/freq_sampling,2*ws/freq_sampling,rp,rs); [b,a] =cheby2(nn,rp,wn); set(handles.edit18,'string',nn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby2 bandpass filter'); end case 4 %选中iir中的bs iir_type=get(handles.popupmenu3,'value'); switch iir_type %iir滤波器类型选择 butter,cheby1,cheby2 case 1 [nn,wn]=buttord(2*wp/freq_sampling,2*ws/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =butter(nn,wn); set(handles.edit18,'string',nn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes2作为画板 cla; %清空画板 plot(n/N,filtered_signal); %画输出的波形 hold on; xlabel('t/s'); ylabel('filtered_signal'); title('butterworth bandstop filter'); case 2 [nn,wn]=cheb1ord(2*wp/freq_sampling,2*ws/freq_sampling,rp,rs); set(handles.edit18,'string',nn); [b,a] =cheby1(nn,rp,wn,'low'); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby1 bandstop filter'); case 3 [nn,wn]=cheb2ord(2*wp/freq_sampling,2*ws/freq_sampling,rp,rs); [b,a] =cheby2(nn,rp,wn,'low'); set(handles.edit18,'string',nn); filtered_signal = filter(b,a,all); axes(handles.axes2); %将axes1作为画板 cla; %清空画板 plot(n/N,filtered_signal); hold on; xlabel('t/s'); ylabel('filtered_signal'); title('cheby2 bandstop filter'); end endcase 2 filter_type=get(handles.popupmenu2,'value'); switch filter_type %滤波器类型选择lp hp bp bs case 1 %滤波器选中fir中的lp,以下为4种fir方式 wn = (2*wp1/freq_sampling+2*ws1/freq_sampling)/2; n2 = str2double(get(handles.edit17, 'String')); filtertype = 'low'; fir_type =get(handles.popupmenu4,'value'); switch fir_type case 1 %hamming窗 window =hamming(n2+1); b = fir1(n2,wn); case 2 %hamming窗 window =hanning(n2+1); b = fir1(n2,wn,window); case 3 %kaiser窗 beta = str2double(get(handles.edit15, 'String')); window = kaiser(n2+1,beta); b = fir1(n2,wn,window); case 4 %chebwin窗 r = str2double(get(handles.edit15, 'String')); window =chebwin(n2+1,r); b = fir1(n2,wn,window); end case 2 %滤波器选中fir中的hp,以下为4种fir方式 wn = (2*wp1/freq_sampling+2*ws1/freq_sampling)/2; n2 = str2double(get(handles.edit17, 'String')); filtertype = 'high'; fir_type =get(handles.popupmenu4,'value'); switch fir_type case 1 %hamming窗 window =hamming(n2+1); b = fir1(n2,wn,filtertype); case 2 %hamming窗 window =hanning(n2+1); b = fir1(n2,wn,'high',window); case 3 %kaiser窗 beta = str2double(get(handles.edit15, 'String')); window = kaiser(n2+1,beta); b = fir1(n2,wn,'high',window); case 4 %chebwin窗 r = str2double(get(handles.edit15, 'String')); window =chebwin(n2+1,r); b = fir1(n2,wn,'high',window); end case 3 %滤波器选中fir中的bp,以下为4种fir方式 wn = [(2*wp1/freq_sampling+2*ws1/freq_sampling)/2 (2*wp2/freq_sampling+2*ws2/freq_sampling)/2]; n2 = str2double(get(handles.edit17, 'String')); filtertype = 'bandpass'; fir_type =get(handles.popupmenu4,'value'); switch fir_type case 1 %hamming窗
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -