ch6.m
来自「基于MATLAB与VC混合编程的数字均衡器的设计」· M 代码 · 共 913 行 · 第 1/3 页
M
913 行
[b a]=cheby2(order,20,2*fband(i:i+1)/handles.Fs);
elseif get(handles.ellip,'Value')==1
[b a]=ellip(order,0.5,20,2*fband(i:i+1)/handles.Fs);
else
errordlg('No filter type chosen or filter type error!');
end
eval(sprintf('k=get(handles.band%d,''Value'');',i));
y=(9^k-1)/8*qfilter(b,a,handles.y);
% for j=1:nn
% if y(j)>=-1&y(j)<=1
% else
% y(j)=0;
% end
% end
handles.yy=handles.yy+y;
set(handles.progress,'String',sprintf('%d0%% complete',i+1));
pause(0.01);
end
guidata(hObject,handles);
set(handles.filt,'Enable','on');
set(handles.filterplay,'Enable','on');
set(handles.progress,'String','100% complete');
set(handles.filt,'Enable','on');
set(handles.save,'Enable','on');
function order_Callback(hObject, eventdata, handles)
% hObject handle to order (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of order as text
% str2double(get(hObject,'String')) returns contents of order as a double
% --- Executes during object creation, after setting all properties.
function order_CreateFcn(hObject, eventdata, handles)
% hObject handle to order (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in reset.
function reset_Callback(hObject, eventdata, handles)
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
for i=1:8
eval(sprintf('set(handles.band%d,''Value'',1)',i));
end
set(handles.order,'String',5);
set(handles.butterworth,'Value',1);
function filterorder_Callback(hObject, eventdata, handles)
% hObject handle to filterorder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of filterorder as text
% str2double(get(hObject,'String')) returns contents of filterorder as a double
% --- Executes during object creation, after setting all properties.
function filterorder_CreateFcn(hObject, eventdata, handles)
% hObject handle to filterorder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function freq1_Callback(hObject, eventdata, handles)
% hObject handle to freq1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of freq1 as text
% str2double(get(hObject,'String')) returns contents of freq1 as a double
% --- Executes during object creation, after setting all properties.
function freq1_CreateFcn(hObject, eventdata, handles)
% hObject handle to freq1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function freq2_Callback(hObject, eventdata, handles)
% hObject handle to freq2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of freq2 as text
% str2double(get(hObject,'String')) returns contents of freq2 as a double
% --- Executes during object creation, after setting all properties.
function freq2_CreateFcn(hObject, eventdata, handles)
% hObject handle to freq2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in lowpass.
function lowpass_Callback(hObject, eventdata, handles)
% hObject handle to lowpass (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of lowpass
set(handles.freq2,'Enable','off');
% --- Executes on button press in highpass.
function highpass_Callback(hObject, eventdata, handles)
% hObject handle to highpass (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of highpass
set(handles.freq2,'Enable','off');
% --- Executes on button press in bandpass.
function bandpass_Callback(hObject, eventdata, handles)
% hObject handle to bandpass (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of bandpass
set(handles.freq2,'Enable','on');
% --- Executes on button press in bandstop.
function bandstop_Callback(hObject, eventdata, handles)
% hObject handle to bandstop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of bandstop
set(handles.freq2,'Enable','on');
% --- Executes on selection change in filtertype.
function filtertype_Callback(hObject, eventdata, handles)
% hObject handle to filtertype (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns filtertype contents as cell array
% contents{get(hObject,'Value')} returns selected item from filtertype
% --- Executes during object creation, after setting all properties.
function filtertype_CreateFcn(hObject, eventdata, handles)
% hObject handle to filtertype (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (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 genfilter.
function genfilter_Callback(hObject, eventdata, handles)
% hObject handle to genfilter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
order=str2double(get(handles.filterorder,'String'));
W1=str2double(get(handles.freq1,'String'));
W2=str2double(get(handles.freq2,'String'));
if W1>1
W1=2*W1/handles.Fs;
end
if W2>1
W2=2*W2/handles.Fs;
end
if get(handles.lowpass,'Value')==1
switch get(handles.filtertype,'Value')
case 1
[b a]=butter(order,W1,'low');
case 2
[b a]=cheby1(order,0.5,W1,'low');
case 3
[b a]=cheby2(order,20,W1,'low');
case 4
[b a]=ellip(order,0.5,20,W1,'low');
otherwise
errordlg('Filter type chosen error!Butterworth?cheby?...');
return;
end
elseif get(handles.highpass,'Value')==1
switch get(handles.filtertype,'Value')
case 1
[b a]=butter(order,W1,'high');
case 2
[b a]=cheby1(order,0.5,W1,'high');
case 3
[b a]=cheby2(order,20,W1,'high');
case 4
[b a]=ellip(order,0.5,20,W1,'high');
otherwise
errordlg('Filter type chosen error!Butterworth?cheby?...');
return;
end
elseif get(handles.bandpass,'Value')==1
switch get(handles.filtertype,'Value')
case 1
[b a]=butter(order,[W1 W2]);
case 2
[b a]=cheby1(order,0.5,[W1 W2]);
case 3
[b a]=cheby2(order,20,[W1 W2]);
case 4
[b a]=ellip(order,0.5,20,[W1 W2]);
otherwise
errordlg('Filter type chosen error!Butterworth?cheby?...');
return;
end
elseif get(handles.bandstop,'Value')==1
switch get(handles.filtertype,'Value')
case 1
[b a]=butter(order,[W1 W2],'bandstop');
case 2
[b a]=cheby1(order,0.5,[W1 W2],'bandstop');
case 3
[b a]=cheby2(order,20,[W1 W2],'bandstop');
case 4
[b a]=ellip(order,0.5,20,[W1 W2],'bandstop');
otherwise
errordlg('Filter type chosen error!Butterworth?cheby?...');
return;
end
else
errordlg('Filter type chosen error!lowpass,highpass,bandpass or bandstop?');
return;
end
[H f]=freqz(b,a,512,2);
plot(handles.axes4,f,abs(H));
handles.b=b;
handles.a=a;
guidata(hObject,handles);
set(handles.filt2,'Enable','on');
% --- Executes on button press in filt2.
function filt2_Callback(hObject, eventdata, handles)
% hObject handle to filt2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.filt2,'Enable','off');
tic
if get(handles.matlab,'Value')==1
handles.yy=filter(handles.b,handles.a,handles.y);
elseif get(handles.vc,'Value')==1
handles.yy=qfilter(handles.b,handles.a,handles.y);
end
set(handles.ellipstime,'String',sprintf('%fs',toc));
guidata(hObject,handles);
set(handles.filt2,'Enable','on');
set(handles.filterplay,'Enable','on');
set(handles.save,'Enable','on');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?