Chapter 2 MATLAB Example
Chapter 2 MATLAB Example
Chapter 2 MATLAB Example
Chapter 2
f = 1; % Frequency of sinusoid in Hz period = 1/f; % Period of sinusoid in seconds t = 0:T:3*period; % Define a time vector of length 3 periods (should be long enough) t = t; % Make it a column vector (optional, but my preference) u = sin(2*pi*f*t); % Generate input signal plot(t,u,k-o); y = lsim(G,u,t); % Find output plot(t,u,k-o,t,y,r-*); grid; % Plot both input and output plot(t,u,k-o,t,y,r-*); grid; % Plot both input and output xlabel(Time (seconds)); % Annotate time axis (one method) legend(Input,Output); % Put legend on plot You can measure the frequency response characteristics from the plot: amplitude ratio and phase shift. Remember that to get phase shift from time shift t use the relation = t .