Upload
rein16
View
216
Download
0
Embed Size (px)
Citation preview
8/6/2019 Filter Implementation
1/22
8/6/2019 Filter Implementation
2/22
function Filter_Implementation_OpeningFcn(hObject, eventdata, handles,varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to Filter_Implementation (see VARARGIN)
% Choose default command line output for Filter_Implementationhandles.output = hObject;
% Update handles structureguidata(hObject, handles);
% UIWAIT makes Filter_Implementation wait for user response (see UIRESUME)% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.function varargout = Filter_Implementation_OutputFcn(hObject, eventdata,
handles)% varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structurevarargout{1} = handles.output;
% --- Executes on button press in pb1.function pb1_Callback(hObject, eventdata, handles)% hObject handle to pb1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (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 edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as adouble
% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (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.
8/6/2019 Filter Implementation
3/22
if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
function edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (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 edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as adouble
% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
function edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (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 edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as adouble
% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
8/6/2019 Filter Implementation
4/22
function edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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 edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as adouble
% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
function edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (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 edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as adouble
% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
% --- Executes on selection change in pop1.function pop1_Callback(hObject, eventdata, handles)% hObject handle to pop1 (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 pop1 contents as cell array% contents{get(hObject,'Value')} returns selected item from pop1
8/6/2019 Filter Implementation
5/22
% --- Executes during object creation, after setting all properties.function pop1_CreateFcn(hObject, eventdata, handles)% hObject handle to pop1 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
% --- Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (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 pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in pop2.function pop2_Callback(hObject, eventdata, handles)% hObject handle to pop2 (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 pop2 contents as cell array% contents{get(hObject,'Value')} returns selected item from pop2
% --- Executes during object creation, after setting all properties.function pop2_CreateFcn(hObject, eventdata, handles)% hObject handle to pop2 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
% --- Executes on button press in pb2.function pb2_Callback(hObject, eventdata, handles)% hObject handle to pb2 (see GCBO)
8/6/2019 Filter Implementation
6/22
% 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 pb3.function pb3_Callback(hObject, eventdata, handles)% hObject handle to pb3 (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 pb4.function pb4_Callback(hObject, eventdata, handles)% hObject handle to pb4 (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 pb5.function pb5_Callback(hObject, eventdata, handles)
% hObject handle to pb5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------function Untitled_1_Callback(hObject, eventdata, handles)% hObject handle to Untitled_1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
function edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (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 edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as adouble
% --- Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
8/6/2019 Filter Implementation
7/22
function edit7_Callback(hObject, eventdata, handles)% hObject handle to edit7 (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 edit7 as text% str2double(get(hObject,'String')) returns contents of edit7 as adouble
% --- Executes during object creation, after setting all properties.function edit7_CreateFcn(hObject, eventdata, handles)% hObject handle to edit7 (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
end
function edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (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 edit8 as text% str2double(get(hObject,'String')) returns contents of edit8 as adouble
% --- Executes during object creation, after setting all properties.function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_Callback(hObject, eventdata, handles)% hObject handle to edit9 (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 edit9 as text
8/6/2019 Filter Implementation
8/22
% str2double(get(hObject,'String')) returns contents of edit9 as adouble
% --- Executes during object creation, after setting all properties.function edit9_CreateFcn(hObject, eventdata, handles)% hObject handle to edit9 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
function edit10_Callback(hObject, eventdata, handles)
% hObject handle to edit10 (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 edit10 as text% str2double(get(hObject,'String')) returns contents of edit10 as adouble
% --- Executes during object creation, after setting all properties.function edit10_CreateFcn(hObject, eventdata, handles)% hObject handle to edit10 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
function edit11_Callback(hObject, eventdata, handles)% hObject handle to edit11 (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 edit11 as text% str2double(get(hObject,'String')) returns contents of edit11 as adouble
% --- Executes during object creation, after setting all properties.function edit11_CreateFcn(hObject, eventdata, handles)% hObject handle to edit11 (see GCBO)
8/6/2019 Filter Implementation
9/22
% 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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
function edit12_Callback(hObject, eventdata, handles)% hObject handle to edit12 (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 edit12 as text% str2double(get(hObject,'String')) returns contents of edit12 as adouble
% --- Executes during object creation, after setting all properties.function edit12_CreateFcn(hObject, eventdata, handles)% hObject handle to edit12 (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 && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');end
% --------------------------------------------------------------------function Untitled_4_Callback(hObject, eventdata, handles)% hObject handle to Untitled_4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.function uipanel2_CreateFcn(hObject, eventdata, handles)% hObject handle to uipanel2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
IMP.M
h=findobj(gcf,'tag','edit1');o=str2num(get(h,'string'));h=findobj(gcf,'tag','edit2');fc1=str2num(get(h,'string'));
8/6/2019 Filter Implementation
10/22
h=findobj(gcf,'tag','edit3');fc2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit4');fs=str2num(get(h,'string'));h=findobj(gcf,'tag','edit5');r=str2num(get(h,'string'));h=findobj(gcf,'tag','pop1');D=get(h,'value');h=findobj(gcf,'tag','pop2');E=get(h,'value');h=findobj(gcf,'tag','edit6');pf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit7');pf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit8');pf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit9');sf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit10');sf2=str2num(get(h,'string'));
h=findobj(gcf,'tag','edit11');sf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit12');sf4=str2num(get(h,'string'));wn=fc1/(fs/2);apf1=pf1/(fs/2)*pi;apf2=pf2/(fs/2)*pi;apf3=pf3/(fs/2)*pi;asf1=sf1/(fs/2)*pi;asf2=sf2/(fs/2)*pi;asf3=sf3/(fs/2)*pi;asf4=sf4/(fs/2)*pi;[x,y]=pol2cart(apf1,1);a1=x+y*i;[x,y]=pol2cart(apf2,1);a2=x+y*i;[x,y]=pol2cart(apf3,1);a3=x+y*i;[x,y]=pol2cart(-apf1,1);a4=x+y*i;[x,y]=pol2cart(-apf2,1);a5=x+y*i;[x,y]=pol2cart(-apf3,1);a6=x+y*i;[x,y]=pol2cart(asf1,1);b1=x+y*i;[x,y]=pol2cart(asf2,1);b2=x+y*i;[x,y]=pol2cart(asf3,1);b3=x+y*i;[x,y]=pol2cart(asf4,1);b4=x+y*i;[x,y]=pol2cart(-asf1,1);b5=x+y*i;[x,y]=pol2cart(-asf2,1);b6=x+y*i;[x,y]=pol2cart(-asf3,1);b7=x+y*i;[x,y]=pol2cart(-asf4,1);b8=x+y*i;wn=fc1/(fs/2);
if (wn>0)&(wn
8/6/2019 Filter Implementation
11/22
8/6/2019 Filter Implementation
12/22
w=[wn w2];[b,a]=butter(o,w,'band');filt1=filter(b,a,rec);figure ('Name','Impulse Response','NumberTitle', 'off');impz(b,a)
elseif D==4 & E==5wn=fc1/(fs/2);[b,a]=butter(o,w,'stop');filt1=filter(b,a,rec);figure ('Name','Impulse Response','NumberTitle', 'off');impz(b,a)
elsea=poly([a1 a2 a3 a4 a5 a6]);b=poly([b1 b2 b3 b4 b5 b6 b7 b8]);filt1=filter(b,a,rec);figure ('Name','Impulse Response','NumberTitle', 'off');impz(b,a)
endelse
disp('error!');
end
MAGNI.M
h=findobj(gcf,'tag','edit1');o=str2num(get(h,'string'));h=findobj(gcf,'tag','edit2');fc1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit3');fc2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit4');fs=str2num(get(h,'string'));h=findobj(gcf,'tag','edit5');r=str2num(get(h,'string'));h=findobj(gcf,'tag','pop1');D=get(h,'value');h=findobj(gcf,'tag','pop2');E=get(h,'value');h=findobj(gcf,'tag','edit6');pf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit7');pf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit8');pf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit9');sf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit10');sf2=str2num(get(h,'string'));
h=findobj(gcf,'tag','edit11');sf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit12');sf4=str2num(get(h,'string'));wn=fc1/(fs/2);apf1=pf1/(fs/2)*pi;apf2=pf2/(fs/2)*pi;apf3=pf3/(fs/2)*pi;asf1=sf1/(fs/2)*pi;asf2=sf2/(fs/2)*pi;
8/6/2019 Filter Implementation
13/22
asf3=sf3/(fs/2)*pi;asf4=sf4/(fs/2)*pi;[x,y]=pol2cart(apf1,1);a1=x+y*i;[x,y]=pol2cart(apf2,1);a2=x+y*i;[x,y]=pol2cart(apf3,1);a3=x+y*i;[x,y]=pol2cart(-apf1,1);a4=x+y*i;[x,y]=pol2cart(-apf2,1);a5=x+y*i;[x,y]=pol2cart(-apf3,1);a6=x+y*i;[x,y]=pol2cart(asf1,1);b1=x+y*i;[x,y]=pol2cart(asf2,1);b2=x+y*i;[x,y]=pol2cart(asf3,1);b3=x+y*i;[x,y]=pol2cart(asf4,1);b4=x+y*i;[x,y]=pol2cart(-asf1,1);b5=x+y*i;[x,y]=pol2cart(-asf2,1);b6=x+y*i;[x,y]=pol2cart(-asf3,1);b7=x+y*i;[x,y]=pol2cart(-asf4,1);b8=x+y*i;wn=fc1/(fs/2);if (wn>0)&(wn
8/6/2019 Filter Implementation
14/22
w2=fc2/(fs/2);w=[wn w2];[b,a]=cheby1(o,r,w,'bandpass');filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
elseif D==3 & E==5wn=fc1/(fs/2);[b,a]=cheby1(o,r,wn,'stop');filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
elseif D==4 & E==2wn=fc1/(fs/2);[b,a]=butter(o,wn);filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
elseif D==4 & E==3wn=fc1/(fs/2);
[b,a]=butter(o,wn,'high');filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
elseif D==4 & E==4wn=fc1/(fs/2);w2=fc2/(fs/2);w=[wn w2];[b,a]=butter(o,w,'band');filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
elseif D==4 & E==5wn=fc1/(fs/2);[b,a]=butter(o,w,'stop');filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
elsea=poly([a1 a2 a3 a4 a5 a6]);b=poly([b1 b2 b3 b4 b5 b6 b7 b8]);filt1=filter(b,a,rec);figure ('Name','Magnitude Response','NumberTitle', 'off');freqz(b,a)
endelse
disp('error!');
end
PLAYFILTER.M
h=findobj(gcf,'tag','edit1');o=str2num(get(h,'string'));h=findobj(gcf,'tag','edit2');fc1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit3');fc2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit4');
8/6/2019 Filter Implementation
15/22
fs=str2num(get(h,'string'));h=findobj(gcf,'tag','edit5');r=str2num(get(h,'string'));h=findobj(gcf,'tag','pop1');D=get(h,'value');h=findobj(gcf,'tag','pop2');E=get(h,'value');h=findobj(gcf,'tag','edit6');pf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit7');pf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit8');pf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit9');sf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit10');sf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit11');sf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit12');
sf4=str2num(get(h,'string'));wn=fc1/(fs/2);apf1=pf1/(fs/2)*pi;apf2=pf2/(fs/2)*pi;apf3=pf3/(fs/2)*pi;asf1=sf1/(fs/2)*pi;asf2=sf2/(fs/2)*pi;asf3=sf3/(fs/2)*pi;asf4=sf4/(fs/2)*pi;[x,y]=pol2cart(apf1,1);a1=x+y*i;[x,y]=pol2cart(apf2,1);a2=x+y*i;[x,y]=pol2cart(apf3,1);a3=x+y*i;[x,y]=pol2cart(-apf1,1);a4=x+y*i;[x,y]=pol2cart(-apf2,1);a5=x+y*i;[x,y]=pol2cart(-apf3,1);a6=x+y*i;[x,y]=pol2cart(asf1,1);b1=x+y*i;[x,y]=pol2cart(asf2,1);b2=x+y*i;[x,y]=pol2cart(asf3,1);b3=x+y*i;[x,y]=pol2cart(asf4,1);b4=x+y*i;[x,y]=pol2cart(-asf1,1);b5=x+y*i;[x,y]=pol2cart(-asf2,1);b6=x+y*i;[x,y]=pol2cart(-asf3,1);b7=x+y*i;[x,y]=pol2cart(-asf4,1);b8=x+y*i;wn=fc1/(fs/2);if (wn>0)&(wn
8/6/2019 Filter Implementation
16/22
b=fir1(o,wn,'band');filt1=filter(b,1,rec);wavplay(filt1)
elseif D==2 & E==5wn=fc1/(fs/2);b=fir1(o,wn,'stop');filt1=filter(b,1,rec);wavplay(filt1)
elseif D==3 & E==2wn=fc1/(fs/2);[b,a]=cheby1(o,r,wn);filt1=filter(b,a,rec);wavplay(filt1)
elseif D==3 & E==3wn=fc1/(fs/2);[b,a]=cheby1(o,r,wn,'high');filt1=filter(b,a,rec);wavplay(filt1)
elseif D==3 & E==4wn=fc1/(fs/2);
w2=fc2/(fs/2);w=[wn w2];[b,a]=cheby1(o,r,w,'bandpass');filt1=filter(b,a,rec);wavplay(filt1)
elseif D==3 & E==5wn=fc1/(fs/2);[b,a]=cheby1(o,r,wn,'stop');filt1=filter(b,a,rec);wavplay(filt1)
elseif D==4 & E==2wn=fc1/(fs/2);[b,a]=butter(o,wn);filt1=filter(b,a,rec);wavplay(filt1)
elseif D==4 & E==3wn=fc1/(fs/2);[b,a]=butter(o,wn,'high');filt1=filter(b,a,rec);wavplay(filt1)
elseif D==4 & E==4wn=fc1/(fs/2);w2=fc2/(fs/2);w=[wn w2];[b,a]=butter(o,w,'band');filt1=filter(b,a,rec);wavplay(filt1)
elseif D==4 & E==5wn=fc1/(fs/2);[b,a]=butter(o,w,'stop');filt1=filter(b,a,rec);wavplay(filt1)
elsea=poly([a1 a2 a3 a4 a5 a6]);b=poly([b1 b2 b3 b4 b5 b6 b7 b8]);filt1=filter(b,a,rec);wavplay(filt1)
8/6/2019 Filter Implementation
17/22
endelse
disp('error!');end
PLAYRECORD.M
wavplay(rec)
PO_ZE.M
h=findobj(gcf,'tag','edit1');o=str2num(get(h,'string'));h=findobj(gcf,'tag','edit2');fc1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit3');fc2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit4');fs=str2num(get(h,'string'));h=findobj(gcf,'tag','edit5');r=str2num(get(h,'string'));h=findobj(gcf,'tag','pop1');
D=get(h,'value');h=findobj(gcf,'tag','pop2');E=get(h,'value');h=findobj(gcf,'tag','edit6');pf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit7');pf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit8');pf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit9');sf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit10');sf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit11');sf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit12');sf4=str2num(get(h,'string'));wn=fc1/(fs/2);apf1=pf1/(fs/2)*pi;apf2=pf2/(fs/2)*pi;apf3=pf3/(fs/2)*pi;asf1=sf1/(fs/2)*pi;asf2=sf2/(fs/2)*pi;asf3=sf3/(fs/2)*pi;asf4=sf4/(fs/2)*pi;[x,y]=pol2cart(apf1,1);a1=x+y*i;[x,y]=pol2cart(apf2,1);a2=x+y*i;
[x,y]=pol2cart(apf3,1);a3=x+y*i;[x,y]=pol2cart(-apf1,1);a4=x+y*i;[x,y]=pol2cart(-apf2,1);a5=x+y*i;[x,y]=pol2cart(-apf3,1);a6=x+y*i;[x,y]=pol2cart(asf1,1);b1=x+y*i;[x,y]=pol2cart(asf2,1);b2=x+y*i;[x,y]=pol2cart(asf3,1);b3=x+y*i;[x,y]=pol2cart(asf4,1);b4=x+y*i;[x,y]=pol2cart(-asf1,1);b5=x+y*i;[x,y]=pol2cart(-asf2,1);b6=x+y*i;
8/6/2019 Filter Implementation
18/22
[x,y]=pol2cart(-asf3,1);b7=x+y*i;[x,y]=pol2cart(-asf4,1);b8=x+y*i;wn=fc1/(fs/2);if (wn>0)&(wn
8/6/2019 Filter Implementation
19/22
[b,a]=butter(o,wn);filt1=filter(b,a,rec);figure ('Name','Poles and Zeros','NumberTitle', 'off');zplane(b,a)
elseif D==4 & E==3wn=fc1/(fs/2);[b,a]=butter(o,wn,'high');filt1=filter(b,a,rec);figure ('Name','Poles and Zeros','NumberTitle', 'off');zplane(b,a)
elseif D==4 & E==4wn=fc1/(fs/2);w2=fc2/(fs/2);w=[wn w2];[b,a]=butter(o,w,'band');filt1=filter(b,a,rec);figure ('Name','Poles and Zeros','NumberTitle', 'off');zplane(b,a)
elseif D==4 & E==5wn=fc1/(fs/2);
[b,a]=butter(o,w,'stop');filt1=filter(b,a,rec);figure ('Name','Poles and Zeros','NumberTitle', 'off');zplane(b,a)
elsea=poly([a1 a2 a3 a4 a5 a6]);b=poly([b1 b2 b3 b4 b5 b6 b7 b8]);filt1=filter(b,a,rec);figure ('Name','Poles and Zeros','NumberTitle', 'off');zplane(b,a)
endelse
disp('error!');end
REC_FIL.M
h=findobj(gcf,'tag','edit1');o=str2num(get(h,'string'));h=findobj(gcf,'tag','edit2');fc1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit3');fc2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit4');fs=str2num(get(h,'string'));h=findobj(gcf,'tag','edit5');r=str2num(get(h,'string'));h=findobj(gcf,'tag','pop1');
D=get(h,'value');h=findobj(gcf,'tag','pop2');E=get(h,'value');h=findobj(gcf,'tag','edit6');pf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit7');pf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit8');pf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit9');
8/6/2019 Filter Implementation
20/22
sf1=str2num(get(h,'string'));h=findobj(gcf,'tag','edit10');sf2=str2num(get(h,'string'));h=findobj(gcf,'tag','edit11');sf3=str2num(get(h,'string'));h=findobj(gcf,'tag','edit12');sf4=str2num(get(h,'string'));wn=fc1/(fs/2);apf1=pf1/(fs/2)*pi;apf2=pf2/(fs/2)*pi;apf3=pf3/(fs/2)*pi;asf1=sf1/(fs/2)*pi;asf2=sf2/(fs/2)*pi;asf3=sf3/(fs/2)*pi;asf4=sf4/(fs/2)*pi;[x,y]=pol2cart(apf1,1);a1=x+y*i;[x,y]=pol2cart(apf2,1);a2=x+y*i;[x,y]=pol2cart(apf3,1);a3=x+y*i;[x,y]=pol2cart(-apf1,1);a4=x+y*i;[x,y]=pol2cart(-apf2,1);a5=x+y*i;
[x,y]=pol2cart(-apf3,1);a6=x+y*i;[x,y]=pol2cart(asf1,1);b1=x+y*i;[x,y]=pol2cart(asf2,1);b2=x+y*i;[x,y]=pol2cart(asf3,1);b3=x+y*i;[x,y]=pol2cart(asf4,1);b4=x+y*i;[x,y]=pol2cart(-asf1,1);b5=x+y*i;[x,y]=pol2cart(-asf2,1);b6=x+y*i;[x,y]=pol2cart(-asf3,1);b7=x+y*i;[x,y]=pol2cart(-asf4,1);b8=x+y*i;if (wn>0)&(wn
8/6/2019 Filter Implementation
21/22
hold on;plot(filt1,'y');hold off;
elseif D==2 & E==5wn=fc1/(fs/2);b=fir1(o,wn,'stop');filt1=filter(b,1,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==3 & E==2wn=fc1/(fs/2);[b,a]=cheby1(o,r,wn);filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);
hold on;plot(filt1,'y');hold off;
elseif D==3 & E==3wn=fc1/(fs/2);[b,a]=cheby1(o,r,wn,'high');filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==3 & E==4wn=fc1/(fs/2);w2=fc2/(fs/2);w=[wn w2];[b,a]=cheby1(o,r,w,'bandpass');filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==3 & E==5wn=fc1/(fs/2);
[b,a]=cheby1(o,r,wn,'stop');filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==4 & E==2wn=fc1/(fs/2);
8/6/2019 Filter Implementation
22/22
[b,a]=butter(o,wn);filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==4 & E==3wn=fc1/(fs/2);[b,a]=butter(o,wn,'high');filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==4 & E==4wn=fc1/(fs/2);
w2=fc2/(fs/2);w=[wn w2];[b,a]=butter(o,w,'band');filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
elseif D==4 & E==5wn=fc1/(fs/2);[b,a]=butter(o,w,'stop');filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);hold on;plot(filt1,'y');hold off;
else D==5a=poly([a1 a2 a3 a4 a5 a6]);b=poly([b1 b2 b3 b4 b5 b6 b7 b8]);filt1=filter(b,a,rec);figure ('Name','Recorded (blue) and Filtered (yellow)','NumberTitle',
'off');plot(rec);
hold on;plot(filt1,'y');hold off;
endelse
disp('error!');end
RECORD.M
rec=wavrecord(5*11025,11025);