2015-04-02 92 views
0

我希望聽到的下一個聲音是所有以前同時播放的諧波的組合,但我無法讓它工作。仍然是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

請添加您的導入並適當標記您的問題。 – cel 2015-04-02 17:32:29

回答

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 

級聯會把波形終端到終端的,所以你會聽到他們一個接一個,按順序排列。