MATLAB: Difficulty to use “sin” function

sin

Consider following:
T = 0.02; %period (sec)
w = 2 * pi / T; %w = 314.1593, angqular frequency (rad/sec)
t = 0 : 0.01 : 20; %time vector (sec)
x = sin(w*t);
plot(t,x)
What is wrong with MATLAB? A sine plot does not look like above. When I set w = 314.1593, the above figure will be plotted. Sine function is a periodic function. But above plot is something completely different. Maximum value should be equal to 1.0 but it is about 10e-12. I cannot figure out where is the problem?

Best Answer

Either increase you sampling rate
T = 0.02; %period (sec)

w = 2 * pi / T; %w = 314.1593, angqular frequency (rad/sec)

t = 0 : 0.001 : 20; %time vector (sec)

x = sin(w*t);
plot(t,x)
or add a phase in sin
T = 0.02; %period (sec)
w = 2 * pi / T; %w = 314.1593, angqular frequency (rad/sec)
t = 0 : 0.01 : 20; %time vector (sec)
x = sin(w*t+pi/10);
plot(t,x)