x=round(10*(rand(5,16)+rand(5,16)-rand(5,16)))
mx=max(max(x)),mn=min(min(x))
H=3L=1
y=(H-L)/(mx-mn)*(x-mn)+L
结果:
x =
-2 7 6-5 8 5-1 2 0-7 3 010 8 9 2
5-3 3 4 6 5 011 0 8-4 4 01016 2
8-4 1 9 912 010 6 7 2 9 8 8 7 6
9-110 6 5 815 7 0 0-1 510 413 4
1 8 3 112 8 9 7 3 0 7 5 7 6 4 5
mx =
16
mn =
-7
y =
Columns 1 through 12
1.43482.21742.13041.17392.30432.04351.52171.78261.60871.00001.86961.6087
2.04351.34781.86961.95652.13042.04351.60872.56521.60872.30431.26091.9565
2.30431.26091.69572.39132.39132.65221.60872.47832.13042.21741.78262.3913
2.39131.52172.47832.13042.04352.30432.91302.21741.60871.60871.52172.0435
1.69572.30431.86961.69572.65222.30432.39132.21741.86961.60872.21742.0435
Columns 13 through 16
2.47832.30432.39131.7826
1.60872.47833.00001.7826
2.30432.30432.21742.1304
2.47831.95652.73911.9565
2.21742.13041.95652.0435
%修改抽样间隔为0.1和程序最后两行%可以观察量化输入输出关系n=input('量化级数,k=[8]')if isempty(n), n=64%默认便产生8个量化级数end%产生题目要求的函数endtime = 2%结束时间dt = 0.1%抽样间隔.抽样20个点t = 0:dt:endtime%0:0.1:2a = zeros(size(t))%产生一个长度为20的全0序列 size(t)->20for tt=1:1/胡没dt %1:10 a(tt+[0:endtime/2-1]*(2/dt))=t(tt)%t when 0 <= t <1endfor tt=1/dt+1:2/dt a(tt+[0:endtime/派拦2-1]*(2/dt))=2-t(tt)% -t+2 when 1 <= t <裤羡纳 2end%均匀量化amax=max(abs(a))%对a求绝对值并将最大值赋给amaxa_quan=a/amax%归一化b_quan=a_quan%赋初值d=1/n%量化间隔q=d.*[1:n]q=q-d/2%量化电平为量化间隔的中间值%对归一化后的输入信号序列进行量化for i=1:n%定位第i个量化间隔码子 a_quan(find((q(i)-d/2<=a_quan) &(a_quan<=q(i)+d/2)))=...q(i).*ones(1,length(find((q(i)-d/2<=a_quan)&(a_quan<=q(i)+d/2))))%赋值为相应的量化电平 b_quan(find(a_quan==q(i))) =(i-1) .* ones(1,length(find(a_quan==q(i))))enda_quan=a_quan*amax%恢复原值(量化后)nu=ceil(log2(n))%编码code=zeros(length(a),nu)for i=1:length(a) for j=nu:-1:0 %从高向低编码 if (fix(b_quan(i)/(2^j))==1) code(i,(nu-j))=1b_quan(i)=b_quan(i)-2^jend endendsqnr=20*log10(norm(a)/norm(a-a_quan))%求量化信噪比欢迎分享,转载请注明来源:内存溢出
评论列表(0条)