init various python test scripts

This commit is contained in:
Obie Hinojosa 2024-11-10 17:57:15 -06:00
parent b7cc09b8a9
commit 81453dcace
4 changed files with 77 additions and 0 deletions

BIN
capture.bin Normal file

Binary file not shown.

35
main.py Normal file
View File

@ -0,0 +1,35 @@
import numpy as np
import matplotlib.pyplot as plt
Fs = 1 # Hz
N = 100 # number of points to simulate, and our FFT size
t = np.arange(N) # because our sample rate is 1 Hz
s = np.sin(0.15*2*np.pi*t)
#s = s * np.hamming(100)
S = np.fft.fftshift(np.fft.fft(s))
S_mag = np.abs(S)
S_phase = np.angle(S)
f = np.arange(Fs/-2, Fs/2, Fs/N)
#plt.figure(0)
#plt.plot(f, S_mag,'.-')
#plt.figure(1)
#plt.plot(f, S_phase,'.-')
#plt.show()
# simulate the signal above, or use your own signal
x = 20
fft_size = 1024
sample_rate = 512
num_rows = len(s) // fft_size # // is an integer division which rounds down
spectrogram = np.zeros((num_rows, fft_size))
for i in range(num_rows):
spectrogram[i,:] = 10*np.log10(np.abs(np.fft.fftshift(np.fft.fft(x[i*fft_size:(i+1)*fft_size])))**2)
plt.imshow(spectrogram, aspect='auto', extent = [sample_rate/-2/1e6, sample_rate/2/1e6, len(s)/sample_rate, 0])
plt.xlabel("Frequency [MHz]")
plt.ylabel("Time [s]")
plt.show()

20
rtl.py Normal file
View File

@ -0,0 +1,20 @@
from rtlsdr import RtlSdr
import numpy as np
import matplotlib.pyplot as plt
sdr = RtlSdr()
sdr.sample_rate = 2.048e6 # Hz
sdr.center_freq = 100e6 # Hz
sdr.freq_correction = 60 # PPM
print(sdr.valid_gains_db)
sdr.gain = 49.6
print(sdr.gain)
x = sdr.read_samples(4096)
sdr.close()
plt.plot(x.real)
plt.plot(x.imag)
plt.legend(["I", "Q"])
plt.savefig("../_images/rtlsdr-gain.svg", bbox_inches='tight')
plt.show()

22
sec.py Normal file
View File

@ -0,0 +1,22 @@
import numpy as np
import matplotlib.pyplot as plt
sample_rate = 1e6
# Generate tone plus noise
t = np.arange(1024*1000)/sample_rate # time vector
f = 50e3 # freq of tone
x = np.sin(2*np.pi*f*t)
# simulate the signal above, or use your own signal
fft_size = 1024
num_rows = len(x) // fft_size # // is an integer division which rounds down
spectrogram = np.zeros((num_rows, fft_size))
for i in range(num_rows):
spectrogram[i,:] = 10*np.log10(np.abs(np.fft.fftshift(np.fft.fft(x[i*fft_size:(i+1)*fft_size])))**2)
plt.imshow(spectrogram, aspect='auto', extent = [sample_rate/-2/1e6, sample_rate/2/1e6, len(x)/sample_rate, 0])
plt.xlabel("Frequency [MHz]")
plt.ylabel("Time [s]")
plt.show()