Skip to content

Instantly share code, notes, and snippets.

View nihalpasham's full-sized avatar
🐢
regionaltantrums!

nihalpasham

🐢
regionaltantrums!
View GitHub Profile
@nihalpasham
nihalpasham / example_glfsr.py
Last active April 5, 2020 07:50
Google pay's -DSSS code sequence
code = [0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1,
0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0,
1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1,
1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1]
degree = 7
# print(u)
@nihalpasham
nihalpasham / dsss_sequence_plot.py
Last active April 13, 2020 03:20
Plotting a DSSS binary code sequence
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import step, xlim, ylim, show
a = np.array([-1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1])
b = np.tile(a, 1)
x = np.arange(0, 127)
fig, (ax1) = plt.subplots(1, figsize=(15,4))
@nihalpasham
nihalpasham / compare_seq_vs_sig.py
Last active April 12, 2020 04:39
DSSS Code Sequence vs Sinc interpolated Code Signal
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import step, xlim, ylim, show
k = 16
a = np.array([-1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1])
# code-sequence
b = np.tile(a, 1)
x = np.arange(0, 127)
@nihalpasham
nihalpasham / dsss_code_sync.py
Last active April 12, 2020 03:44
DSSS code synchronization
number_of_code_samples = len(us1)
print(len(us1))
correlation_magnitude_buffer = []
squared_correlation_magnitude_buffer = []
# so that we dont overshoot when sliding the code signal forward
range_ = (int(number_of_complex_samples/number_of_code_samples)-1)*number_of_code_samples
@nihalpasham
nihalpasham / load_wav_file.py
Last active April 14, 2020 04:07
Extracting the baseband signal and loading it into python
import numpy as np
import os
from scipy.io import wavfile
import matplotlib.pyplot as plt
file_path = "/Users/Nil/devspace/Github_repos/alltheFSKs/iPhone_MFSK_Gpay_samples/iPhone_stereo_r_48khz_raw_c4755658_frequency_translated_lowpass_filtered.wav"
fs, data = wavfile.read(file_path)
# print(fs)
@nihalpasham
nihalpasham / first_correl_peak.py
Last active April 14, 2020 03:45
Finding the first correlation peak
h3 = sorted((v,i) for (v,i) in enumerate(squared_correlation_magnitude_buffer) if (i > 125) and ( v < 4000))
h4 = max([i for v,i in h3])
print(h3)
print(h4)
@nihalpasham
nihalpasham / code_tracking.py
Last active April 14, 2020 03:48
code_tracking
i = 3844
peaks = []
while True:
v = max(normalized_correlation_magnitude_buffer[i-200 : i+200])
s, = np.where(np.isclose(normalized_correlation_magnitude_buffer, v, rtol = 1e-09))
@nihalpasham
nihalpasham / visual_comparison_timedomain.py
Last active April 12, 2020 04:22
DSSS - Visual comparison of spread Vs de-spread signals
x = np.linspace(0, 42.33, 2032)
y = np.sin(2 * np.pi * ((4+0)/42.33) * x)
print(len(x))
print(len(y))
z = np.multiply(y, us1)
mot = np.multiply(z, us1)
@nihalpasham
nihalpasham / fft_plot_dsss_example_signals.py
Last active April 12, 2020 04:24
DSSS - FFT plot of spread Vs despread signals
f = signal.resample(mot, 512)
N = 512
# sample spacing
T = 1.0 / 12000.0
yf = fft(f)
xf = fftfreq(N, T)
xf = fftshift(xf)
yplot = fftshift(yf)
@nihalpasham
nihalpasham / despread_and_visualize.py
Last active April 14, 2020 04:02
Despreading the signal and visualising data via a Fourier transform
from scipy.fftpack import fft, fftfreq, fftshift
from scipy import signal
from scipy.signal import butter,filtfilt
k = 38389 # one of the peaks chosen randomly
sample_rate = 48000
nyq_rate = sample_rate / 2.0
order = 9