Skip to content

Instantly share code, notes, and snippets.

@jboone
Created January 15, 2016 18:09
Show Gist options
  • Save jboone/04fe26bc5bb1f0c262b5 to your computer and use it in GitHub Desktop.
Save jboone/04fe26bc5bb1f0c262b5 to your computer and use it in GitHub Desktop.
Downconverting band-limited real-valued signal is a mess I don't have time to clean up. :-)
#!/usr/bin/env python
import numpy
import scipy.fftpack
import matplotlib.pyplot as plt
def plot_time_domain_of(items):
for t, samples, label in items:
plt.plot(t, samples, label=label)
plt.legend()
plt.show()
def plot_spectrum_of(items):
for t, samples, label in items:
f = scipy.fftpack.fft(samples) / len(samples)
f_mag = numpy.absolute(f)
f_db = numpy.log10(f_mag) * 20
plt.plot(f_db, label=label)
plt.legend()
plt.show()
sampling_rate = 137.5e6
intermediate_frequency = 35e6
target_center_frequency = 20e6
frequency_shift = target_center_frequency - intermediate_frequency
sample_count = 200
test_signal_frequency = 20e6
n = numpy.arange(0, sample_count, dtype=numpy.float64)
t = n / sampling_rate
w = t * 2 * numpy.pi
signal = numpy.cos(w * test_signal_frequency)
sinusoid = numpy.cos(w * frequency_shift)
output = signal * sinusoid
signals = (
(t, signal, 'signal'),
(t, sinusoid, 'mix'),
(t, output, 'out'),
)
plot_time_domain_of(signals)
plot_spectrum_of(signals)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment