%Examples for the ELEC241 Matlab tutorial %Chris Rozell - 8/26/03 (crozell@rice.edu) t = [0:.01:1]; % independent (time) variable A = 8; % amplitude f_1 = 2; % create a 2 Hz sine wave lasting 1 sec s_1 = A*sin(2*pi*f_1*t); f_2 = 4; % create a 4 Hz sine wave lasting 1 sec s_2 = A*sin(2*pi*f_2*t); %plot the 2 Hz sine wave in the top panel figure subplot(3,1,1) plot(t, s_1) title('2 Hz sine wave') ylabel('Amplitude') %plot the 4 Hz sine wave in the middle panel subplot(3,1,2) plot(t, s_2) title('4 Hz sine wave') ylabel('Amplitude') %plot the summed sine waves in the bottom panel subplot(3,1,3) plot(t, s_1+s_2) title('Summed sine waves') ylabel('Amplitude') xlabel('Time (s)') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % create the same sine waves using Euler's relations s_3 = (exp(j*2*pi*f_1*t) - exp(-j*2*pi*f_1*t))/(2*j); s_4 = imag(exp(j*2*pi*f_2*t)); % plot the 2 and 4 Hz waves together in the same panel figure subplot(2,1,1) plot(t,s_3, 'b-') hold on plot(t, s_4, 'r--') ylabel('Amplitude') % again plot the sum in the bottom panel subplot(2,1,2) plot(t, s_3+s_4) ylabel('Amplitude') xlabel('Time (s)')