% Animation of a pressure wave reflecting from a partially % absorptive wall. Input is the absorption coefficient (alpha) % 9/20/2000 J Lamancusa % c=343.; freq=50; lambda=c/freq; alpha=input('alpha = ') refl=sqrt(1.0-alpha) w=2*pi*freq; k=w/c; xmax=1.75*lambda; x=linspace(0,xmax,100); npts=80 %80 points is one complete cycle M=moviein(npts); figure; for n=1:npts; t=n/2000.; a=k*x-w*t; b=k*x+w*t; y=sin(a); z=refl*sin(b); sum=(y+z); plot(x,y,'r-',x,z,'g-',x,sum,'b-'); axis([0 xmax -2.0 2.0]); h=uicontrol('Style','Pushbutton','Position',[5 0 80 30],... 'Callback','hold off','String','Hold Off'); h=uicontrol('Style','Pushbutton','Position',[95 0 80 30],... 'Callback','hold on','String','Hold On'); h=uicontrol('Style','Pushbutton','Position',[450 0 80 30],... 'Callback','close','String','QUIT'); M(:,n)=getframe; %drawnow; end; xlabel('Distance from Driver (meters)') ylabel('Sound Pressure (Pa)') S=['50 Hz ','ALPHA = ',num2str(alpha), ' REFL = ',num2str(refl)] title(S) text('position',[12.4 -2.0],'string','WALL','FontWeight','bold', 'rotation',90) text('position',[ -1.0 -2.0],'string','DRIVER','FontWeight','bold','rotation',90) movie(M,1); fig=figure('position',[100 100 300 200]); map= get(fig,'colormap'); %mpgwrite(M,map,'wave_movie',[1 0 1 0 10 8 10 25]);