MATLAB: Plotting a sinusoidal wave

sinusoid

Hello,
I'm not sure how to go about write a function for a sinusoid that oscillates between 0 and 0.1 with a period of 1 second. The sinusoid should be sampled at 2ms and plotted for the first 10 seconds. Thank you in advance.

Best Answer

Try this:
% Make a sinusoid that oscillates between 0 and 0.1 with a period of 1 second.
% The sinusoid should be sampled at 2 ms and plotted for the first 10 seconds.
amplitude = 0.1;
period = 1.0;
% Time samples go from 0 to 10 seconds.
% Have 5000 of them so that the spacing is 2 milliseconds.
t = linspace(0, 10, 5000);
% Create y
y = amplitude * sin(2 * pi * t / period);
plot(t, y, 'b-', 'LineWidth', 2);
xlabel('t', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
grid on;
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');