# Walking through a spectrum a little at a time

I am capturing samples with an RTL-SDR:

import numpy as np
from rtlsdr import RtlSdr

sdr = RtlSdr()
F_station = int(88.7e6)
Fc = F_station - F_offset
Fs = 2.4e6
N = Fs
sdr.sample_rate = Fs
sdr.center_freq = Fc
sdr.gain = 'auto'

x1 = np.array(samples).astype("complex64")


I would like to walk through this spectrum 5kHz at a time. I am attempting to "tune" to each frequency:

width = 5000
targetFreq = Fc - Fs/2 + width/2
while targetFreq < Fc + Fs/2:
Foffset = targetFreq + Fc
fc1 = np.exp(-1.0j*2.0*np.pi* Foffset/Fs*np.arange(len(x1)))  # center on target freq
x2 = x1 * fc1


Then I decimate to reduce the bandwidth to the width I want to process, stepping over the whole bandwidth in 'width' increments. My decimate function uses scipy.signal's decimate function, often several times (to get down to the right width):

    x3 = decimate(x2, width, Fs)


I process the x3s and put them together. The output has some sanity to it, but is not correct. Is the method I'm using to step through the larger bandwidth (multiply by a complex exponential with phase -F_offset/Fs and decimate to "narrow the bandwidth") the wrong approach?

• Does decimate filter before discarding samples? – AnonSubmitter85 Mar 22 '18 at 2:28
• @AnonSubmitter85 - scipy.signal's decimate "Downsample[s] the signal after applying an anti-aliasing filter." – HH- Apologize to Carole Baskin Mar 22 '18 at 3:13
• Nothing jumps out as wrong with your approach. Have you tried it on a noise-free sinusoid centered in one of your "widths"? – AnonSubmitter85 Mar 22 '18 at 3:32
• @AnonSubmitter85 - Is there any place online that describes this approach that you'd link to? – HH- Apologize to Carole Baskin Mar 22 '18 at 3:33
• I am talking about just assigning x1 to be something like $e^{j2\pi f_0 t}$ for some $f_0$ that is centered in one of the "widths". This way you know what the output should be and can compare it against what you are getting. – AnonSubmitter85 Mar 22 '18 at 3:49