/
FM_display.py
78 lines (54 loc) · 1.21 KB
/
FM_display.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import threading
import queue
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.lines as line
import numpy as np
from scipy import fftpack
from scipy import signal
from rtlsdr import *
import time
cos = np.cos
sin = np.sin
lg = np.log10
plot = plt.plot
fft = fftpack.fft
pi = np.pi
N = 4*1024
data = np.arange(0,N,1)
# plot the spectra
fig = plt.figure()
ax = plt.axes(xlim=(0,N),ylim=(-60,0))#
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.arange(len(data))
X = data
line.set_data(x, X)
return line,
anim = animation.FuncAnimation(fig, animate, frames=1, interval=100, blit=False)
Q = queue.Queue()
sdr = RtlSdr()
window = signal.hamming(N)
def data_processing():
global Q
global data
global window
while 1:
origin_data = Q.get()
while not Q.empty():
Q.get()
window_data = origin_data
ob_data = abs(fftpack.fft(window_data))
#sdata=fftpack.fftshift(fftpack.fft(ob_data,overwrite_x=True))
data = 20*lg(ob_data/N)
t1 = threading.Thread(target = data_processing)
t2 = threading.Thread(target = rtlsdr_main)
t1.start()
t2.start()
plt.show()
sdr.cancel_read_async()
sdr.close()
print('ended')