%Daniel Linnen %HW1 clear all; %declaring counting variables l=1; m=1; count=1; %initializing values to zero h1=0; x1=0; xn=0; sn=0; dn=0; Pxr=0; Pdr=0; echo=0; Pxe1=0; Pde1=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); 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 h1=h(i-97); x1=x(i); 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; Pdr=Pdr+dn*dn; Pxr=Pxr+xn*xn; %rectangular if(l==65) Pxe(m) = 10*log10(Pxe1); Pde(m) = 10*log10(Pde1); Pxrw(m) = 10*log10(Pxr/64); Pdrw(m) = 10*log10(Pdr/64); m=m+1; pxr=0; pdr=0; Pxe1=0; Pde1=0; l=1; end %end if end % end while %% plotting figure(1) plot(Pxrw, 'r') hold plot(Pdrw, 'b') figure(2) plot(Pxe, 'r') hold plot(Pde, 'b')