Skip to content

Instantly share code, notes, and snippets.

@daniestevez
Created August 9, 2018 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniestevez/d2b26df02e25f6a7c4a527a887b7704d to your computer and use it in GitHub Desktop.
Save daniestevez/d2b26df02e25f6a7c4a527a887b7704d to your computer and use it in GitHub Desktop.
DSLWP-B waterfall script
#!/usr/bin/env python3
import numpy as np
from scipy.fftpack import fft, fftshift
from scipy.signal import blackman
import matplotlib.pyplot as plt
# Parameters
N = 2**13
averaging = 4
samp_rate = 40000
freq = 2400
span = 1000
hz_per_bin = samp_rate/N
centre_bin = int(np.round(freq/hz_per_bin))
span_bin = int(np.ceil(span/hz_per_bin))
samples = np.fromfile('/tmp/dslwp_photo.c64', dtype=np.complex64)
total_transforms = len(samples)//(N//2) - 1
lines = total_transforms//averaging
window = blackman(N)
waterfall = np.empty((lines, 2*span_bin), dtype=np.float32)
for line in range(lines):
transforms = np.zeros((averaging, 2*span_bin), dtype=np.float32)
for transform in range(averaging):
start = (line * averaging + transform)*N//2
x = samples[start : start+N]
f = fft(x * window)[centre_bin - span_bin : centre_bin + span_bin]
transforms[transform,:] = np.real(f)**2 + np.imag(f)**2
waterfall[line,:] = 10*np.log10(np.average(transforms, axis=0)) - 20*np.log10(N)
plt.imsave('dslwp.png', waterfall[:,::-1].T, vmin = -125, vmax=-95, cmap='viridis', origin='bottom')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment