Skip to content

Commit

Permalink
Fix sdft latency calculus #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Jun 14, 2022
1 parent b8e36ce commit 7ef5ba0
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions python/stftpitchshift/sdft.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ def sdft(samples, dftsize):

deltas = samples - delayline

dfts = deltas[:, None] * twiddles[:-1]
data = deltas[:, None] * twiddles[:-1]

for i in range(1, N):

dfts[i] += dfts[i - 1]
data[i] += data[i - 1]

dfts *= np.conj(twiddles[1:])
dfts = window(dfts)
data *= np.conj(twiddles[1:])

dfts = window(data)

return dfts

Expand All @@ -46,17 +47,13 @@ def isdft(dfts, latency=1):

N, M = dfts.shape

if latency == 1:

twiddles = np.array([-1 if m % 2 else +1 for m in range(M)])

else:

weight = 2 / (1 - np.cos(np.pi * latency))
twiddles = np.array([-1 if m % 2 else +1 for m in range(M)]) \
if latency == 1 else \
np.exp(-1j * np.pi * latency * np.arange(M))

twiddles = weight * np.exp(1j * np.pi * latency * np.arange(M))
weight = 2 / (1 - np.cos(np.pi * latency))

samples = np.sum(np.real(dfts * twiddles), axis=-1)
samples = np.sum(np.real(dfts * twiddles * weight), axis=-1)

return samples

Expand Down Expand Up @@ -87,12 +84,13 @@ def isdft(dfts, latency=1):

roi = (np.min(t), np.max(t), 0, sr / (dftsize * 2))

# plot.figure()
# plot.plot(t, x, alpha=0.5)
# plot.plot(t, samples, alpha=0.5)

plot.figure()
plot.imshow(db.T, extent=roi, cmap='inferno', aspect='auto', interpolation='nearest', origin='lower')
plot.clim(-120, 0)

plot.figure()
plot.plot(t, x, alpha=0.5)
plot.plot(t, samples, alpha=0.5)
plot.xlim(0, 0.1)

plot.show()

0 comments on commit 7ef5ba0

Please sign in to comment.