diff --git a/capture.bin b/capture.bin new file mode 100644 index 0000000..4c57689 Binary files /dev/null and b/capture.bin differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..0a2db39 --- /dev/null +++ b/main.py @@ -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() diff --git a/rtl.py b/rtl.py new file mode 100644 index 0000000..60b266e --- /dev/null +++ b/rtl.py @@ -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() \ No newline at end of file diff --git a/sec.py b/sec.py new file mode 100644 index 0000000..106e605 --- /dev/null +++ b/sec.py @@ -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() \ No newline at end of file