Homework # 2 Solutionece-research.unm.edu/hayat/ece542_04/Hw2sol.pdf · Homework # 2 Solution ......
Click here to load reader
Transcript of Homework # 2 Solutionece-research.unm.edu/hayat/ece542_04/Hw2sol.pdf · Homework # 2 Solution ......
EECE542: Digital Communications Theory Prof. M. Hayat Homework #2 Solution
6
Homework # 2 Solution
>
≤=Φ
AuAAuu
u)( ; Q is a 4-level quantizer
Assume that X(t) is WSS with pdf;
>
≤−=
00
11)(
x
xxxf X Assume that A = 0.8
( )[ ]( ) ( ) ( )∫ ∫ ∫ −+−+−=
Φ−Ε=b A
b AXXX dxxfqAdxxfqxdxxfqx
XXQ
0
12
22
22
1
22
)(2)(2)(2
)()(σ
From class notes, for each b ≥ 0, the best choice of q1 & q2 must satisfy
(*)
∫
∫= b
X
x
X
dxxf
dxxxfq
0
01
)(
)( ;
∫
∫ ∫+−= 1
1
2
)(
)()1(
bX
A
b AX
dxxf
dxxfAdxxxq
After some algebra, we obtain,
( )bbbq
3623
1 −−
= ; ( )363
32)33(2
22
2 +−−++−
=bb
bbAAAq
Furthermore, the optimal choice of b must satisfy
( )2121 qqb +=
EECE542: Digital Communications Theory Prof. M. Hayat Homework #2 Solution
6
Now Substitute for q1 and q2 in terms of b to obtain: ( ) 02916102 234 =−++−+− KbKbbb
where ( )233 AAAK +−= with a = 0.8, we solve for b and obtain: b = 0.3746 ; q1 = 0.1729 ; q2 = 0.5762 Solutions to Problem 1: Huffman encoder/decoder solution (by B. Ratliff): The following files can be found at the the courses’s webpage at: http://www.eece.unm.edu/faculty/hayat/eece542_02/hw.html ENCODER.EXE DECODER.EXE codegen.h decoder.cpp encoder.cpp list.h probgen.h To encode a file called input.txt, using k symbols at a time, and r percent perturbation, type the following at the dos command prompt: encoder input.txt output.txt k r This puts the Huffman code for input.txt in the file output.txt. To decode the file output.txt and put in the file input.txt, type decoder output.txt input.txt k r Simulation ** See the following Matlab code and plot. For each b, there is a q1 and 2, according to (*), we can plot the empirical error as a function of b in the range 0 – 0.8. Note that the empirical minimizing bOPT is ~ 0.3856 when 50,000 simulated runs are generated. By contrast, bOPT ≈ 0.3364 when 500 samples are used. Also note that the experimental bOPT depends on the mesh size used to partition b, which is 1/500 in the following code. Matlab code for solving for the parameter “b” and the q’s: clear a=.8; n=1 k=(a*(3-3*a+a*a)); a4=-2; a3=10; a2=-16; a1=9+k; a0=-2*k;
EECE542: Digital Communications Theory Prof. M. Hayat Homework #2 Solution
6
C=[a4 a3 a2 a1 a0]; R=roots(C); b_th=R(4) b=b_th; q1=(b*(3-2*b))/(6-3*b); q2=(k+b*b*(2*b-3))/(3*(b-1)^2); X=(rand(1,n)+rand(1,n))-1; I1=find(X>a); X(I1)=a; I2=find(X<-a); X(I2)=-a; J1=find(X<=-b); J2=find(X>-b & X<=0); J3=find(X>0 & X<b); J4=find(X>=b); Q(J1)=-q2; Q(J2)=-q1; Q(J3)=q1; Q(J4)=q2; err=(sum((Q-X).^2))/n; B=b; end b_th Simulation code showing the optimal b: %ECE-522, Digital Communications II %Winter 2001, M. M. Hayat %HW 3, four-level quantizer: Theoretical and %simulation_based optimization clear a=.8; n=5000 k=(a*(3-3*a+a*a)); a4=-2; a3=10; a2=-16; a1=9+k; a0=-2*k; C=[a4 a3 a2 a1 a0]; R=roots(C);
EECE542: Digital Communications Theory Prof. M. Hayat Homework #2 Solution
6
b_th=R(4) b=0; for i=1:500 q1=(b*(3-2*b))/(6-3*b); q2=(k+b*b*(2*b-3))/(3*(b-1)^2); X=(rand(1,n)+rand(1,n))-1; I1=find(X>a); X(I1)=a; I2=find(X<-a); X(I2)=-a; J1=find(X<=-b); J2=find(X>-b & X<=0); J3=find(X>0 & X<b); J4=find(X>=b); Q(J1)=-q2; Q(J2)=-q1; Q(J3)=q1; Q(J4)=q2; err(i)=(sum((Q-X).^2))/n; B(i)=b; b=b+a/500; end plot(B,err) xlabel('b') ylabel('\sigma^2') b_sim=B(find(err==min(err))) b_th
EECE542: Digital Communications Theory Prof. M. Hayat Homework #2 Solution
6
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.80.01
0.015
0.02
0.025
0.03
0.035
0.04
0.045
0.05
0.055
b
σ2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.80.01
0.015
0.02
0.025
0.03
0.035
0.04
0.045
0.05
0.055
0.06
b
σ2
Plots: N = 5000 N = 500
EECE542: Digital Communications Theory Prof. M. Hayat Homework #2 Solution
6
N = 50,000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.80.01
0.015
0.02
0.025
0.03
0.035
0.04
0.045
0.05
0.055
b
σ2