	

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % .m script of web demo "Analog Butterworth filter"
    % Written for GNU Octave
    %
    % INSTITUTE OF TELECOMMUNICATIONS
    % University of Stuttgart
    % www.inue-uni-stuttgart.de
    % author:Sagar Hukkire
    % date: 14.01.2016
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % This example script just prints the values of the given parameters.
    % Make sure that the function prototype matches the prototype defined
    % in the XML config file. (Parameter names are arbitrary but should be the same
    % for better readability)

    function [] = Analog_Butterworth(order,omega_cutoff,centerFrequency,bandwidthBandpass, checkbox1,display_option,filename)



    % define formats
    landscape = "-S930,350";
    portrait  = "-S640,480";

    % select format
    output_format = portrait;

    % Create an invisible figure.
    fh = figure(1);
    set(fh, "visible", "off");

    % define style
    set(0, "defaultlinelinewidth", 2);
    set(0, "defaultaxesfontsize", 8);
    set(0, "defaultaxesfontname", "Helvetica");
    set(0, "defaulttextfontsize", 8);
    set(0, "defaulttextfontname", "Helvetica");


    % Plot into the figure
    %welcome = ["Hi there! Change the values on the right\nand press [Create Plot]!\n"];
    %text(0.1, 0.8, welcome, "fontsize", 8, "color", "red");
    % str = ["value of text1: " num2str(text1) "\n"];
    % str = [str "value of enum1: " enum1 "\n"];
    % str = [str "value of checkbox1: " num2str(checkbox1) "\n"];
    % str = [str "value of range1: " num2str(range1) "\n"];
    % str = [str "value of select1: " select1 "\n"];
    % text(0.1, 0.5, str);


    %Analog_Lowpass_Code_Starts

    if(!checkbox1)
        if(display_option=='Lp')
            b =1;                                                                           %Some filter with lot's of static gain

            omega=linspace(0,2*omega_cutoff);

            k=1:order;
            analogPoles=omega_cutoff*exp(j*pi*((2*k)+order-1)/(2*order));                   %Calculation of poles for Butterworth lowpass
            denCoefficients=abs(poly(analogPoles));                                         %Denomator Coefficient
            ze = j*omega;                                                                   %Pre-compute exponent

            tfLowpass = polyval(b, ze)./polyval(denCoefficients, ze);                        %Evaluate transfer function and take the amplitude

            absLowpass=abs(tfLowpass)/max(abs(tfLowpass));

            


            plot(omega,absLowpass,'b',omega_cutoff,max(absLowpass)*(1/sqrt(2)),'o')
            title(['Low pass Butterworth Filter']);
            xlabel('\Omega');
            ylabel('|H(\Omega)|');
            grid on;
            grid minor;
        end
        %Analog_Lowpass_Code_Ends

        if(display_option=='Hp')

            %%Analog Highpass Butterworth Filter Code Starts%%

            b =1;                                                                           %Some filter with lot's of static gain

            omega=linspace(0,2*omega_cutoff);

            k=1:order;
            analogPoles=omega_cutoff*exp(j*pi*((2*k)+order-1)/(2*order));                   %Calculation of poles for Butterworth lowpass
            denCoefficients=abs(poly(analogPoles));                                         %Denomator Coefficient
            ze = j*omega;                                                                   %Pre-compute exponent





            numhighpassCoefficient =[b zeros(1,order)];                                       %Numerator highpass coeffients

            highpassPoles=((omega_cutoff*omega_cutoff)./analogPoles);                       %highpass poles

            denhighpassCoefficient=abs(poly(highpassPoles));                                  %absolute values of high pass denominator coefficients

            tfHighpass=polyval(numhighpassCoefficient,ze)./polyval(denhighpassCoefficient,ze);%Evaluate transfer function and take the amplitude

            absHighpass= abs(tfHighpass);

            

            plot(omega,absHighpass,'b',omega_cutoff,max(absHighpass)*(1/sqrt(2)),'o');

            title(['Highpass Butterworth Filter']);

            xlabel('\Omega');

            ylabel('|H(\Omega)|');

            grid on;

            grid minor;

        end


        if(display_option=='Bp')

            b =1;                                                                           %Some filter with lot's of static gain

            omega=linspace(0,2*(centerFrequency+(bandwidthBandpass/2)));

            k=1:order;
            analogPoles=omega_cutoff*exp(j*pi*((2*k)+order-1)/(2*order));                   %Calculation of poles for Butterworth lowpass
            denCoefficients=abs(poly(analogPoles));                                         %Denomator Coefficient
            ze = j*omega;                                                                   %Pre-compute exponent

            format short e;

            for i=1:order

                denBandpass(:,i)=roots([1 -(bandwidthBandpass)*analogPoles(i)/omega_cutoff centerFrequency.^2]);

                denBandpassCoefficient=abs(poly(denBandpass(:)));                           %bandpass denominator coefficients

            end

            numBandpass=[zeros(1,order) ((bandwidthBandpass).^order)*b zeros(1,order)];      %bandpass numerator coefficients

            tfBandpass=polyval(numBandpass,ze)./polyval(denBandpassCoefficient,ze);          %Evaluate transfer function and take the amplitude




            plot(omega,abs(tfBandpass/1),'b',centerFrequency+(bandwidthBandpass/2),max(abs(tfBandpass/1))*(1/sqrt(2)),'bo',centerFrequency-(bandwidthBandpass/2),max(abs(tfBandpass/1))*(1/sqrt(2)),'bo')

            title(['Bandpass Butterworth Filter']);

            xlabel('\Omega');

            ylabel('|H(\Omega)|');

            grid on;

            grid minor;

        end

    end

    %%Analog Bandpass Butterworth Filter Code ends%%


    if(checkbox1)

        if(display_option=='Lp')


            b =1;                                                                           %Some filter with lot's of static gain

            omega=logspace(0,ceil(log10(omega_cutoff))+1,500);


            k=1:order;
            analogPoles=omega_cutoff*exp(j*pi*((2*k)+order-1)/(2*order));                   %Calculation of poles for Butterworth lowpass
            denCoefficients=abs(poly(analogPoles));                                         %Denomator Coefficient
            ze = j*omega;                                                                   %Pre-compute exponent

            tfLowpass = polyval(b, ze)./polyval(denCoefficients, ze);                        %Evaluate transfer function and take the amplitude

            absLowpass=abs(tfLowpass)/max(abs(tfLowpass))

            loglog(omega,absLowpass,'b',omega_cutoff,max(absLowpass)*(1/sqrt(2)),'o');
            title(['Low pass Butterworth Filter']);
            xlabel('\Omega');
            ylabel('|H(\Omega)|');
            grid on;
            grid minor;
        end


        if(display_option=='Hp')

            %%Analog Highpass Butterworth Filter Code Starts%%

            b =1;                                                                           %Some filter with lot's of static gain

            omega=logspace(0,ceil(log10(omega_cutoff))+1,500);

            k=1:order;
            analogPoles=omega_cutoff*exp(j*pi*((2*k)+order-1)/(2*order));                   %Calculation of poles for Butterworth lowpass
            denCoefficients=abs(poly(analogPoles));                                         %Denomator Coefficient
            ze = j*omega;                                                                   %Pre-compute exponent


            numhighpassCoefficient =[b zeros(1,order)];                                       %Numerator highpass coeffients

            highpassPoles=((omega_cutoff*omega_cutoff)./analogPoles);                       %highpass poles

            denhighpassCoefficient=abs(poly(highpassPoles));                                  %absolute values of high pass denominator coefficients

            tfHighpass=polyval(numhighpassCoefficient,ze)./polyval(denhighpassCoefficient,ze);%Evaluate transfer function and take the amplitude

            absHighpass= abs(tfHighpass);

            loglog(omega,absHighpass,'b',omega_cutoff,max(absHighpass)*(1/sqrt(2)),'o');
            title(['Highpass Butterworth Filter']);
            xlabel('\Omega');
            ylabel('|H(\Omega)|');
            grid on;
            grid minor;
        end

        if(display_option=='Bp')


            b =1;                                                                           %Some filter with lot's of static gain

            omega=logspace(0,ceil(log10(centerFrequency+(bandwidthBandpass/2)))+1,500);

            k=1:order;
            analogPoles=omega_cutoff*exp(j*pi*((2*k)+order-1)/(2*order));                   %Calculation of poles for Butterworth lowpass
            denCoefficients=abs(poly(analogPoles));                                         %Denomator Coefficient
            ze = j*omega;                                                                   %Pre-compute exponent

            format short e;

            for i=1:order

                denBandpass(:,i)=roots([1 -(bandwidthBandpass)*analogPoles(i)/omega_cutoff centerFrequency.^2]);

                denBandpassCoefficient=abs(poly(denBandpass(:)));                           %bandpass denominator coefficients

            end

            numBandpass=[zeros(1,order) ((bandwidthBandpass).^order)*b zeros(1,order)];      %bandpass numerator coefficients

            tfBandpass=polyval(numBandpass,ze)./polyval(denBandpassCoefficient,ze);          %Evaluate transfer function and take the amplitude

            loglog(omega,abs(tfBandpass),'b',centerFrequency+(bandwidthBandpass/2),max(abs(tfBandpass/1))*(1/sqrt(2)),'bo',centerFrequency-(bandwidthBandpass/2),max(abs(tfBandpass/1))*(1/sqrt(2)),'bo');

            title(['Bandpass Butterworth Filter']);

            xlabel('\Omega');

            ylabel('|H(\Omega)|');
            grid on;
            grid minor;
        end

    end



    print(filename, "-dpng", output_format);						% Create an image file. This png image is displayed on the webpage. Its size
    % must be 640x480.


    end














