I've been working from this reference document, essentially trying to recreate Figure 7 with the understanding that the two functions place_signal and signal_shift were able to undo one another. enter image description here

import numpy as np
import matplotlib.pyplot as plt

def place_signal(size,location,signal,sinc_length=100):

    bin = int(np.floor(location))
    delta = location - bin

    x = np.zeros(size,dtype=np.complex128)
    for idx in range(-sinc_length,sinc_length):
        # skip indexes that are invalid
        if bin+idx<0 or bin+idx>=size:

        temp = np.pi*(idx+delta)
        x[bin+idx]+= signal*np.sin(temp)/temp

    return x
def signal_shift(original, shift):
    orig_fft = np.fft.fft(original)
    phases = np.linspace(-np.pi, np.pi, len(original)) * shift
    shift = np.exp(complex(0, 1) * phases)
    result_fft = orig_fft * shift
    return np.fft.ifft(result_fft)

size = 128
location = 64.5
signal = complex(1,0)
offset = location - np.floor(location)

x0 = place_signal(size,location,signal)
x1 = np.zeros(size,dtype=np.complex128)
x1[int(size/2)] += signal

y0 = signal_shift(x0,offset)
y1 = signal_shift(x1,offset)
y2 = signal_shift(y1,offset)

plt.plot(np.real(x0),label="Place Signal")
plt.plot(np.real(y1),label="Sample Shift")

plt.plot(np.real(y0),label="Place Signal shifted back")
plt.plot(np.real(y2),label="Signal shift shifted back")

The first plot shows how a signal can be placed/shifted by half a sample using both functions. enter image description here

The second plot shows how the signal_shift is used on both signals to shift them by 0.5 samples. enter image description here

The signal moved with signal_shift is back in its original position (albeit with a negative sign), but the signal generated by place_signal does not compress the same way, and I don't understand why.

Any help would be very appreciated. Thank you.

  • $\begingroup$ Hi Michael. I'm reading this really quickly without time at the moment to go through your code, but since there's no activity I'll comment in case it's helpful that my first thought is for you to zero pad your FFT's (which then approach the continuous frequency IDFT) where you might find more insight as the samples given are on the same IDFT. What you see here is the subsampled IDFT $\endgroup$ Commented Mar 30 at 23:02

1 Answer 1


I actually found this post, which shows that I had missed an fftshift of the phases vector in my signal_shift function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.