Skip to content

Instantly share code, notes, and snippets.

@nihalpasham
Created April 14, 2020 09:53
Show Gist options
  • Save nihalpasham/0939457cbe7176f09aad9b7eda214e29 to your computer and use it in GitHub Desktop.
Save nihalpasham/0939457cbe7176f09aad9b7eda214e29 to your computer and use it in GitHub Desktop.
symbol extraction
symbols_real = []
symbols_imag = []
base_freq = 100 # This is in Hertz
symbol_rate = 23.6
num_tones = 16 # This particular MFSK modulation contains 16 tones i.e. (500-100/23.6) =~ 16.95
# But its apparently odd to have an odd number of frequencies
# So, I settled on '16'. Turns out that was right.
tone_zero = int(round(base_freq/symbol_rate)) # the first or lowest tone in the sequence
sample_rate = 48000
nyq_rate = sample_rate / 2.0
order = 9 # This number is after experimentation. like Filter-design always is
cutoff = 560 # same as above.
for index in iter(peaks):
despread_re = np.multiply(us1, re[ index[0] : index[0] + len(us1) ])
despread_im = np.multiply(us1, im[ index[0] : index[0] + len(us1) ])
normal_cutoff = cutoff / nyq_rate
# Get the filter coefficients
b, a = butter(order, normal_cutoff, btype='low', analog=False)
real = filtfilt(b, a, despread_re)
normal_cutoff = cutoff / nyq_rate
# Get the filter coefficients
b, a = butter(order, normal_cutoff, btype='low', analog=False)
imag = filtfilt(b, a, despread_im)
fft_instant_real = np.fft.rfft(real)
real_fft = fft_instant_real[tone_zero : tone_zero + num_tones]
fft_instant_imag = np.fft.rfft(imag)
imag_fft = fft_instant_imag[tone_zero : tone_zero + num_tones]
currsymbol = np.argmax(np.absolute(real_fft))
symbols_real.append(currsymbol)
currsymbol = np.argmax(np.absolute(imag_fft))
symbols_imag.append(currsymbol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment