%nuqg.m
clc;
clear all;
close all;
%15 point non uniform quantization achieved for
%gaussian distributed data with unit variance.
%Initializing the points between -4 to 4
p=rand(1,6)*4;
p=sort(p);
p=[0 p 4];
%Computation of q's
for iteration=1:1:100000
for i=1:1:7
t=p(i):0.001:p(i+1);
temp=(1/sqrt(2*pi))*exp(-(t.^2)/2);
q(i)=(eps+trapz(t.*temp))/(eps+trapz(temp));
end
p(1)=0;
p(8)=4;
for i=2:1:7
p(i)=(q(i-1)+q(i))/2;
end
end
figure
subplot(2,1,1)
t=-4:0.001:4;
a=(1/sqrt(2*pi))*exp(-(t.^2)/2);
plot(t,a)
subplot(2,1,2)
p=p(2:1:length(p));
p=[-p 0 p];
p=sort(p);
q=[-q 0 q];
q=sort(q);
plot(p,zeros(length(p)),'ro')
hold on,plot(q,zeros(length(q)),'b*')