正弦波滑音从一个音调到另一个numpy的 [英] sine wave glissando from one pitch to another in Numpy

查看:223
本文介绍了正弦波滑音从一个音调到另一个numpy的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在一个程序,我需要慢慢平稳的正弦波的间距从一个音高变化到另一个。我能够获得频率的阵列间距应在任何特定时刻(例如,[440,526.5,634.2 794.8 880],虽然不多,更长),但似乎我无法实际应用的频率以一浪。我最好的尝试是:

I have been working on a program where I need to slowly and smoothly change the pitch of a sine wave from one pitch to another. I am able to get an array of the frequency the pitch should be at any given moment (for instance, [440, 526.5, 634.2 794.8, 880], though much, much longer) but it seems I am unable to actually apply that frequency to a wave. My best attempt is:

numpy.sin(2*math.pi*x*freq/self.sample_rate)

其中,频率是频率的阵列和x是枚举阵列([0,1,2,3,4 ...])。这种方法的作品的排序,但是它使频率去预期频率以上,然后回落。我一直在这个问题上很长一段时间,一直未能在找到一个更合适的方法取得任何进展。任何建议?是我不够清楚的前pressing我的困境?

where "freq" is the array of frequencies and x is an enumeration array ([0,1, 2, 3, 4...]). This method sort of works, however it makes the frequency go above the expected frequency, and then back down. I have been working on this problem for a very long time and have been unable to make any progress on finding a more appropriate method. Any advice? Was I clear enough in expressing my dilemma?

感谢您。

推荐答案

的问题是,当你通过坡道频率,每个频率有效地对给定的时间不同的阶段。当通过这些阶段快速而连续滚动,它们驱动在较高频率的正弦波(或更低也是可能的)。

The issue is that as you ramp through the frequencies, each frequency effectively has a different phase for the given time. When you scroll through these phases quickly and continuously, they drive the sine wave at higher frequency (or lower is also possible).

想象一下,例如,你瞬间变化的频率 - 要做到这一点你必须提供相位校正 P_1 = p_0 + 2 * PI * T *(F_0,F_1)来使阶段在时间 T 。当你这样做是小步骤,你也必须作出类似的相位校正,每个相位校正增加了previous。

Imagine, for example, that you changed the frequency instantaneously -- to do this you'd have to supply the phase correction p_1 = p_0 + 2*pi*t*(f_0-f_1) to make the phases match up at time t. As you do this is little steps, you also have to make a similar phase correction, with each phase correction adding to the previous.

下面是生成的数字,与下面的code。顶部图是中间无相位校正的频率,和底部具有连续校正的相位

Here's the resulting figure, with the code below. The top figure is the frequency the middle is without the phase correction, and the bottom has the continuously corrected phase.

from pylab import *

sample_rate = .001
f0, f1 = 10, 20
t_change = 2

times = arange(0, 4, sample_rate)

ramp = 1./(1+exp(-6.*(times-t_change)))
freq = f0*(1-ramp)+f1*ramp
phase_correction = add.accumulate(times*concatenate((zeros(1), 2*pi*(freq[:-1]-freq[1:]))))

figure()
subplot(311)
plot(times, freq)
subplot(312)
plot(times, sin(2*pi*freq*times))
subplot(313)
plot(times, sin(2*pi*freq*times+phase_correction))

show()

这篇关于正弦波滑音从一个音调到另一个numpy的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