%PCM Pulse Code Modulation vs variable channel BER
%J.Clark/Feb 28th 2008
%**************************************************************************
%Copy audio.wav located in C:\MATLAB7\work to test.wav using pcm_a.mdl
%[m d] = wavfinfo('test.wav') Gives wav file data
%audio.wav = test.wav 110336 samples in 1 channel
%x=wavread('test.wav') Read in wav file normalized to +/-1
%max(x)=.9921
%min(x)=-.7268
%y=2^16*x Normalize to +/- 65536
%max(y)=65016
%min(y)=-47634
%z=y+65536 Normalize to 0 to 131072
%max(z)=130552
%min(z)=17902
%2^17=131072 Require 17bits to represent
%b=de2bi(z,17) Convert decimal number to binary vector
%c=bsc(b,0.001) Introduce random errors with p(e) of 10-3
%Data test
%x(500)=0.0172
%y(500)=1128 0.0172*65536=11272
%z(500)=66664 (0.0172*65536)+65536=66663
%b(500,1:17)=00010110001000001
%bi2de(z) Convert back binary to decimal
%wavwrite(z,24000,'test1.wav') Adjust sampling frequency FS to 24000
%Playback corrupted file with pcm_b.mdl
%**************************************************************************
x=wavread('test.wav');
y=(2^16)*x;
z=(2^16)+y;
b=de2bi(z,17);
c=bsc(b,0.0001);
d=bi2de(c);
e=d-2^16;
f=e./2^16;
wavwrite(f,24000,'test1.wav');