%Daniel Linnen %HW2 Half Duplex clear all; %declaring counting variables l=1; m=1; count=1; %initializing values to zero xn=0; sn=0; dn=0; echo=0; Pxe1=0; Pde1=0; hang=0; %declaring files f1=fopen('C:\ELE 498D\testw.dat', 'r'); f2=fopen('C:\ELE 498D\test1.dat', 'r'); %initializing arrays x=zeros(105,1); p=zeros(11,1); h=[-0.01,-0.05,0.1,0.3,0.2,-0.1,0.05,0.01]; %end of declaration %start of program while(count==1) %reading files [xn,count] = fread(f1, 1, 'short'); if(count==0) break; end [sn,count] = fread(f2, 1, 'short'); l=l+1; %converting to integers xn = xn/32768; sn = sn/32768; %update the input buffer for i=105:-1:2 x(i)=x(i-1); end %end for x(1)=xn; echo=0; %convolution (to make the echo) for i=98:105 echo = echo + h(i-97) * x(i); end %end for %combining talker2's voice with echo, the only signal we have access too dn = echo + sn; %exponential Pxe1 = 0.95 * Pxe1 + (1-0.95) * xn * xn; Pde1 = 0.95 * Pde1 + (1-0.95) * dn * dn; %per 64 samples store one point if(l==65) Pxe(m) = 10*log10(Pxe1); %converting to dB Pde(m) = 10*log10(Pde1); for(z=11:-1:2) %shifting hang buffer p(z)=p(z-1); end p(1)=Pxe(m); if(Pde(m) < p(11)-3) %comparing with hang measurement in dB Pde(m) = Pde(m)-30; %attenuating in dB end m=m+1; %incrimenting Pxe1=0; %resetting values Pde1=0; l=1; end %end if end % end while %% plotting figure(1) plot(Pxe, 'r') hold plot(Pde, 'b')