% This is a MATLAB script file which creates and displays % the sum of two complex-conjugate complex-exponentials % as an animation. Very cool... % That is, the animation shows how % % exp(j*t)+exp(-j*t)=2*cos(t). % % I have found that this is a concept which students often % struggle with in Linear Systems (soon to be Signals and Systems) % and which is the basis of all Fourier analysis. % % The moving blue circle represents exp(j*t). % The moving red circle represents exp(-j*t). % The moving green circle represents the sum exp(j*t)+exp(-j*t)=2*cos(t). % The moving yellow is simply a time marker on the zero axis. % % Be patient, the frames must load, then they play fast. % You can reduce the memory requirements by increasing the % SKIP parameter and by increasing the step size in t. % % Author: Dr. Russell C. Hardie 10/22/97 % University of Dayton %---------------% % Generate Data % %---------------% figure(1) step=.01; t=[0:step:4*pi]; x=exp(i*t); plot3(real(x),t,imag(x)) hold on xc=exp(-i*t); %% plot3(real(xc),t,imag(xc),'r-') % plot conjugate path plot3(real(xc+x),t,imag(xc+x),'g-') Z=zeros(size(t)); plot3(Z,t,Z,'y-') title('The formation of cos(t) from complex exponentials'); xlabel('Real Axis'); ylabel('Time Axis'); zlabel('Imaginary Axis'); grid %----------------------------------% % Create Movie One Frame at a Time % %----------------------------------% SKIP=20; % controls how many points in t to move between each frame M=moviein(length(1:SKIP:length(t))); count=1; for n=1:SKIP:length(t) plot3(real(x(n)),t(n),imag(x(n)),'bo'); plot3(real(xc(n)),t(n),imag(xc(n)),'ro'); plot3(real(x(n)+xc(n)),t(n),imag(x(n)+xc(n)),'go'); plot3(0,t(n),0,'yo'); M(:,count)=getframe; count=count+1; drawnow hold off plot3(real(x),t,imag(x)) hold on %% plot3(real(xc),t,imag(xc),'r-') % plot conjugate path plot3(real(xc+x),t,imag(xc+x),'g-') plot3(Z,t,Z,'y-') title('The formation of cos(t) from complex exponentials'); xlabel('Real Axis'); ylabel('Time Axis'); zlabel('Imaginary Axis'); grid end %------------% % Play Movie % %------------% % frames per second fps=10; % movie speed (10 is max). movie(M,-5,fps)