function my_filter=my_filter(order,fre,amp)
N=order/2; %filter order 2N+1       
fft_size=100*N;           desired_MSE=10^-3;
delta_p=0.05;             delta_s=0.05;     %tolerance values  
if length(amp)==4 && amp(1)==1 && amp(2)==1 && amp(3)==0 && amp(4)==0; %Design Low Pass Filter
    w_p=fre(2)*pi; w_s=fre(3)*pi; 
    for a=1:1:fft_size;
        w=(a-1)*2*pi/fft_size; %angular frequency
        if (0<=w&&w<=w_p)||(2*pi-w_p<=w&&w<=2*pi);
            Hid(a)=1;
            Ed(a)=delta_p;
        elseif w_s<=w&&w<=2*pi-w_s;
            Hid(a)=0;
            Ed(a)=delta_s;
        end
    end
    g=ifft(Hid,fft_size);
    MSE=10;
    while (MSE>desired_MSE); %Apply iterations to find MSE<desired MSE value 
        hk=g;
        c=N+2:1:fft_size;
        hk(c)=0;
        for e=2:1:N+1;
            hk(fft_size+2-e)=hk(e);
        end
        HK=fft(hk,fft_size);
        for f=1:1:fft_size;
            w=(f-1)*2*pi/fft_size; %angular frequency
            if (0<=w&&w<=w_p)||(w_s<=w&&w<=2*pi-w_s)||(2*pi-w_p<=w&&w<=2*pi);
                if HK(f)>Hid(f)+Ed(f);
                    G(f)=Hid(f)+Ed(f);
                elseif HK(f)<Hid(f)-Ed(f);
                    G(f)=Hid(f)-Ed(f);
                else 
                    G(f)=HK(f);
                end
            end
        end
        g=ifft(G,fft_size);
        new_hk=g;
        b=N+2:1:fft_size;
        new_hk(b)=0;
        for d=2:1:N+1;
            new_hk(fft_size+2-d)=new_hk(d);
        end
        array=hk(1:(N+1))-new_hk(1:(N+1));
        array=array.*array;
        total=array(1);
        for i=2:1:(N+1);
            total=total+2*array(i);
        end
        MSE=total/(2*N+1);%MSE between h_k and h_k+1
    end
elseif length(amp)==4 && amp(1)==0 && amp(2)==0 && amp(3)==1 && amp(4)==1; %Design High Pass Filter 
    w_s=fre(2)*pi;      w_p=fre(3)*pi;  
    for a=1:1:fft_size;
        w=(a-1)*2*pi/fft_size; %angular frequency
        if (0<=w&&w<=w_s)||(2*pi-w_s<=w&&w<=2*pi);
            Hid(a)=0;
            Ed(a)=delta_s;
        elseif w_p<=w&&w<=2*pi-w_p;
            Hid(a)=1;
            Ed(a)=delta_p;
        end
    end
    g=ifft(Hid,fft_size);
    MSE=10;
    while (MSE>desired_MSE); %Apply iterations to find MSE<desired MSE value 
        hk=g;
        c=N+2:1:fft_size;
        hk(c)=0;
        for e=2:1:N+1;
            hk(fft_size+2-e)=hk(e);
        end
        HK=fft(hk,fft_size);
        for f=1:1:fft_size;
            w=(f-1)*2*pi/fft_size; %angular frequency
            if (0<=w&&w<=w_s)||(w_p<=w&&w<=2*pi-w_p)||(2*pi-w_s<=w&&w<=2*pi);
                if HK(f)>Hid(f)+Ed(f);
                    G(f)=Hid(f)+Ed(f);
                elseif HK(f)<Hid(f)-Ed(f);
                    G(f)=Hid(f)-Ed(f);
                else 
                    G(f)=HK(f);
                end
            end
        end
        g=ifft(G,fft_size);
        new_hk=g;
        b=N+2:1:fft_size;
        new_hk(b)=0;
        for d=2:1:N+1;
            new_hk(fft_size+2-d)=new_hk(d);
        end
        array=hk(1:(N+1))-new_hk(1:(N+1));
        array=array.*array;
        total=array(1);
        for i=2:1:(N+1);
            total=total+2*array(i);
        end
        MSE=total/(2*N+1);%MSE between h_k and h_k+1
    end
