欢迎来到天天文库
浏览记录
ID:53279686
大小:31.00 KB
页数:3页
时间:2020-04-02
《PCM编解码的MATLAB实现.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、clc%clearallcloseallfs=100;t=1/fs:1/fs:1;n=8;s1=cos(2*pi*t);s=s1/max(abs(s1));%信号归一化y=Alaw(s);%A律量化[quc]=u_quantize(y,n);qu1=decode(c,length(s),ceil(log2(n))+1);x=invAlaw(qu1);x=x*max(abs(s1));plot(t,s1)holdonplot(t,x,'r')figure(2)functiony=Alaw(s0)A=87.6;A0=1/A;s=abs(s0);y=zeros(1,length(s));y(
2、find(s<=A0))=(A*s(find(s<=A0))/(1+log(A))).*sign(s0(s<=A0));y(find(s>A0))=((1+log(A*s(find(s>A0))))/(1+log(A))).*sign(s0(s>A0));functionx=invAlaw(y)A=87.6;A0=1/A;y0=abs(y);index=find(y0<=1/(log(A)+1));%x(index)=(log(A)+1)/A*y0(index).*sign(y(index));x(index)=y0(index)*(1+log(A))/A.*sign(y(index)
3、);index=find(y0>1/(log(A)+1));x(index)=1/A*exp(y0(index)*(1+log(A))-1).*sign(y(index));%x(index)=1/A*exp(y0(index)/(1/(log(A)+1))-1).*sign(y(index));function[quc]=u_quantize(y0,n)%%%%%%%%均匀量化m=0:1/n:1;q=m(1:n)+1/(2*n);n1=ceil(log2(n));y=abs(y0);fori=1:nqu(find((y>=m(i))&y<=m(i+1)))=q(i);codi(fin
4、d((y>=m(i))&y<=m(i+1)))=i-1;endqu=qu.*sign(y0);%%%%%%%%编码c=zeros(1,length(y0)*(n1+1));fork=1:length(y0)c((k-1)*(n1+1)+2:k*(n1+1))=dectobin(codi(k),n1);ify0(k)>0c((k-1)*(n1+1)+1)=1;endend%cod=dec2bin(codi);%[rl]=size(cod);%fork=1:r%c((k-1)*(l+1)+1)=sign(y0(k)+abs(y0(k)));%fork1=2:l+1%c((k-1)*(l+1
5、)+k1)=str2num(cod(k,k1-1));%end%end%%cod=str2num(cod);%%%%%%%%将符号数组转换为数字%r=ceil(log2(n+1));%c=zeros(1,length(codi)*r);%fork=1:length(codi)%l=length(cod(k,:));%forj=1:length(cod(k,:))%c((k-1)*r+j)=str2num(cod(k,j));%end%endfunctionqu1=decode(c,N,n0)%N=length(c)/8;n=2^(n0-1);m=0:1/n:1;q=m(1:n)+1/(
6、2*n);%mi=zeros(1,N);fori=1:Nmi=bintodec(c((i-1)*n0+2:i*n0));qu1(i)=q(mi+1);ifc((i-1)*n0+1)==0qu1(i)=-qu1(i);
此文档下载收益归作者所有