generate simple sine wave in matlab

不羁的心 提交于 2019-12-10 12:35:25

问题


How do I generate a simple sine wave in matlab?

I would like to generate a wave which represents a temperature signal with an amplitude of 15 degrees during a 24 hour period, how can I do this?

t = 1:24
x = 15.*sin(pi*t)
plot(t,x)

where 15 is the amplitude. This does not generate a sine wave as I expected. I was expecting to see one wave which extends over a 24 hour period with an amplitude of 15, say with the lowest value of 5 and a maximum of 20 (how do I include these in the equation?).


回答1:


Add a constant and adjust frequency:

x = 5 + 15*sin(2*pi*t/24);

In your code the frequency is incorrect, and the sampling period is too large for that frequency: you have aliasing. That's why you don't see a sine wave.




回答2:


This doesn't have to with Matlab really. If you'd like to generate a wave with fixed period of, say, T = 24hours you'll have to calculate the sine-function accordingly.

E.g.

t = 1:24;
y = 15 * sin(2*pi*t / T);


来源:https://stackoverflow.com/questions/19959607/generate-simple-sine-wave-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!