Plotting in MATLAB

Here is the MATLAB code used to plot \(x(t) = 10 \cos(2 \pi 1000 t + \pi/2 )\)
A = 10; f0 = 1000; phi = pi/2;
T0 = 1/f0;
tt = -2*T0 : T0/40 : 2*T0;

xx = A*cos(2*pi*f0*tt + phi);

plot(tt,xx)
title('Sinusoid: x(t) = 10 \cos(2*pi*1000*t + pi/2)');
xlabel('Time (sec)');
grid on

Line by line this code does:
  1. Define the three parameters for the plot, A=amplitude, f0=frequency, and phi=phase angle.
  2. The period, T0, is 1 over the frequency.
  3. tt is the time axis for the plot, here we start 2 periods before 0 and quit 2 periods after.
  4. Here the values of the cosine are computed.
  5. The plot.
  6. Put a title on the plot so we know what it is.
  7. Also label the x axis.
  8. Show the grid.
You can copy and paste this code into MATLAB to test it.
Once you have tried the code in MATLAB try modifying it to plot \(x(t) = 120 \cos(2 \pi 250 t - \pi/4 )\) for \(t\) from -4 ms to 8 ms. Does your answer make sense?