Professional Documents
Culture Documents
end
for j=0:L2-1
a = -F + j*2*F/L2;
b = -F + (j+1)*2*F/L2;
if (x(i+1) < -F)
Sq2(i+1) = -F + F/L2;
end
if (x(i+1) > F)
Sq2(i+1) = F - F/L2;
end
if(x(i+1) >=a && x(i+1) <b)
Sq2(i+1) = (a+b)/2;
end
end
for i = 0:N-1
e1 = e1 + (x(i+1) - Sq1(i+1))^2;
e2 = e2 + (x(i+1) - Sq2(i+1))^2;
end
e1 = sqrt(e1/N)
e2 = sqrt(e2/N)
subplot(3,1,1)
plot(s,x); xlabel('n'); ylabel('original signal');
subplot(3,1,2)
stairs(s,Sq1); xlabel('n'); ylabel('4 level quantizer');
subplot(3,1,3)
stairs(s,Sq2); xlabel('n'); ylabel('16 level quantizer');
Result:
s = 1:N;
for i=0:N-1
for j=0:L1-1
a = -F + j*2*F/L1;
b = -F + (j+1)*2*F/L1;
if (x(i+1) < -F)
Sq1(i+1) = -F + F/L1;
end
if (x(i+1) > F)
Sq1(i+1) = F - F/L1;
end
if(x(i+1) >=a && x(i+1) <b)
Sq1(i+1) = (a+b)/2;
end
end
end
for i=0:N-1
for j=0:L2-1
a = -F + j*2*F/L2;
b = -F + (j+1)*2*F/L2;
if (x(i+1) < -F)
Sq2(i+1) = -F + F/L2;
end
if (x(i+1) > F)
Sq2(i+1) = F - F/L2;
end
if(x(i+1) >=a && x(i+1) <b)
Sq2(i+1) = (a+b)/2;
end
end
end
for i = 0:N-1
e1 = e1 + (x(i+1) - Sq1(i+1))^2;
e2 = e2 + (x(i+1) - Sq2(i+1))^2;
end
e1 = sqrt(e1/N)
e2 = sqrt(e2/N)
subplot(3,1,1)
plot(s,x); xlabel('n'); ylabel('original signal');
subplot(3,1,2)
stairs(s,Sq1); xlabel('n'); ylabel('4 level quantizer');
subplot(3,1,3)
stairs(s,Sq2); xlabel('n'); ylabel('16 level quantizer');
Result:
max(max(X));
42;
length(X);
1:N;
i=1:N
Z(i) = X(i,1);
%Z(i,2) = X(i,2);
end
wavwrite(Z,Fs,'test');
for (i = 1:N)
x = abs(X(i,1));
if(X(i,1) > 0)
if ( (x >= 0) && (x <= V/A))
Y(i) = A*x/(1 + log(A));
end
if ( (x > V/A) && (x <= V))
Y(i) = V*(1 + log(A*x/V))/(1 + log(A));
end
else
if ( x >= 0 && x <= V/A)
Y(i) = -A*x/(1 + log(A));
end
if ( (x > V/A) && (x <= V))
Y(i) = -V*(1 + log(A*x/V))/(1 + log(A));
end
end
end
wavwrite(Y,Fs,'hello_Acomp');
V1 = max(Y);
for i=1:N
if ( abs(Y(i)) <= V/(1+log(A)))
Xr(i) = Y(i)*(1 + log(A))/A;
end
if ( (abs(Y(i)) >= V/(1+log(A))) && (abs(Y(i)) <= V))
if (Y(i) > 0)
Xr(i) = exp(abs(Y(i))*(1 + log(A))/V - 1)*V/A;
else
Xr(i) = -exp(abs(Y(i))*(1 + log(A))/V - 1)*V/A;
end
end
end
wavwrite(Xr,Fs,'hello_Aexp');
subplot(3,1,1)
plot(s,Z); xlabel('n'); ylabel('original signal');
subplot(3,1,2)
stairs(s,Y); xlabel('n'); ylabel('Compressed signal');
subplot(3,1,3)
stairs(s,Xr); xlabel('n'); ylabel('Expanded signal at receiver');
Result: