Вы находитесь на странице: 1из 9

2/29/2012

CMME302
DIGITAL
COMMUNICATION
MATLAB ASSIGNMENT
NO.1
2

The -law (for positive amplitude)

y =


ln

) 0



The MATLAB code and plot for the -law are shown below:
function Calculate(mu)

% mu: compression parameter

X=0:0.01:1; %x=m/mp

Y1= (1/(log(1+mu(1)))*(log(1+(mu(1)*X))));
Y2= (1/(log(1+mu(2)))*(log(1+(mu(2)*X))));
Y3= (1/(log(1+mu(3)))*(log(1+(mu(3)*X))));
Y4= (1/(log(1+mu(4)))*(log(1+(mu(4)*X))));


plot (X,Y1,'r'),grid
hold on
plot (X,Y2,'b')
hold on
plot (X,Y3,'k')
hold on
plot (X,Y4,'y')


xlabel('m/m_p')
ylabel(' \mu law')
title('The plot of \mu law')
legend(' \mu=0.001',' \mu=10',' \mu=100',' \mu=1000')

hold off
end

% In the MATLAB command window

>> Calculate([0.01 10 100 1000])


3




The A-law (for positive amplitude)


{




function Y=calculaw(A)

step1=(1/A)/100;
X1= 0 : step1 : (1/A);
Y1= (A/(1+log(A)))*X1;

step2=(1-(1/A))/100;
X2 = (1/A) : step2 : 1;
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
m/m
p



l
a
w
The plot of law


=0.001
=10
=100
=1000
4

Y2= (1/(1+log(A)))*(1+log(A*X2));

Y= [Y1,Y2];
X=[X1,X2];

plot(X,Y,'r'),grid
xlabel(' m/m_p')
ylabel(' A law')
title('The plot of A-law')
hold on

end

% In MATLAB command window

>> calculaw(1);
>> calculaw(10);
>> calculaw(87.6);
>> calculaw(1000);



0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
m/m
p

A


l
a
w
The plot of A-law
5

Ratio of signal to quantization noise in PCM

Our first trial to do this plot was by used the simplified equation (approximated) for
SNR mentioned in our textbook. The equation and the resultant plot are shown below:



This equation requires that:




- The MATLAB code for the above equation is:

function SNR= calcu(mu)
X=0:0.10:60;
SNR=10*log10((3*(256^2))./(log(1+mu)).^2);

hold on

plot (X,SNR,'b'); grid

xlabel('Relative signal power')
ylabel('SNR in dB')
title('Ratio of signal to quantization noise in PCM with and without compression')

hold off

end

% in MATLAB command window

>> calcu(200);

>> calcu(.000001);


The resultant plot:

6




We can see that the output SNRdB is a straight line through the different values for
the sigas power, which is expected sice its a costat. Ad we ca see that whe ,
the SNR is about 39 dB.

In order to get the original shape for the SNR we went back to the un-approximated
equation that gives the SNR in both its conditions; compressed case and uncompressed
case. The equation is:



0 10 20 30 40 50 60
20
40
60
80
100
120
140
160
180
Relative signal power
S
N
R

i
n

d
B
Ratio of signal to quantization noise in PCM with and without compression
7


{




In the uncompressed case we get

from the line intersection with zero from the


already known graph in the textbook. We found it to be about 7dB which equals to 5 in
linear scale (

.
We wrote that MATLAB code for this case and plotted it as follows:
x=0:10:60;
X=10.^(x./10);
y=X/6.3;
y1=196608*y;
Y=10*log10(y1);
plot(x,Y)
grid
xlabel('Relative signal power');
ylabel('SNR in dB');
title ('Uncompressed case for SNR');

0 10 20 30 40 50 60
40
50
60
70
80
90
100
110
Relative signal power
S
N
R

i
n

d
B
Uncompressed case for SNR
8

It should be a linear straight ie startig from 7dB, but I dot kow where the
mistake that I did is.

As the compressed case is like the simplified equation above, so it will also give a
straight line (constant). So, we tried to go for the origins of this equation, we found several
derivations, we used one of them its code and plot as follow:

The MATLAB code and plot:

X=0:0.01:100;

y1=((54.1).*(X.^2));
y2=(1+(0.4596.*X)+(0.0528.*(X.^2)));
y3=y1.*(0.0528./y2);

Y=10*(log(y3));

plot(X,Y)
grid

xlabel('Relative signal power in dB')
ylabel('SNR in db')
title('SNR if \mu-law compandor was used')

9




0 10 20 30 40 50 60 70 80 90 100
-100
-80
-60
-40
-20
0
20
40
Relative signal power in dB
S
N
R

i
n

d
b
SNR if -law compandor was used

Вам также может понравиться