Beruflich Dokumente
Kultur Dokumente
close all
clc
%fid = fopen('voice1.wav','r'); % open given raw data file
%[s_in,COUNT] = fread(fid,'int16'); % read the given data into vector X
inputfilename=input('Enter the Wave file name (ie ''test.wav'') => ','s');
disp('
OK ')
[s_in,fs,N]=wavread(inputfilename);
%s_in=s_in(1:end,1);
s_in=s_in';
%zzz=zeros(1,500);%[1 -1 1-1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1
-1 1 -1 1-1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1-1 1 1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1-1 1 -1 1 -1 1 -1 1 -1
1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1];
%s_in=[zzz,s_in];
COUNT=22000;
disp(' PLEASE WAIT ADPCM CODING IN PROGRESS');
disp('
')
%%%%%%%%%%%%%LOOK UP TABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
indexTable=[-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8];
%stepsizeTable=[ 16 17 19 21 23 25 28 31 34 37 41 45 50 55 60 66 73 80 88 97 107
118 130 143 157 173 190 209 230 253 279 307 337 371 408 449 494 544 598 658 724
796 876 963 1060 1166 1282 1411 1552];
stepsizeTable = [7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34
, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190,
209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876,
963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 33
27, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 114
87, 12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767]
;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%ENCODER %%%%%%%%%%%%%%%%%%%%%
%initialization
d_n=0;
x_p=0;% x predicted
%d_n=??????
B3 = 0; B2 =0 ; B1 =0; B0 = 0;% bits of quantized difference
index=1;
ss_n=stepsizeTable(index);% stepsize
time=clock;
for (i=1:COUNT)
d_n= s_in(i) - x_p; %%
if d_n 0
B3 = 1;
d_n = abs(d_n);
else
B3 = 0;
end
if (d_n >= ss_n)
B2 = 1; d_n = (d_n - ss_n);
else
B2 = 0;
end
if (d_n >= (ss_n/2) )
i =i+1;
end
comptime= etime(clock,time);
%fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%ENCODER ENDS %%%%%%%%%%%%%%%%%%%%%%%%
comin=fix(comptime/60);
cosec=round(rem(comptime,60));
demin=fix(decomptime/60);
desec=round(rem(decomptime,60));
disp(' ')
str=[' Time taken to compress file = ',int2str(comin),'min ',int2str(cosec),'sec
'];
disp(str)
str=[' Time to decopress file = ',int2str(demin),'min ',int2str(desec),'sec'];
disp(str)
disp(' ')
otherwise
%disp('OK. THANX & ALLAH HAFIZ')
disp(' ')
loop=0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%PLOTS%%%%%%%%%%%%%%%%%%
let1=input('Do you want to view plots of the data (Y/N) ? ','s');
switch let1
case {'Y','y'}
subplot(2,1,1)
xx=1:151;
plot(xx,s_in(300:450))
title('Original Speech Signal');
subplot(2,1,2)
plot(xx,output(300:450))
title('Decompressed ADPCM Speech Signal');
otherwise
disp(' ')
disp('OK. THANX & ALLAH HAFIZ')
disp(' ')
end