[N,fk,mk,w]=firpmord([100,150],[1,0],[0.01,0.01],500);
fg = [0,100/250,150/250,1]; mk=[1,1,0,0];
g = firhalfband(22,100/250);
plot(500*w1/(2*pi),20*log10(abs(G))), grid
xlabel('Frequency (Hz)'),ylabel('Gain(dB)'), title('Model filter')
f0=[0,100/1000,375/1000,625/1000,875/1000,1]; m0=[1,1,0,0,0,0];
ff = firpm(18,f0,m0,[1,0.5,0.5]);
plot(2000*w1/(2*pi),20*log10(abs(F))), grid
xlabel('Frequency (Hz)'),ylabel('Gain(dB)'),title('Masking filter')
N = 5; alpha = -0.5; Fs = 0.4; % Input parameters for emqf_LP.m
[A1b,A1i,A0b,A0i,beta,Ap,As,Fp,F3db]=emqf_igi(N,alpha,Fs/2); % Filter design
EMQF design
===============================
N = 5
alpha = -0.500000000
F_s = 0.400000000
F_p = 0.273837466
F_3dB = 0.333333333
A_p = 0.0031204598
A_s = 31.437217336
alpha1 = -0.267949192
beta =
0.3445
0.7871
A=(conv(A1b,A0i)+conv(A0b,A1i))/2; % Numerator of G(z)
B=conv(A1i,A0i); % Denominator of G(z)
plot(f,20*log10(abs(G))),ylabel('Gain, dB'),grid
title('EMQF filter, used as model and masking filter ')
freq = [0,0.4,0.625,1]; m1=[1,1,0,0];
f1 = firpm(20,freq,m1,w);
[F1,fr] = freqz(f1,1,1024,2);
plot(fr,20*log10(abs(F0)),fr,20*log10(abs(F1)),'r'),grid
xlabel('Normalized frequency, \omega/\pi'),ylabel('Gain(dB)')
legend('Location','best')
legend('Filter F_0(z)','Filter F_1(z)')
f0=[0,f0,0]; % Equalization of the masking filters' lengths
h = conv(gm,f0) + conv(gmc,f1); % Impulse response of the overall filter
[H,Fr]=freqz(h,1,1024,2000);
plot(Fr,20*log10(abs(H)));
xlabel('Frequency [Hz]'),ylabel('Gain, dB')
plot([0,650,650,1000],[0,0,-40,-40],'r')
title('Wide-band filter')
g(1)=axes('Position',[0.20 0.55 0.40 0.07]);
plot(Fr(1:650),20*log10(abs(H(1:650)))),axis([0,600,-0.1,0.1])
disp('END OF EXAMPLE 10.3')
delta_p = (10^(ap/20)-1)/(10^(ap/20)+1); % Passband ripple
delta_s = 10^(-as/20); % Stopband ripple
freq = [0,0.6,0.85,1]; m0 = [1,1,0,0]; w = [delta_p/delta_s,1]; % Seting design parameters for masking filter f0
f0 = firpm(18,freq,m0,w); % Designing the masking filter f0
freq = [0,0.4,0.625,1]; m1=[1,1,0,0]; % Seting design parameters for masking filter f1
f1 = firpm(20,freq,m1,w); % Designing the masking filter f1
plot(2000*w1/(2*pi),20*log10(abs(H)));
xlabel('Frequency [Hz]'),ylabel('Gain, dB')
plot([0,650,650,1000],[0,0,-40,-40],'r')
g(1)=axes('Position',[0.20 0.55 0.40 0.07]);
plot(Fr(1:325),20*log10(abs(H(1:325)))),axis([0,600,-0.1,0.1])
disp('END OF EXAMPLE 10.4')
disp(' END OF CHAPTER X')
function [A1b,A1i,A0b,A0i,beta,Ap,As,Fp,F3db]=emqf_igi(N,alpha,Fs)
% emqf_0 EMQF (Elliptic Minimal Q Factors) digital filter design.
% [A1b,A1i,A0b,A0i,beta,Ap,As,Fp,F3db]=emqf_LP(N,alpha,Fs) designs an N'th order
% lowpass digital EMQF filter with normalized stopband edge
% frequency Fs. The sampling frequency is assumed to be F0=1.
% The constant alfa is chosen by designer. For given Fp and Fs
% (Fp and Fs the boundary frequencies of the specificatin),
% the permited values alfa are in the range:
% -(1-(tan(pi*Fa)^2)/(1+(tan(pi*Fa)^2)<alfa<-(1-(tan(pi*Fp)^2)/(1+(tan(pi*Fp)^2).
% The value of alfa approximates
% (1-(tan(pi*Fa)(tan(pi*Fp))/(1+(tan(pi*Fa)(tan(pi*Fp))
% and is adjusted to be represented as a simple combination
% In the case of a half-band filter alfa=0
% * Allpass branches in vectors A1b,A1i,A0b,A0i
% * Normalized frequencies (F0=1) in vector f, length 500.
% * Square pole magnitudes of the complex poles in vector beta.
% * passband ripple Ap (dB)
% * minimal stopband attenuation As (dB)
% * passband boundary frequency of EMQF filter Fp
% * 3 dB attenuation frequency F3db
disp('===============================')
disp([sprintf(' N = %6u', N)])
disp([sprintf(' alpha = %15.9f', alpha)])
disp([sprintf(' F_s = %15.9f',2*Fs)])
F3db = (1/pi)*atan(sqrt((1+alpha)/(1-alpha)));
disp('------- error -----------------')
disp('N should be odd number')
disp('choose new N = 3, 5, 7, 9, 11, ...')
disp('-------------------------------')
H=0; w=0; zzd=0; ppd=0; Ap=0; As=0; Fp=0; F3db=0;omega=0;co=0;
disp([sprintf(' F_3dB = %15.9f', F3db)])
disp('------- error -----------------')
disp('Fs should be larger than F3dB')
disp(['choose new Fs > ' num2str(F3db) ' or'])
disp(['choose new alpha < ' num2str(-cos(2*pi*Fs))])
disp('-------------------------------')
H=0; w=0; zzd=0; ppd=0; Ap=0; As=0;omega=0;co=0;
Fp = (1/pi)*atan(((1+alpha)/(1-alpha))*(1/tan(pi*Fs)));
disp([sprintf(' F_p = %15.9f', 2*Fp)])
disp([sprintf(' F_3dB = %15.9f', 2*F3db)])
xi = tan(pi*Fs)/tan(pi*Fp);
t = .5*(1-(1-1/xi^2)^(1/4))/(1+(1-1/xi^2)^(1/4));
q = t+2*t^5+15*t^9+150*t^13;
t = .5*(1-1/sqrt(xi))/(1+1/sqrt(xi));
qp = t+2*t^5+15*t^9+150*t^13;
disp([sprintf(' A_p = %15.9g', Ap)])
disp([sprintf(' A_s = %15.9f', As)])
x = ellipj( ((2*ind-1)/N + 1)*ellipke(1/a^2), 1/a^2);
kor = 2*sqrt(a)*tan(pi*Fp)/(1+a*tan(pi*Fp)^2);
b(ind) = ((a+x^2) - kor*sqrt((1-x^2)*(a^2-x^2)) )/...
((a+x^2) + kor*sqrt((1-x^2)*(a^2-x^2)) );
a1 = -(1-tan(pi*F3db))/(1+tan(pi*F3db));
disp([sprintf(' alpha1 = %15.9f', a1)])
p1 = conv(p1,[1 alpha*(1+beta(ind)) beta(ind)]);
p2 = conv(p2,[1 alpha*(1+beta(ind)) beta(ind)]);