Skip to content

Instantly share code, notes, and snippets.

View nihalpasham's full-sized avatar
🐢
regionaltantrums!

nihalpasham

🐢
regionaltantrums!
View GitHub Profile
@nihalpasham
nihalpasham / dtb_node_and_property_constructor.rs
Last active March 10, 2022 07:29
Snippet to create flattened dtb nodes and properties
#[derive(Debug)]
#[repr(C)]
/// Constructs a device-tree `node`, given a name and buffer. The buffer must be adequately sized.
pub struct RawNodeConstructor<'a> {
fdt_begin_node: u32,
node_name: &'a [u8],
}
impl<'a> RawNodeConstructor<'a> {
pub fn make_raw_node(buf: &'a mut [u8], name: &'a str) -> Result<Self> {
@nihalpasham
nihalpasham / token_generation.py
Created April 14, 2020 12:09
token generation
real_tokens = []
imag_tokens = []
for i in range(0, len(symbols_real)):
if symbols_real[i] == 15:
token = symbols_real[i:i+9]
checksum = np.sum(token) % 16
if checksum <= 4 or checksum >= 13 :
q = (''.join([format(symbol, 'x') for symbol in token[1:7]]))
# print(q)
@nihalpasham
nihalpasham / symbol_decoding.py
Created April 14, 2020 10:59
symbol decoding
tokens_real = []
tokens_imag = []
for i in range(0, len(symbols_real)-1):
if symbols_real[i] == 15:
token = symbols_real[i:i+8]
tokens_real.append(token)
for i in range(0, len(symbols_imag)-1):
if symbols_imag[i] == 15:
@nihalpasham
nihalpasham / symbol_extraction.py
Created April 14, 2020 09:53
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
@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
@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 / 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 / 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 / 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 / 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)