Add delay effect to signal in python

539 Views Asked by At

I need to add a delay effect to a signal and plot it over the original signal. I have to do it with only scipy, matplotlib and numpy libraries. Specifically using scipy.ndimage.interpolation.shift()

This is my code so far:

def delaySignal (array, delay ,sl) :
    #array = array that is gonna get shifted 
    #delay = time in ms for how long it shifts
    #sl = sample length = used to determine how many cells to shift
    time_delay_s = delay/1000
    time_value_of_cell = delay/sl
    shift = int(time_delay_s/time_value_of_cell)
    y = scipy.ndimage.interpolation.shift(array,shift)
    y = y / np.sum(y);
    return y

y_sl_d, sr_sl_d = lb.load('simpleLoop.wav')

delay= delaySignal(y_sl_d,100, sr_sl_d)


y_delayed = np.convolve(y_sl_d,delay, mode = "same")
#plot the results
plt.figure()
plt.plot(y_sl_d)       # Plot the unedited signal
plt.plot(y_delayed) # Plot the edited signal over it

However, I get completely shifted signal. Can anyone explain why this happens and suggest some ideas on how to fix it?

I have tried changing the array that goes into the delaySignal into an array np.linspace(-sl / 2, sl / 2, sl) where sl is signal length but it produced nonsense.

0

There are 0 best solutions below