elseif length(amp)==6 && amp(1)==0 && amp(2)==0 && amp(3)==1 && amp(4)==1 && amp(5)==0 && amp(6)==0; %Design Band Pass Filter 
    w_1=fre(2)*pi; w_2=fre(3)*pi; w_3=fre(4)*pi; w_4=fre(5)*pi; 
    for a=1:1:fft_size;
        w=(a-1)*2*pi/fft_size; %angular frequency
        if (0<=w&&w<=w_1)||(w_4<=w&&w<=2*pi-w_4)||(2*pi-w_1<=w&&w<=2*pi);
            Hid(a)=0;
            Ed(a)=delta_s;
        elseif (w_2<=w&&w<=w_3)||(2*pi-w_3<=w&&w<=2*pi-w_2);
            Hid(a)=1;
            Ed(a)=delta_p;
        end
    end
    g=ifft(Hid,fft_size);
    MSE=10;
    while (MSE>desired_MSE); %Apply iterations to find MSE<desired MSE value 
        hk=g;
        c=N+2:1:fft_size;
        hk(c)=0;
        for e=2:1:N+1;
            hk(fft_size+2-e)=hk(e);
        end
        HK=fft(hk,fft_size);
        for f=1:1:fft_size;
            w=(f-1)*2*pi/fft_size; %angular frequency
            if (0<=w&&w<=w_1)||(w_4<=w&&w<=2*pi-w_4)||(2*pi-w_1<=w&&w<=2*pi)||(w_2<=w&&w<=w_3)||(2*pi-w_3<=w&&w<=2*pi-w_2);
                if HK(f)>Hid(f)+Ed(f);
                    G(f)=Hid(f)+Ed(f);
                elseif HK(f)<Hid(f)-Ed(f);
                    G(f)=Hid(f)-Ed(f);
                else 
                    G(f)=HK(f);
                end
            end
        end
        g=ifft(G,fft_size);
        new_hk=g;
        b=N+2:1:fft_size;
        new_hk(b)=0;
        for d=2:1:N+1;
            new_hk(fft_size+2-d)=new_hk(d);
        end
        array=hk(1:(N+1))-new_hk(1:(N+1));
        array=array.*array;
        total=array(1);
        for i=2:1:(N+1);
            total=total+2*array(i);
        end
        MSE=total/(2*N+1);%MSE between h_k and h_k+1
    end
elseif length(amp)==6 && amp(1)==1 && amp(2)==1 && amp(3)==0 && amp(4)==0 && amp(5)==1 && amp(6)==1; %Design Band Stop Filter
    w_1=fre(2)*pi; w_2=fre(3)*pi; w_3=fre(4)*pi; w_4=fre(5)*pi; 
    for a=1:1:fft_size;
        w=(a-1)*2*pi/fft_size; %angular frequency
        if (0<=w&&w<=w_1)||(w_4<=w&&w<=2*pi-w_4)||(2*pi-w_1<=w&&w<=2*pi);
            Hid(a)=1;
            Ed(a)=delta_p;
        elseif (w_2<=w&&w<=w_3)||(2*pi-w_3<=w&&w<=2*pi-w_2);
            Hid(a)=0;
            Ed(a)=delta_s;
        end
    end
    g=ifft(Hid,fft_size);
    MSE=10;
    while (MSE>desired_MSE); %Apply iterations to find MSE<desired MSE value 
        hk=g;
        c=N+2:1:fft_size;
        hk(c)=0;
        for e=2:1:N+1;
            hk(fft_size+2-e)=hk(e);
        end
        HK=fft(hk,fft_size);
        for f=1:1:fft_size;
            w=(f-1)*2*pi/fft_size; %angular frequency
            if (0<=w&&w<=w_1)||(w_4<=w&&w<=2*pi-w_4)||(2*pi-w_1<=w&&w<=2*pi)||(w_2<=w&&w<=w_3)||(2*pi-w_3<=w&&w<=2*pi-w_2);
                if HK(f)>Hid(f)+Ed(f);
                    G(f)=Hid(f)+Ed(f);
                elseif HK(f)<Hid(f)-Ed(f);
                    G(f)=Hid(f)-Ed(f);
                else 
                    G(f)=HK(f);
                end
            end
        end
        g=ifft(G,fft_size);
        new_hk=g;
        b=N+2:1:fft_size;
        new_hk(b)=0;
        for d=2:1:N+1;
            new_hk(fft_size+2-d)=new_hk(d);
        end
        array=hk(1:(N+1))-new_hk(1:(N+1));
        array=array.*array;
        total=array(1);
        for i=2:1:(N+1);
            total=total+2*array(i);
        end
        MSE=total/(2*N+1);%MSE between h_k and h_k+1
    end
else disp('Please read the instruction and enter valid values for filter');
end
x= firpm(order,fre,amp);
xx(1:(N+1))=x((N+1):(2*N+1)); %take negative indexed elements and place at the end of time array
y=(N+2):1:fft_size;
xx(y)=0;
for z=2:1:N+1;
    xx(fft_size+2-z)=xx(z);
end
new_hk=real(new_hk);%found from iterations
xx=real(xx);%found from firpm method
H1=fft(new_hk,fft_size);%FFT found from iterations
H2=fft(xx,fft_size);%FFT found from firpm method
array2=new_hk(1:(N+1))-xx(1:(N+1));
array2=array2.*array2;
total2=array2(1);
for ii=2:1:(N+1);
    total2=total2+2*array2(ii);
end
Resulting_MSE=total2/(2*N+1);%MSE between my design and firpm
kk=1:1:fft_size;
ww=(kk-1)*2*pi/fft_size;
plot(ww,abs(H1),ww,abs(H2));%plot magnutude of frequency responses on the same graph
title('Frequency Responses versus Angular Frequency Graph');
figure;
plot([0:1:N],new_hk(1:N+1),'o',[0:1:N],xx(1:N+1),'x');%plot magnutude of filter coefficients on the same graph
title('Filter coefficients graph for two filter'); %only positive indexed coeeficients 
new_hk(1:N+1)%Designed Filter coefficients (only zero and positive indexed coefficients)
xx(1:N+1)%‘firpm’ Filter coefficients (only zero and positive indexed coefficients) 
Resulting_MSE %Resulting MSE between iterative design and ‘firpm’ design