difficulty to use "sin" function

6 visualizzazioni (ultimi 30 giorni)
parham kianian
parham kianian il 13 Mag 2020
Commentato: Stephen23 il 13 Mag 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 Commento
Stephen23
Stephen23 il 13 Mag 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 ?

Accedi per commentare.

Risposta accettata

Mehmed Saad
Mehmed Saad il 13 Mag 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)

Più risposte (1)

Walter Roberson
Walter Roberson il 13 Mag 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.

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by