Why do I have a problem in doing a uniform quantizationfor the fourth sample and the 0 ?

close all;
clear all; clc;
F = 50;
Ts = 1/800;
tmin = 0;
tmax= 0.02;
nmin = ceil(tmin/Ts);
nmax = floor(tmax/Ts);
n = nmin:nmax;
x = sin(2*pi*F*n*Ts);
N= 2 ;
L = 2^N;
xmax = ceil(max(x));
xmin = floor(min(x));
step_size = (xmax-xmin)/L;
L_l = floor(min(x)):step_size: ceil(max(x)); % This the quantization levels
mid_levels = xmin+step_size/2:step_size: xmax % This is the mid lines
% of the quantization levels
disp('quantization level')
disp(L_l)
for j=1:nmax+1
y(j)=sin(2*pi*F*(j-1)*Ts);
end
disp('values of the samples of the function ')
disp(y)
% check if the sample is within a range of the quantiza levels
%if yes give it the corresponding mid line
for I= 1:nmax+1
y1(j)=sin(2*pi*F*(j-1)*Ts);% vector with the samples of the signal
for j=1:L
if y(I)<=L_l(j+1) && y(I)>L_l(j) % If the sample is between L1 = L_(j)
%and L2 = L_(j+1)
y1(I) = mid_levels(j); % give it the mid line of L1 (between L1 and0)
end
% I tried to even make others if statement to cover everything but
% it didn't work
end
end
disp('new values ');
disp(y1);
stem(n,x,'filled','LineWidth',1)
hold on
stem(n,y1,'filled','LineWidth',1)
ylim([xmin,xmax]);
yticks(xmin:(step_size):xmax);

Answers (0)

Asked:

on 23 Dec 2020

Edited:

on 23 Dec 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!