Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Visualizing Phase Shift
- % This code creates a Phase shift sin(theta) with animation and movie
- %% a) Animation of phase shift
- axis( [-pi, pi, -1, 1] ); % axis constraints
- theta = linspace( -pi, pi, 100); % value of theta
- delta_theta = 0 : 0.1 : pi; % phase shift
- y = sin(theta);
- h = plot( theta, y ); % plot sin(theta)
- xticks ( [-pi -2*pi/3 -pi/3 0 pi/3 2*pi/3 pi] ) % x-axis tick marks
- xticklabels({'-\pi', '-2/3\pi', '-1/3\pi' '0\pi', ...
- '1/3\pi' , '2/3\pi', '\pi'}) % x-axis tick labels
- title('phase shift by 0')
- a = 1;
- for b = delta_theta(1:end)
- a = a + 1;
- y = sin(theta - b);
- set(h, 'XData', ...
- theta, 'YData', y)
- drawnow
- str = sprintf('Phase Shift by %s',...
- num2str(b));
- title(str)
- pause(0.05)
- end % for loop
- %% b) Movie of phase shift
- axis( [-pi, pi, -1, 1] ); % axis constraints
- theta = linspace( -pi, pi, 100); % value of theta
- delta_theta = 0 : 0.1 : pi; % phase shift
- y = sin(theta); % g1(x)
- h = plot( theta, y ); % plot sin(theta)
- xticks ( [-pi -2*pi/3 -pi/3 0 pi/3 2*pi/3 pi] ) % x-axis tick marks
- xticklabels({'-\pi', '-2/3\pi', '-1/3\pi' '0\pi', ...
- '1/3\pi' , '2/3\pi', '\pi'}) % x-axis tick labels
- title('phase shift by 0')
- a = 1;
- Phase_Shift(1) = getframe;
- for b = delta_theta(1:end)
- a = a + 1;
- y = sin(theta - b);
- set(h, 'XData', ...
- theta, 'YData', y)
- str = sprintf('Phase shift by %s', ...
- num2str(b));
- title(str)
- pause(0.1)
- Phase_Shift(a) = getframe;
- end %for loop
- pause;
- movie(Phase_Shift)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement