问题
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