Equalizer design example

% "Filter design" lecture notes (EE364) by S. Boyd
% (figures are generated)
%
% Designs a frequency-domain and time-domain FIR equalizer for
% a single-input single-output (SISO) channel.
%
% Frequency-domain equalization uses a Chebychev criteria and
% is specified in terms of frequency response functions.
% It is a convex problem (which can be formulated as an SOCP):
%
%   minimize   max |G(w)H(w) - G_des(w)|     for w in [0,pi]
%
% where H is the frequency response function and our variable
% is the filter impulse response h. Function G is the unequalized
% frequency response and G_des is the desired freq response.
%
% Time-domain equalization immediately designs the impulse
% response function by specifying the problem in time (it's an LP):
%
%   minimize   max_{t neq D} |g_tilde(t)|
%       s.t.   g_tilde(D) = 1
%
% where g_tilde is the impulse response of equalized system,
% and D is the delay of the system.
%
% Written for CVX by Almir Mutapcic 02/02/06

%********************************************************************
% problem specs
%********************************************************************
% sample channel with impulse response g
g =.5*[ 0.6526;  0.2157; -0.2639;  1.8024; -0.6430; ...
        0.1096; -0.7190;  0.4206; -0.0193;  0.6603;];

% problem parameters
n  = 30;              % filter order
D  = 10;              % overall delay

%********************************************************************
% frequency domain equalization
%********************************************************************
% number of freq samples (rule-of-thumb)
m  = 15*(length(g) + n);

w = linspace(0,pi,m)';
G = exp( -j*kron(w,[0:length(g)-1]) )*g;
A = exp( -j*kron(w,[0:n-1]) );

% desired frequency response is a pure delay (equalized channel)
Gdes = exp(-j*D*w);

% formulate and solve the Chebyshev design problem
cvx_begin
  variable hf(n,1)
  minimize( max( abs( G.*(A*hf) - Gdes ) ) )
cvx_end

% check if problem was successfully solved
disp(['Frequency equalization problem is ' cvx_status])
if ~strfind(cvx_status,'Solved')
  return
end

%********************************************************************
% time-domain equalization
%********************************************************************
% define the convolution matrix
Tconv = toeplitz([g; zeros(n-1,1)],[g(1) zeros(1,n-1)]);

% create array of all times without t=D
times_not_D = [1:D D+2:size(Tconv,1)];

% formulate and solve the time equalization problem
cvx_begin
  variable t
  variable ht(n,1)

  minimize( max( abs( Tconv(times_not_D,:)*ht ) ) )
  subject to
    Tconv(D+1,:)*ht == 1;
cvx_end

% check if problem was successfully solved
if ~strfind(cvx_status,'Solved')
  disp(['Frequency equalization problem is ' cvx_status])
  return
end

%********************************************************************
% equalizer plots
%********************************************************************
% plot g
figure(1)
plot([0:length(g)-1],g,'o',[0:length(g)-1],g,'b:')
xlabel('t')
ylabel('g(t)')

figure(2)
H = exp(-j*kron(w,[0:length(g)-1]))*g;
% magnitude
subplot(2,1,1);
plot(w,20*log10(abs(H)))
axis([0,pi,-20,20])
xlabel('w')
ylabel('mag G(w) in dB')
% phase
subplot(2,1,2)
plot(w,angle(H))
axis([0,pi,-pi,pi])
xlabel('w')
ylabel('phase G(w)')

% freq equalizer
figure(3)
plot([0:n-1],hf,'o',[0:n-1],hf,'b:')
xlabel('t')
ylabel('h(t)')

% plot g_tilde
figure(4)
gt=conv(g,hf);
plot([1:length(gt)]-1,gt,'o',[1:length(gt)]-1,gt,'b:')
xlabel('t')
ylabel('g tilde(t)')
axis([0,length(gt)-1,-.2 1.2])

figure(5)
H = exp(-j*kron(w,[0:length(gt)-1]))*gt;
% amplitude
subplot(2,1,1)
plot(w,20*log10(abs(H)))
axis([0,pi,-20,20])
xlabel('w')
ylabel('mag G tilde(w) in dB')
% phase
subplot(2,1,2)
plot(w,angle(H))
axis([0,pi,-pi,pi])
xlabel('w')
ylabel('phase G tilde(w)')

% time equalizer
figure(6)
plot([0:n-1],ht,'o',[0:n-1],ht,'b:')
xlabel('t')
ylabel('h(t)')

% plot g_tilde
figure(7)
gt=conv(g,ht);
plot([1:length(gt)]-1,gt,'o',[1:length(gt)]-1,gt,'b:')
xlabel('t')
ylabel('g tilde(t)')

figure(8)
H = exp(-j*kron(w,[0:length(gt)-1]))*gt;
% magnitude
subplot(2,1,1)
plot(w,20*log10(abs(H)))
axis([0,pi,-20,20])
xlabel('w')
ylabel('mag G tilde(w) in dB')
% phase
subplot(2,1,2)
plot(w,angle(H))
axis([0,pi,-pi,pi])
xlabel('w')
ylabel('phase G tilde(w)')
 
Calling SDPT3: 1799 variables, 31 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 31
 dim. of socp   var  = 1799,   num. of socp blk  = 600
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      mean(obj)   cputime
-------------------------------------------------------------------
 0|0.000|0.000|5.2e+02|2.8e+01|3.0e+04| 0.000000e+00| 0:0:00| chol  1  1 
 1|0.990|1.000|5.3e+00|9.6e-02|3.4e+02|-1.459459e+01| 0:0:00| chol  1  1 
 2|1.000|1.000|1.1e-07|9.6e-03|2.4e+01|-1.224387e+01| 0:0:00| chol  1  1 
 3|1.000|0.983|1.9e-08|1.1e-03|4.2e-01|-2.102187e-01| 0:0:00| chol  1  1 
 4|1.000|0.741|5.7e-09|3.6e-04|1.2e-01|-8.753066e-02| 0:0:00| chol  1  1 
 5|0.659|0.889|1.9e-09|4.8e-05|4.8e-02|-9.526151e-02| 0:0:00| chol  1  1 
 6|0.864|0.888|2.7e-10|6.3e-06|1.1e-02|-9.483495e-02| 0:0:01| chol  1  1 
 7|0.879|0.759|3.4e-11|1.6e-06|2.9e-03|-9.565164e-02| 0:0:01| chol  1  1 
 8|0.596|0.759|1.4e-11|3.9e-07|1.3e-03|-9.592666e-02| 0:0:01| chol  1  1 
 9|0.492|0.724|7.4e-12|1.1e-07|6.8e-04|-9.612943e-02| 0:0:01| chol  1  1 
10|0.460|0.577|4.0e-12|4.6e-08|4.0e-04|-9.624807e-02| 0:0:01| chol  1  1 
11|0.717|0.684|1.1e-12|1.4e-08|1.4e-04|-9.636335e-02| 0:0:01| chol  1  1 
12|0.650|0.863|4.0e-13|2.0e-09|5.5e-05|-9.640065e-02| 0:0:01| chol  1  1 
13|0.835|0.960|4.6e-14|7.9e-11|1.1e-05|-9.642115e-02| 0:0:01| chol  1  1 
14|0.933|0.961|6.1e-13|4.1e-12|1.3e-06|-9.642567e-02| 0:0:01| chol  1  1 
15|1.000|0.971|9.5e-12|1.1e-12|1.4e-07|-9.642622e-02| 0:0:01| chol  1  1 
16|0.566|1.000|2.5e-12|1.5e-12|7.2e-08|-9.642625e-02| 0:0:01| chol  2  2 
17|0.567|1.000|1.2e-12|1.0e-12|3.8e-08|-9.642626e-02| 0:0:01| chol  2  2 
18|0.567|1.000|1.5e-12|1.0e-12|2.0e-08|-9.642627e-02| 0:0:01| chol  1  1 
19|0.567|1.000|1.4e-12|1.0e-12|1.1e-08|-9.642628e-02| 0:0:02|
  stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 19
 primal objective value = -9.64262710e-02
 dual   objective value = -9.64262818e-02
 gap := trace(XZ)       = 1.08e-08
 relative gap           = 9.05e-09
 actual relative gap    = 9.05e-09
 rel. primal infeas     = 1.40e-12
 rel. dual   infeas     = 1.00e-12
 norm(X), norm(y), norm(Z) = 3.6e-01, 1.1e+00, 3.2e+00
 norm(A), norm(b), norm(C) = 1.6e+02, 2.0e+00, 2.5e+01
 Total CPU time (secs)  = 1.5  
 CPU time per iteration = 0.1  
 termination code       =  0
 DIMACS: 1.4e-12  0.0e+00  1.3e-11  0.0e+00  9.0e-09  9.0e-09
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.0964263
Frequency equalization problem is Solved
 
Calling SDPT3: 77 variables, 31 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 31
 dim. of socp   var  = 76,   num. of socp blk  = 38
 dim. of free   var  =  1 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      mean(obj)   cputime
-------------------------------------------------------------------
 0|0.000|0.000|2.6e+01|1.8e+01|4.1e+02|-1.437979e-10| 0:0:00| chol  1  1 
 1|1.000|1.000|9.4e-06|1.0e-01|7.0e+00|-3.431082e+00| 0:0:00| chol  1  1 
 2|1.000|0.981|1.2e-06|1.2e-02|1.3e-01|-6.342741e-02| 0:0:00| chol  1  1 
 3|1.000|0.744|2.3e-08|3.7e-03|5.0e-02|-2.668426e-02| 0:0:00| chol  1  1 
 4|0.544|0.588|1.2e-08|1.6e-03|3.1e-02|-2.986768e-02| 0:0:00| chol  1  1 
 5|0.867|0.876|1.9e-09|2.1e-04|7.8e-03|-3.169750e-02| 0:0:00| chol  1  1 
 6|0.876|0.470|6.8e-10|1.1e-04|3.0e-03|-3.235907e-02| 0:0:00| chol  1  1 
 7|0.968|0.335|4.3e-10|7.4e-05|1.7e-03|-3.227447e-02| 0:0:00| chol  1  1 
 8|1.000|0.929|1.3e-10|8.2e-06|2.7e-04|-3.163723e-02| 0:0:00| chol  1  1 
 9|0.867|0.972|3.1e-11|1.0e-06|2.4e-05|-3.162017e-02| 0:0:00| chol  1  1 
10|0.997|0.947|2.7e-10|9.2e-08|3.1e-06|-3.162482e-02| 0:0:00| chol  1  1 
11|1.000|0.947|3.7e-11|1.2e-08|2.7e-07|-3.162506e-02| 0:0:00| chol  1  1 
12|0.992|0.975|7.3e-12|1.0e-09|1.7e-08|-3.162505e-02| 0:0:00| chol  1  1 
13|0.557|0.944|3.3e-12|6.5e-11|5.8e-09|-3.162505e-02| 0:0:00|
  stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 13
 primal objective value = -3.16250442e-02
 dual   objective value = -3.16250500e-02
 gap := trace(XZ)       = 5.81e-09
 relative gap           = 5.46e-09
 actual relative gap    = 5.46e-09
 rel. primal infeas     = 3.29e-12
 rel. dual   infeas     = 6.46e-11
 norm(X), norm(y), norm(Z) = 7.7e-01, 1.1e+00, 2.7e-01
 norm(A), norm(b), norm(C) = 1.1e+01, 2.0e+00, 2.4e+00
 Total CPU time (secs)  = 0.3  
 CPU time per iteration = 0.0  
 termination code       =  0
 DIMACS: 3.3e-12  0.0e+00  7.8e-11  0.0e+00  5.5e-09  5.5e-09
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.031625