Skip to content

Instantly share code, notes, and snippets.

@gowrishankarin
Created May 17, 2014 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowrishankarin/7c7e1ff6579b0c6a7120 to your computer and use it in GitHub Desktop.
Save gowrishankarin/7c7e1ff6579b0c6a7120 to your computer and use it in GitHub Desktop.
Karplus Strong Algorithm, y[n] = ay[n-M] + x[n]
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
@gowrishankarin
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment