clear all
close all
clc

reply = lower(strtrim(input('Do you want to design a FB with only lower M? Y/N   ',"s")));

if reply == "y"
M=input("Enter the number of channels. M = ");
validateattributes(M, {'numeric'}, {'scalar','integer','positive','even'});

N=input("Enter the prototype filter order. N = ");
validateattributes(N, {'numeric'}, {'scalar','integer','positive'});

delta1=input("Enter the reconstruction error of the distortion transfer function. delta1 = ");
validateattributes(delta1, {'numeric'}, {'scalar','positive'});

delta2=input("Enter the reconstruction error of the aliasing transfer function. delta2 = ");
validateattributes(delta2, {'numeric'}, {'scalar','positive'});

attenuation=input("Enter the stopband attenuation of the prototype filter. as = ");
validateattributes(attenuation, {'numeric'}, {'scalar','positive'});

delta3=10^(-attenuation/20);

ratio=input("Enter the ratio (=passband ripple/stopband ripple) for the initial equiripple prototype filter, which is needed for the same as.  ratio = ");
validateattributes(ratio, {'numeric'}, {'scalar','positive'});

if mod(N,2)==0
X=Function_evenM_evenN(M,N,delta1,delta2,delta3,ratio);
save('Filter_lower_M.mat', 'X');
else
X=Function_evenM_oddN(M,N,delta1,delta2,delta3,ratio);
save('Filter_lower_M.mat', 'X');
end

elseif reply == "n"
fprintf('\n');
display("The relation of a prototype filter order (N) and a number of channels (M) should be N=Ns*M+M-1.")

M=input("Enter the number of channels. M = ");
validateattributes(M, {'numeric'}, {'scalar','integer','positive','even'});

N=input("Enter the prototype filter order. N (odd) = ");
validateattributes(N, {'numeric'}, {'scalar','integer','positive','odd'});

delta=input("Enter the allowed error. delta = ");
validateattributes(delta, {'numeric'}, {'scalar','positive'});

delta=round(0.8*delta,4);
delta1=delta;
delta2=delta;
delta3=delta;

ratio=input("Enter the ratio (=passband ripple/stopband ripple) for the initial equiripple prototype filter, which is needed for the same as. ratio = ");
validateattributes(ratio, {'numeric'}, {'scalar','positive'});

X=Function_evenM_oddN(M,N,delta1,delta2,delta3,ratio);
save('Filter_lower_M.mat', 'X');

else
error("Invalid input. Please enter Y or N.")

end

