Maximize stopband attenuation of a lowpass FIR filter (magnitude design)
n = 20;
wpass = 0.12*pi;
wstop = 0.24*pi;
delta = 1;
m = 15*n;
w = linspace(0,pi,m)';
A = [ones(m,1) 2*cos(kron(w,[1:n-1]))];
ind = find((0 <= w) & (w <= wpass));
Lp = 10^(-delta/20)*ones(length(ind),1);
Up = 10^(+delta/20)*ones(length(ind),1);
Ap = A(ind,:);
ind = find((wstop <= w) & (w <= pi));
As = A(ind,:);
cvx_begin
variable r(n,1)
minimize( max( abs( As*r ) ) )
subject to
Ap*r >= (Lp.^2);
Ap*r <= (Up.^2);
A*r >= 0;
cvx_end
disp(['Problem is ' cvx_status])
if ~strfind(cvx_status,'Solved')
return
end
h = spectral_fact(r);
Ustop = 10*log10(cvx_optval);
fprintf(1,'The max attenuation in the stopband is %3.2f dB.\n\n',Ustop);
H = [exp(-j*kron(w,[0:n-1]))]*h;
figure(1)
plot([0:n-1],h','o',[0:n-1],h','b:')
xlabel('t'), ylabel('h(t)')
figure(2)
subplot(2,1,1)
plot(w,20*log10(abs(H)), ...
[0 wpass],[delta delta],'r--', ...
[0 wpass],[-delta -delta],'r--', ...
[wstop pi],[Ustop Ustop],'r--')
xlabel('w')
ylabel('mag H(w) in dB')
axis([0 pi -50 5])
subplot(2,1,2)
plot(w,angle(H))
axis([0,pi,-pi,pi])
xlabel('w'), ylabel('phase H(w)')
Calling sedumi: 828 variables, 21 equality constraints
For improved efficiency, sedumi is solving the dual problem.
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
eqs m = 21, order n = 829, dim = 829, blocks = 229
nnz(A) = 12228 + 0, nnz(ADA) = 441, nnz(L) = 231
it : b*y gap delta rate t/tP* t/tD* feas cg cg prec
0 : 1.25E+02 0.000
1 : -8.10E-01 4.27E+01 0.000 0.3408 0.9000 0.9000 4.90 1 1 7.7E+01
2 : -6.93E-01 1.09E+01 0.000 0.2556 0.9000 0.9000 2.08 1 1 1.2E+01
3 : -3.57E-01 4.67E+00 0.000 0.4282 0.9000 0.9000 2.20 1 1 3.0E+00
4 : -7.18E-02 2.30E+00 0.000 0.4935 0.9000 0.9000 3.56 1 1 6.3E-01
5 : -2.40E-02 1.01E+00 0.000 0.4372 0.9000 0.9000 1.84 1 1 2.2E-01
6 : -8.79E-03 3.98E-01 0.000 0.3955 0.9000 0.9000 1.31 1 1 8.8E-02
7 : -4.47E-03 2.04E-01 0.000 0.5118 0.9000 0.9000 1.11 1 1 5.1E-02
8 : -1.95E-03 8.02E-02 0.000 0.3931 0.9000 0.9000 1.07 1 1 2.7E-02
9 : -9.23E-04 3.51E-02 0.000 0.4375 0.9000 0.9000 1.01 1 1 1.8E-02
10 : -2.58E-04 3.98E-03 0.000 0.1135 0.9145 0.9000 0.98 1 1 7.1E-03
11 : -1.65E-04 1.21E-03 0.000 0.3036 0.9331 0.9000 1.00 1 1 4.3E-03
12 : -1.65E-04 7.62E-04 0.410 0.6307 0.9000 0.0000 0.99 1 1 3.9E-03
13 : -1.44E-04 5.85E-04 0.162 0.7670 0.9000 0.9000 0.98 1 1 3.0E-03
14 : -1.27E-04 2.80E-04 0.000 0.4782 0.9439 0.9000 0.95 1 1 2.1E-03
15 : -1.07E-04 5.69E-05 0.000 0.2035 0.9194 0.9000 0.99 1 1 6.2E-04
16 : -1.05E-04 1.20E-05 0.000 0.2109 0.9118 0.9000 0.99 1 1 1.4E-04
17 : -1.05E-04 2.46E-06 0.000 0.2050 0.9080 0.9000 1.00 1 1 3.1E-05
18 : -1.05E-04 2.86E-07 0.000 0.1162 0.9070 0.9000 1.00 1 1 3.7E-06
19 : -1.05E-04 1.38E-09 0.000 0.0048 0.9990 0.9601 1.00 2 2 1.3E-08
iter seconds digits c*x b*y
19 0.1 6.1 -1.0483614480e-04 -1.0483646538e-04
|Ax-b| = 6.6e-10, [Ay-c]_+ = 3.2E-10, |x|= 7.5e-01, |y|= 3.1e-01
Detailed timing (sec)
Pre IPM Post
1.000E-02 1.200E-01 0.000E+00
Max-norms: ||b||=1, ||c|| = 1.258925e+00,
Cholesky |add|=0, |skip| = 0, ||L.L|| = 2.26418.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.000104836
Problem is Solved
The max attenuation in the stopband is -39.79 dB.