pcm_use.m
来自「西交大刘树棠写的《数字信号处理》那本书的所有源代码」· M 代码 · 共 28 行
M
28 行
%show the pcm encode and decode
%editor :mnp
%Email:sagadean@126.com
clc;
fs=8;ts=1/fs;
t=0:0.01:5;
xt=sin(2*pi*t)
subplot(311);plot(t,xt);grid
t1=0:ts:5;
x=sin(2*pi*t1);
subplot(312);stem(t1,x);
xx=floor(x(1:8)*4096);%取一个周期八个点,向零取整
y=pcm_a_encode(xx);%y为8*8的矩阵
ym=y'%先转置
y1=ym(:)';%转为1*64的矩阵
yy=pcm_a_decode(y1);%
%取五个周期,通过巴特沃兹滤波器后,抽样信号还原
y3=[yy yy yy yy yy];
t2=0.016:0.016:length(y3)*0.016*8
x1=zeros(1,8*length(y3));
for i=1:length(y3)%插值,使得波形平缓抽样信号
x1(8*i-7)=y3(i)
end
[b a]=butter(9,1/32);
yy2=filter(b,a,x1);
subplot(313);plot(t2,yy2)
axis([0 5 -500 500]);grid
title('抽样信号还原波形');xlabel('t2');ylabel('y');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?