A1=8;
fs=1000;% sampling frequency
fc=150;% frequency of the signal
t=0:1/fs:1;%discrete time
x=A1*cos(2*pi*fc*t);% discrete signal
%--------Quantization------------%
n=4;
L=(2^n);
delta=(max(x)-min(x))/L;
xq=min(x)+(round((x-min(x))/delta)).*delta;
%--------END------------%
subplot(2,1,1)
stem(t,x,'R');
subplot(2,1,2);% breaking the window figure to plot both graphs
stem(t,x,'b');% plot of discrete time signaltitle('Discrete time representation')% title of the figure
xlabel('time(s)')% label on the x-axis of the plot
ylabel('X[n]')% label on the y-axis of the plot
subplot(2,1,2);
stairs(t,xq,'b');% the quantized output
title('Quantized Signal')% title of the figurea
xlabel('time')% label on the x-axis of the plot
ylabel('amplitude')% label on the y-axis of the plot
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}