互相添加谐波ipython

时间:2015-04-02 17:27:18

标签: python ipython

我希望听到的下一个声音是同时播放的所有谐波的组合,但我无法让它工作。仍然是ipython的新手,所以还在学习如何使用它。

t = arange(0, 0.5, 1/44100)
fundamental = 440
mySound = sin(2*pi*t*100)
for k in range(1,6) :
    print "Adding harmonic: ", k 
    mySound = concatenate([mySound,  (mySound+(sin(2*pi*((2*k)-1)*t*100)/((2*k)-1)))/k])
play(mySound)
plot(mySound[1:1000]) # plot first 1000 samples

1 个答案:

答案 0 :(得分:1)

您需要使用添加,而不是连接。就是这样:

for k in range(1,6) :
    print "Adding harmonic: ", k 
    mySound += sin(2*pi*((2*k)-1)*t*100)/((2*k)-1)))/k
    # or mySound = mySound + sin(2*pi*((2*k)-1)*t*100)/((2*k)-1)))/k  # is close to the same thing (though less efficient) and more similar to what you had

连接将波形端对端,所以你会依次听到它们。