如何模拟由给定信号驱动的谐振子(不是由正弦波驱动)
我有一个值表,告诉我信号电平如何随时间变化,我想模拟由该信号驱动的谐振子。即使模拟不是 100% 准确也没关系。 我知道振荡器的频率。 我找到了很多公式,但它们都使用正弦波作为驱动器。
I've got a table of values telling me how the signal level changes over time and I want to simulate a harmonic oscillator driven by this signal. It does not matter if the simulation is not 100% accurate.
I know the frequency of the oscillator.
I found lots of formulas but they all use a sine wave as driver.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你想执行一些时间离散模拟。众所周知的公式需要分析输入(参见格林函数)。如果您有某个时间点的力表,典型的分析公式不会对您有太大帮助。
这个想法是这样的:对于时间 t0 的每个点,振荡器都有一些给定的加速度、速度等。现在一个力作用在它上 - 根据给定的表格 - 这将改变它的加速度 (F = m * a) 。对于下一个时间步 t1,我们假设加速度保持在该常数,因此我们可以应用简单的牛顿方程< /a> (v = a * dt) 且该时间范围内 dt = (t1-t0)。迭代直到模拟出所需的时间范围。
这个模拟最重要的参数是dt,即计算的细粒度程度。例如,您可能希望每秒 10 步,但这完全取决于您的输入参数。本质上,我们在这里所做的是方程的欧拉积分。
当然,这并不是全部 - 这种模拟可能非常复杂,尤其是。在表现不佳的情况下,例如极端加速等。在这些情况下,您需要在一帧内执行数值健全性检查,因为在单个帧中会发生“极端”的情况。此外,一些数值积分可能变得必要,例如 Runge-Kutta 算法 。然而,我想这在这一点上已经很遥远了。
编辑:就在我发布此内容后,有人对原始问题发表了评论,指出“
I guess you want to perform some time-discrete simulation. The well-known formulae require analytic input (see Green's function). If you have a table of forces at some point in time, the typical analytical formulae won't help you too much.
The idea is this: For each point in time t0, the oscillator has some given acceleration, velocity, etc. Now a force acts on it -according to the table you were given- which will change it's acceleration (F = m * a). For the next time step t1, we assume the acceleration stays at that constant, so we can apply simple Newtonian equations (v = a * dt) with dt = (t1-t0) for this time frame. Iterate until the desired range in time is simulated.
The most important parameter of this simulation is dt, that is, how fine-grained the calculation is. For example, you might want to have 10 steps per second, but that completely depends on your input parameters. What we're doing here, in essence, is an Eulerian integration of the equations.
This, of course, isn't all there is - such simulations can be quite complicated, esp. in not-so-well behaved cases where extreme accelerations, etc. In those cases you need to perform numerical sanity checks within a frame, because something 'extreme' happens in a single frame. Also some numerical integration might become necessary, e.g. the Runge-Kutta algorithm. I guess that leads to far at this point, however.
EDIT: Just after I posted this, somebody posted a comment to the original question pointing to the "Verlet Algorithm", which is basically an implementation of what I described above.
http://en.wikipedia.org/wiki/Simple_harmonic_motion
http://en.wikipedia.org/wiki/Hooke's_Law
http://en.wikipedia.org/wiki/Euler_method
http://en.wikipedia.org/wiki/Simple_harmonic_motion
http://en.wikipedia.org/wiki/Hooke's_Law
http://en.wikipedia.org/wiki/Euler_method
好吧,我终于弄清楚了,并编写了一个 GUI 应用程序来测试它,直到它起作用。但我的电脑对每秒执行 1000*44100 次不太满意,即使没有 gui^^
无论如何:这是我的测试代码(效果很好):
Ok, i finally figured it out and wrote a gui app to test it until it worked. But my pc is not very happy with doing it 1000*44100 times per second, even without gui^^
Whatever: here is my test code (wich worked quite well):