A list,

Based on MATLAB PCM codec

Ii. Source code

clear all;
close all;
[x,fs]= audioread('C6_1_y.wav');  
v=1;
xx=x/v;
sxx=floor(xx*4096);
y=pcm_encode(sxx);
yy=pcm_decode(y,v)'; nq=sum((x-yy).*(x-yy))/length(x); sq=mean(yy.^2); snr=(sq/nq); t=(1:length(x))/fs; subplot(211) plot(t,x/max(abs(x))) axis tight title('(a) Pre-coding speech')
xlabel('Time/s')
ylabel('幅度')
subplot(212)
plot(t,yy/max(abs(yy)))
axis tight
title('(b) Decoded speech ')
xlabel('time/s')
ylabel('幅度'%PCM decode function function[out]=pcm_decode(ins,v) n=length(ins); % input is80 0 Bit PCM sampled signal in= 0 (ins'.8,n/8)'; Slot (1)=0; % slot(2)=32; slot(3)=64; slot(4)=128; slot(5)=256; slot(6)=512; slot(7)=1024; slot(8)=2048; step(1)=2; % step step (2) = 2; step(3)=4; step(4)=8; step(5)=16; step(6)=32; step(7)=64; step(8)=128; function[out]=pcm_encode(x) n=length(x); %-4096
      
       0 out(i,1)=1; Else out(I,1)=0; End the if abs (x (I)) > = 0 & abs (x (I)) < 32% according to the scope of input output after 2-4 out (I, 2) = 0; out(i,3)=0; out(i,4)=0; step=2; st=0; elseif 32<=abs(x(i)) & abs(x(i))<64 out(i,2)=0; out(i,3)=0; out(i,4)=1; step=2; st=32; elseif 64<=abs(x(i)) & abs(x(i))<128 out(i,2)=0; out(i,3)=1; out(i,4)=0; step=4; st=64; elseif 128<=abs(x(i)) & abs(x(i))<256 out(i,2)=0; out(i,3)=1; out(i,4)=1; step=8; st=128; elseif 256<=abs(x(i)) & abs(x(i))<512 out(i,2)=1; out(i,3)=0; out(i,4)=0; step=16; st=256; elseif 512<=abs(x(i)) & abs(x(i))<1024 out(i,2)=1; out(i,3)=0; out(i,4)=1; step=32; st=512; elseif 1024<=abs(x(i)) & abs(x(i))<2048 out(i,2)=1; out(i,3)=1; out(i,4)=0; step=64; st=1024; elseif 2048<=abs(x(i)) & abs(x(i))<4096 out(i,2)=1; out(i,3)=1; out(i,4)=1; step=128; st=2048; else out(i,2)=1; out(i,3)=1; out(i,4)=1; step=128; st=2048; End if(abs(x(I))>=4096) % out(I,2:8)=[1 1 1 1 1 1 1 1]; Out (I,5:8)=t(1:4); end
      Copy the code

3. Operation results

Fourth, note

Version: 2014 a