Code covered by the BSD License  

Highlights from
Filter Design Toolbox

image thumbnail

Filter Design Toolbox

by

Behnam Shariati

 

This program can evaluate all filter types characteristics with some adequate inputs.

Filter(varargin)
% This GUI is designed by M. Behnam Shariati
%                         Email: behnam.sh@ieee.org
%                                shariati.behnam@gmail.com
%                         Cellphone: 0098-935-486-8772
function varargout = Filter(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Filter_OpeningFcn, ...
                   'gui_OutputFcn',  @Filter_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

function Filter_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;


guidata(hObject, handles);

function varargout = Filter_OutputFcn(hObject, eventdata, handles) 

varargout{1} = handles.output;



function designmethod_Callback(hObject, eventdata, handles)

function designmethod_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function typeoffilter_Callback(hObject, eventdata, handles)

function typeoffilter_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function apass_Callback(hObject, eventdata, handles)
APASS=get(hObject,'String');
if (isempty(APASS))     
    set(hObject,'String','Default')
end
guidata(hObject, handles);

function apass_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function astop_Callback(hObject, eventdata, handles)
ASTOP=get(hObject,'String');
if (isempty(ASTOP))     
    set(hObject,'String','Default')
end
guidata(hObject, handles);

function astop_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function wpass_Callback(hObject, eventdata, handles)
WPASS=get(hObject,'String');
if (isempty(WPASS))     
    set(hObject,'String','Default')
end
guidata(hObject, handles); 

function wpass_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function wstop_Callback(hObject, eventdata, handles)
WSTOP=get(hObject,'String');
if (isempty(WSTOP))     
    set(hObject,'String','Default')
end
guidata(hObject, handles);

function wstop_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function wsample_Callback(hObject, eventdata, handles)

function wsample_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
      
function unitresponse_Callback(hObject, eventdata, handles)
WPASS = get(handles.wpass,'String');
WSTOP = get(handles.wstop,'String');
APASS = get(handles.apass,'String');
ASTOP = get(handles.astop,'String');
WS = get(handles.wsample,'string');
WPASS = str2num(WPASS);
WSTOP = str2num(WSTOP);
APASS = str2num(APASS);
ASTOP = str2num(ASTOP);
WS = str2num(WS);
popdesign = get(handles.designmethod,'Value');
poptype = get(handles.typeoffilter,'Value');
switch popdesign
    case 1
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                step(handles.axes1,G);
%                 butterworhLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = butter(ORDER,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 butterworthHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = butter(n,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 butterworthBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = butter(n,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                step(handles.axes1,sys)
%                 butterworthBS
        end
    case 2
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                 set(handles.order,'string',ORDER);
                [Z,P,K]=cheb1ap(ORDER,APASS);
                sys=zpk(Z,P,K);
                G = tf(sys);
                step(handles.axes1,G);
%                 chebyshev1LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby1(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 chebyshev1HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 chebyshev1BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                step(handles.axes1,sys)
%                 chebyshev1BS
        end
    case 3
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=cheb2ap(ORDER,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                step(handles.axes1,G);
%                 chebyshev2LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby2(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 chebyshev2HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 chebyshev2BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                step(handles.axes1,sys)
%                 chebyshev2BS
        end
    case 4
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = ellipord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=ellipap(ORDER,APASS,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                step(handles.axes1,G);
%                 EllipticLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = ellip(ORDER,APASS,ASTOP,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 EllipticHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                step(handles.axes1,sys);
%                 EllipticBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
                WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);

                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                step(handles.axes1,sys)
%                 EllipticBS
        end
end

function impulseresponse_Callback(hObject, eventdata, handles)
WPASS = get(handles.wpass,'String');
WSTOP = get(handles.wstop,'String');
APASS = get(handles.apass,'String');
ASTOP = get(handles.astop,'String');
WS = get(handles.wsample,'string');

WPASS = str2num(WPASS);
WSTOP = str2num(WSTOP);
APASS = str2num(APASS);
ASTOP = str2num(ASTOP);
WS = str2num(WS);
popdesign = get(handles.designmethod,'Value');
poptype = get(handles.typeoffilter,'Value');
switch popdesign
    case 1
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                impulse(handles.axes1,G);
%                 butterworhLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = butter(ORDER,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 butterworthHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = butter(n,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 butterworthBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = butter(n,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys)
%                 butterworthBS
        end
    case 2
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                 set(handles.order,'string',ORDER);
                [Z,P,K]=cheb1ap(ORDER,APASS);
                sys=zpk(Z,P,K);
                G = tf(sys);
                impulse(handles.axes1,G);
%                 chebyshev1LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby1(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 chebyshev1HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 chebyshev1BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys)
%                 chebyshev1BS
        end
    case 3
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=cheb2ap(ORDER,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                impulse(handles.axes1,G);
%                 chebyshev2LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby2(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 chebyshev2HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 chebyshev2BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys)
%                 chebyshev2BS
        end
    case 4
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = ellipord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=ellipap(ORDER,APASS,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                impulse(handles.axes1,G);
%                 EllipticLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = ellip(ORDER,APASS,ASTOP,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 EllipticHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                impulse(handles.axes1,sys);
%                 EllipticBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                impulse(handles.axes1,sys)
%                 EllipticBS
        end
end

function magnitude_Callback(hObject, eventdata, handles)
WPASS = get(handles.wpass,'String');
WSTOP = get(handles.wstop,'String');
APASS = get(handles.apass,'String');
ASTOP = get(handles.astop,'String');
WS = get(handles.wsample,'string');

WPASS = str2num(WPASS);
WSTOP = str2num(WSTOP);
APASS = str2num(APASS);
ASTOP = str2num(ASTOP);
WS = str2num(WS);
popdesign = get(handles.designmethod,'Value');
poptype = get(handles.typeoffilter,'Value');
switch popdesign
    case 1
        
        switch poptype
            
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                bode(handles.axes1,G);
%                 butterworhLP
            case 2
                
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = butter(ORDER,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 butterworthHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = butter(n,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 butterworthBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = butter(n,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
%                 butterworthBS
        end
    case 2
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                 set(handles.order,'string',ORDER);
                [Z,P,K]=cheb1ap(ORDER,APASS);
                sys=zpk(Z,P,K);
                G = tf(sys);
                bode(handles.axes1,G);
%                 chebyshev1LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby1(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 chebyshev1HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 chebyshev1BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
%                 chebyshev1BS
        end
    case 3
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=cheb2ap(ORDER,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                bode(handles.axes1,G);
%                 chebyshev2LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby2(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 chebyshev2HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 chebyshev2BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
%                 chebyshev2BS
        end
    case 4
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = ellipord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=ellipap(ORDER,APASS,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                bode(handles.axes1,G);
%                 EllipticLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = ellip(ORDER,APASS,ASTOP,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 EllipticHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
%                 EllipticBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
%                 EllipticBS
        end
end

function polezero_Callback(hObject, eventdata, handles)
WPASS = get(handles.wpass,'String');
WSTOP = get(handles.wstop,'String');
APASS = get(handles.apass,'String');
ASTOP = get(handles.astop,'String');
WS = get(handles.wsample,'string');

WPASS = str2num(WPASS);
WSTOP = str2num(WSTOP);
APASS = str2num(APASS);
ASTOP = str2num(ASTOP);
WS = str2num(WS);
popdesign = get(handles.designmethod,'Value');
poptype = get(handles.typeoffilter,'Value');
switch popdesign
    case 1
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                pzmap(handles.axes1,G);
%                 butterworhLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = butter(ORDER,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 butterworthHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = butter(n,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 butterworthBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = butter(n,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys)
%                 butterworthBS
        end
    case 2
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                 set(handles.order,'string',ORDER);
                [Z,P,K]=cheb1ap(ORDER,APASS);
                sys=zpk(Z,P,K);
                G = tf(sys);
                pzmap(handles.axes1,G);
%                 chebyshev1LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby1(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 chebyshev1HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
               pzmap(handles.axes1,sys);
%                 chebyshev1BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys)
%                 chebyshev1BS
        end
    case 3
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=cheb2ap(ORDER,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                pzmap(handles.axes1,G);
%                 chebyshev2LP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby2(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 chebyshev2HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 chebyshev2BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys)
%                 chebyshev2BS
        end
    case 4
        
        switch poptype
            case 1
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = ellipord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER);
                [Z,P,K]=ellipap(ORDER,APASS,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                pzmap(handles.axes1,G);
%                 EllipticLP
            case 2
                WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = ellip(ORDER,APASS,ASTOP,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 EllipticHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys);
%                 EllipticBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                pzmap(handles.axes1,sys)
%                 EllipticBS
        end
end

function phasedelay_Callback(hObject, eventdata, handles)
WPASS = get(handles.wpass,'String');
WSTOP = get(handles.wstop,'String');
APASS = get(handles.apass,'String');
ASTOP = get(handles.astop,'String');
WS = get(handles.wsample,'string');

WPASS = str2num(WPASS);
WSTOP = str2num(WSTOP);
APASS = str2num(APASS);
ASTOP = str2num(ASTOP);
WS = str2num(WS);
popdesign = get(handles.designmethod,'Value');
poptype = get(handles.typeoffilter,'Value');
switch popdesign
    case 1
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 butterworhLP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = butter(ORDER,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 butterworthHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = butter(n,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 butterworthBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = butter(n,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 butterworthBS
        end
    case 2
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=cheb1ap(ORDER,APASS);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev1LP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby1(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev1HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev1BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev1BS
        end
    case 3
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=cheb2ap(ORDER,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev2LP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby2(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev2HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev2BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 chebyshev2BS
        end
    case 4
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = ellipord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=ellipap(ORDER,APASS,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 EllipticLP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = ellip(ORDER,APASS,ASTOP,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 EllipticHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 EllipticBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                pd=-(phase1./w);
                semilogx(handles.axes1,w,pd)
                datacursormode on
%                 EllipticBS
        end
end

function groupdelay_Callback(hObject, eventdata, handles)
WPASS = get(handles.wpass,'String');
WSTOP = get(handles.wstop,'String');
APASS = get(handles.apass,'String');
ASTOP = get(handles.astop,'String');
WS = get(handles.wsample,'string');

WPASS = str2num(WPASS);
WSTOP = str2num(WSTOP);
APASS = str2num(APASS);
ASTOP = str2num(ASTOP);
WS = str2num(WS);
popdesign = get(handles.designmethod,'Value');
poptype = get(handles.typeoffilter,'Value');
switch popdesign
    case 1
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
%                 butterworhLP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = butter(ORDER,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
%                 butterworthHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = butter(n,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                bode(handles.axes1,sys);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
%                 butterworthBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = buttord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = butter(n,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                bode(handles.axes1,sys)
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
%                 butterworthBS
        end
    case 2
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=cheb1ap(ORDER,APASS);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev1LP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb1ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby1(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev1HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
                
%                 chebyshev1BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb1ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby1(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev1BS
        end
    case 3
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=cheb2ap(ORDER,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev2LP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = cheb2ord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = cheby2(ORDER,APASS,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev2HP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev2BP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = cheb2ord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = cheby2(n,APASS,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 chebyshev2BS
        end
    case 4
        WPASS = WPASS/WS;
        WSTOP = WSTOP/WS;
        [ORDER,Wn] = ellipord(WPASS,WSTOP,APASS,ASTOP);
        set(handles.order,'string',ORDER);
        switch poptype
            case 1
                [Z,P,K]=ellipap(ORDER,APASS,ASTOP);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [Z,P,K]=buttap(ORDER);
                sys=zpk(Z,P,K);
                G = tf(sys);
                [mag,phase,w] = bode(G);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 EllipticLP
            case 2
%                 WPASS = WPASS/WS;
                WSTOP = WSTOP/WS;
                [ORDER,Wn] = buttord(WPASS,WSTOP,APASS,ASTOP);
                set(handles.order,'string',ORDER)
                [b,a] = ellip(ORDER,APASS,ASTOP,Wn*WS*2*pi,'high','s');
                sys=tf(b,a);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 EllipticHP
            case 3
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'string',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'s');
                sys=tf(b,a);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 EllipticBP
            case 4 
                WS1 = get(handles.ws1,'String');
WP1 = get(handles.wp1,'String');
WP2 = get(handles.wp2,'String');
WS2 = get(handles.ws2,'String');
WS1 = str2num(WS1);
WP1 = str2num(WP1);
WP2 = str2num(WP2);
WS2 = str2num(WS2);
                wpass=[WP1,WP2]/WS;
                wstop=[WS1,WS2]/WS;
                [n,Wn] = ellipord(wpass,wstop,APASS,ASTOP);
                set(handles.order,'String',n);
                [b,a] = ellip(n,APASS,ASTOP,Wn*2*WS*pi,'stop','s');
                sys=tf(b,a);
                [mag,phase,w] = bode(sys);
                w=rot90(w);
                k=size(phase);
                for n=1:1:k(3)
                phase1(n)=phase(1,1,n);
                end
                for n=1:1:k(3)-1;
                    w1(n)=w(n);
                end
                gd=-(diff(phase1)./diff(w));
                semilogx(handles.axes1,w1,gd)
                datacursormode on
%                 EllipticBS
        end
end



function ws1_Callback(hObject, eventdata, handles)

function ws1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function wp2_Callback(hObject, eventdata, handles)

function wp2_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function wp1_Callback(hObject, eventdata, handles)

function wp1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function ws2_Callback(hObject, eventdata, handles)

function ws2_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% This GUI is designed by M. Behnam Shariati
%                         Email: behnam.sh@ieee.org
%                                shariati.behnam@gmail.com
%                         Cellphone: 0098-935-486-8772

Contact us