fs=input('请输入采样频率fs=');
n=0:fs;
t=0:0.0001:1;
mt=sin(2*pi*t);
sinf=sin(2*pi*n/fs);
stem(n/fs,sinf,'.','r');%hold on;
%plot(t,mt);grid on;
b=1;
a=-1;
M=16; %量化级数
delta=2/M; %量化间隔
for i=1:M+1
mi(i)=a+(i-1)*delta; %第i个量化级的初始电平
qi(i)=a+i*delta-delta/2; %第i个量化级的量化值
end
for i=1:17
for k=1:33
if(sinf(k)==mi(i))
sinf1(k)=mi(i)+delta/2;
end
end
for j=1:16
for k=1:33
if(mi(j)<sinf(k) && sinf(k)<mi(j+1))
sinf1(k)=qi(j);
end
end
end
end
n=0:32;hold on;
stem(n/32,sinf1,'o');
axis([0 1 -1.1 1.1]);