# Why do I need this modulo tweak to bandpass filter an I/Q signal

I have an I/Q signal with $$f_c=2.06\text{MHz}$$ and $$f_s=50\text{KHz}$$. I am looking the first 256 samples of the signal, which is a NumPY array of complex numbers. If I do a spectrogram of this signal I get this picture:

specgram(sig,Fs=fs); Notice that the Y-axis range of the spectrogram is $$-25000$$ to $$+25000$$.

If I do an FFT of the 256-sample signal, I will get 256 numbers, like this:

U=fft.fft(sig)
plot(U) Notice that the $$y$$-axis range is now $$-250$$ to $$250$$. I want to be able to tightly bandpass this signal at any level in this range. I write the following naive bandpass function. In writing it I discover that I have to do a little tweaking to get a continuous response:

def bandpass(M,lo,hi):
N=M.shape
lo = (lo+N//2) % N
hi = (hi+N//2) % N
F=copy(M)
F[lo:hi]=0
return M-F


The tweaking I had to do is in these lines:

    lo = (lo+N//2) % N
hi = (hi+N//2) % N


As a result of this tweaking, I get the linear response I am looking for, which is I want to be able to knock out any bin in the frequency range linearly index from 0 to 255:

specgram(fft.ifft(bandpass(fft.fft(sig),50,52)),Fs=fs); and

specgram(fft.ifft(bandpass(fft.fft(sig),180,182)),Fs=fs); Why do I have to do the modulo tweak to get the linear response I was looking for?