difficulty to use "sin" function

7 visualizaciones (últimos 30 días)
parham kianian
parham kianian el 13 de Mayo de 2020
Comentada: Stephen23 el 13 de Mayo de 2020
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?
  1 comentario
Stephen23
Stephen23 el 13 de Mayo de 2020
You are plotting integer multiples of pi:
>> w*t(1:8)
ans =
0.00000 3.14159 6.28319 9.42478 12.56637 15.70796 18.84956 21.99115
What is sine of any integer multiple of pi ?

Iniciar sesión para comentar.

Respuesta aceptada

Mehmed Saad
Mehmed Saad el 13 de Mayo de 2020
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)

Más respuestas (1)

Walter Roberson
Walter Roberson el 13 de Mayo de 2020
Your w is approximately 100*pi and your t values are all integer multiples of 1/100 . When you multiply the two together, you get an integer multiple of 1/100 * 100*pi which will give you an integer multiple of pi. sin() of an integer multiple of pi is 0 to within round-off error. SO what you are plotting is just round-off error.

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by