# length 15 (-7,...,7) linear phase FIR filter param n := 8; param N := 300; param pi := 4*atan(1); param eps := 1.0e-5; set NU := {0..1 by 1/N}; param Sp2 {nu in NU} := (if 0.1< nu && nu<=0.8 then 1 else 0); param Ss2 {nu in NU} := (if nu<=0.3 || nu> 0.9 then 1 else 0); var rho >= 0; var h_real {0..n-1}; var h_imag {1..n-1}; var u_real {0..n-1}; var u_imag {1..n-1}; var v_real {0..n-1}; var v_imag {1..n-1}; var H {nu in NU} = h_real[0] + 2* sum {k in 1..n-1} (h_real[k]*cos(-2*pi*k*nu) - h_imag[k]*sin(-2*pi*k*nu)); var H2 {nu in NU} = h_real[0] + 2* sum {k in 1..n-1} (h_real[k]*cos(-4*pi*k*nu) - h_imag[k]*sin(-4*pi*k*nu)); var H4 {nu in NU} = h_real[0] + 2* sum {k in 1..n-1} (h_real[k]*cos(-8*pi*k*nu) - h_imag[k]*sin(-8*pi*k*nu)); var U {nu in NU} = u_real[0] + 2* sum {k in 1..n-1} (u_real[k]*cos(-2*pi*k*nu) - u_imag[k]*sin(-2*pi*k*nu)); var V2 {nu in NU} = v_real[0] + 2* sum {k in 1..n-1} (v_real[k]*cos(-4*pi*k*nu) - v_imag[k]*sin(-4*pi*k*nu)); minimize power_bnd: rho; subject to passband: sqrt(sum {nu in NU} (H[nu] + U[nu]*H2[nu] + U[nu]*V2[nu]*H4[nu] - 1)^2 * Sp2[nu] ) <= sqrt(0.7*N)*rho; subject to stopband: sqrt(sum {nu in NU} H[nu]^2 * Ss2[nu]) <= sqrt(0.4*N)*sqrt(eps); let h_real[0] := 2; let u_real[0] := 2; let v_real[0] := 2; unfix {k in 0..n-1} h_real[k]; unfix {k in 1..n-1} h_imag[k]; fix {k in 0..n-1} u_real[k]; fix {k in 1..n-1} u_imag[k]; fix {k in 0..n-1} v_real[k]; fix {k in 1..n-1} v_imag[k]; solve; printf {nu in NU}: "%7.4f %10.3e \n", nu, 20*log10(abs(H[nu])) > 5h.out; printf {nu in NU}: "%7.4f %10.3e \n", nu, 20*log10(abs(U[nu])) > 5u.out; printf {nu in NU}: "%7.4f %10.3e \n", nu, 20*log10(abs(V2[nu])) > 5v.out; printf {nu in NU}: "%7.4f %10.3e \n", nu, 20*log10(abs(U[nu]*H2[nu])) > 5uh.out; printf {nu in NU}: "%7.4f %10.3e \n", nu, 20*log10(abs(U[nu]*V2[nu]*H4[nu])) > 5uvh.out;