Created
May 17, 2014 17:52
-
-
Save gowrishankarin/7c7e1ff6579b0c6a7120 to your computer and use it in GitHub Desktop.
Karplus Strong Algorithm, y[n] = ay[n-M] + x[n]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KarplusStrong: | |
def ks_loop(self, x, alpha, D): | |
import numpy as np | |
if D < 1: | |
print('Duration D must be greater than 1') | |
if x.ndim != 1: | |
print('The array entered is of the wrong size') | |
return None | |
M = len(x) | |
size_y = D*M | |
y = np.zeros((size_y, 1)) | |
for i in range(M): | |
y[i] = x[i] | |
for index in range(M+1, size_y): | |
y[index] = float(alpha*y[index - M]) | |
return y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Karplus Strong Algorithm, y[n] = ay[n-M] + x[n]#
x[n] --> Input Signal
M --> Delay
a --> a is the alpha, decay component.
Python CLI Commands
import numpy as np
x = np.random.randn(100)
from KarplusStrong import KarplusStrong
ks = KarplusStrong()
y = ks.ks_loop(x, 0.9, 10)
stem(np.arange(x.size),x,)
xlabel('Samples')
ylabel('x')
show
size(y)