相关文章推荐
狂野的麦片  ·  Android ...·  6 月前    · 
爱搭讪的长颈鹿  ·  414 URI Too Long - ...·  12 月前    · 
小眼睛的课本  ·  Perform an in-place ...·  1 年前    · 
class fmDemodulator(object): def __init__(self, sdr=None): self.sdr = sdr if sdr else RtlSdr(device_index) def demod(self, *args): Fs = self.sdr.sample_rate # Read IQ samples samples = self.sdr.read_samples(256*1024) print(samples) # Convert sampled data into numpy array x1 = np.array(samples).astype("complex64") # Downmixed Baseband Signal (Adjust offset to be centered) offsetFreq = 0 # already centered fc1 = np.exp(-1.0j*2.0*np.pi* offsetFreq/Fs*np.arange(len(x1))) x2 = x1 * fc1 # Filter and downsample the FM Radio Signal bwFM = 200000 # approx. 170 kHz for a single channel decRate = int(Fs/bwFM) x3 = signal.decimate(x2, decRate) newFs = Fs/decRate ### Demodulate 200kHz FM Signal # Polar discriminator y4 = x3[1:] * np.conj(x3[:-1]) x4 = np.angle(y4) # The de-emphasis filter # Given a signal 'x4' (in a numpy array) with sampling rate newFS d = newFs * 75e-6 # Calculate the # of samples to hit the -3dB point x = np.exp(-1/d) # Calculate the decay between each sample b = [1-x] # Create the filter coefficients a = [1,-x] x5 = signal.lfilter(b,a,x4) # Find a decimation rate to achieve audio sampling rate between 44-48 kHz audioFreq = 44100.0 dec_audio = int(newFs/audioFreq) audioFs = newFs/dec_audio print(audioFreq) x6 = signal.decimate(x5, dec_audio) # Scale audio to adjust volume x6 *= 10000 / np.max(np.abs(x6)) return x6, audioFs def start(self): while True: x6, audioFs = self.demod() sd.play(x6, audioFs) return def main(): sdr = RtlSdr(device_index) fm = fmDemodulator(sdr) # SDR Configurations sdr.sample_rate = int(2.4e6) # Hz sdr.center_freq = int(102e6) # Hz sdr.freq_correction = 77 # PPM +- 20 sdr.gain = 'auto' fm.start() # Clean up sdr.close() del(sdr) if __name__ == '__main__': main() 提前谢谢!