%-------------------------------------------------------------- % % name: adpcm_sim.m % description: This simulation performs the encoding and % decoding of an audio file using the ADPCM % adaptive differential pulse code modulation % compression algorithm. % %--------------------------------------------------------------- clear %input the voice file. %[wav_voice,Fs,bits] = wavread('d:/ron_b/audio-stuff/sine_wave.wav',2e3); %read in wave file Fs = 8Khz 8bits %auwrite(wav_voice,Fs,8,'mu','d:/ron_b/audio-stuff/sine_wave.au'); %compress to mu-law format %voice = auread('d:/ron_b/audio-stuff/sine_wave.au'); %read in mu-law encoded data. %[wav_voice,Fs,bits] = wavread('c:/MATLABR11/bin/audio_samples/sine_wave.wav'); %read in wave file Fs = 8Khz 8bits %auwrite(wav_voice,Fs,8,'mu','c:/MATLABR11/bin/audio_samples/sine_wave.au'); %compress to mu-law format %voice = auread('c:/MATLABR11/bin/audio_samples/sine_wave.au'); %read in mu-law encoded data. [wav_voice,Fs,bits] = wavread('c:/MATLABR11/bin/audio_samples/Apco8000.wav',[10e3 30e3]); %read in wave file Fs = 8Khz 8bits auwrite(wav_voice,Fs,8,'mu','c:/MATLABR11/bin/audio_samples/Apco8000.au'); %compress to mu-law format voice = auread('c:/MATLABR11/bin/audio_samples/Apco8000.au'); %read in mu-law encoded data. mu_voice = lin2mu(voice); %convert to mu-law encoded. lk = adpcm_encode(mu_voice); %encode the voice signal using adpcm recovered_voice = adpcm_decode(lk); %decode the voice using adpcm lin_recovered_voice = mu2lin(recovered_voice); %convert to linear figure(9); subplot(2,1,1),plot(voice),title('linear input data stream'); subplot(2,1,2),plot(lin_recovered_voice),title('linear decoded data stream'); sound(voice,Fs,bits); %sound the input voice. pause sound(lin_recovered_voice,Fs,bits); %sound the decoded voice