aboutsummaryrefslogtreecommitdiffstats
path: root/dpd
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-05-13 11:06:57 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-05-13 11:06:57 +0200
commit7e536b0169cd606dac6c2f4241a520e1c68bfa4a (patch)
tree575991ac1ee3333bff35121d0dedee6505f5ed3a /dpd
parenta34f81d00b9a3f247fa6bd2e31d2c95d4ce7c12f (diff)
downloaddabmod-7e536b0169cd606dac6c2f4241a520e1c68bfa4a.tar.gz
dabmod-7e536b0169cd606dac6c2f4241a520e1c68bfa4a.tar.bz2
dabmod-7e536b0169cd606dac6c2f4241a520e1c68bfa4a.zip
DPD: Move power calculation into function
Diffstat (limited to 'dpd')
-rwxr-xr-xdpd/show_spectrum.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/dpd/show_spectrum.py b/dpd/show_spectrum.py
index b9e0180..83ecd8d 100755
--- a/dpd/show_spectrum.py
+++ b/dpd/show_spectrum.py
@@ -98,11 +98,7 @@ def get_samples(port, num_samps_to_request):
return (tx_ts, txframe, rx_ts, rxframe)
-sampling_rate = 8192000
-fft_size = 4096
-freqs = np.fft.fftshift(np.fft.fftfreq(fft_size, d=1./sampling_rate))
-
-def plot_spectrum_once(port, num_samps_to_request):
+def get_spectrum(port, num_samps_to_request):
tx_ts, txframe, rx_ts, rxframe = get_samples(port, num_samps_to_request)
print("Received {} & {} frames at {} and {}".format(
@@ -114,7 +110,15 @@ def plot_spectrum_once(port, num_samps_to_request):
rx_spectrum = np.fft.fftshift(np.fft.fft(rxframe, fft_size))
rx_power = 20*np.log10(np.abs(rx_spectrum))
+ return tx_power, rx_power
+
+
+sampling_rate = 8192000
+fft_size = 4096
+freqs = np.fft.fftshift(np.fft.fftfreq(fft_size, d=1./sampling_rate))
+def plot_spectrum_once(port, num_samps_to_request):
+ tx_power, rx_power = get_spectrum(port, num_samps_to_request)
fig = pp.figure()
fig.suptitle("TX and RX spectrum")
@@ -138,17 +142,7 @@ def plot_spectrum_animated(port, num_samps_to_request):
axes[1].set_ylim(-60, 40)
def update(frame):
- tx_ts, txframe, rx_ts, rxframe = get_samples(port, num_samps_to_request)
-
- print("Received {} & {} frames at {} and {}".format(
- len(txframe), len(rxframe), tx_ts, rx_ts))
-
- print("Calculate TX and RX spectrum assuming 8192000 samples per second")
- tx_spectrum = np.fft.fftshift(np.fft.fft(txframe, fft_size))
- tx_power = 20*np.log10(np.abs(tx_spectrum))
-
- rx_spectrum = np.fft.fftshift(np.fft.fft(rxframe, fft_size))
- rx_power = 20*np.log10(np.abs(rx_spectrum))
+ tx_power, rx_power = get_spectrum(port, num_samps_to_request)
lines[0].set_ydata(tx_power)
lines[1].set_ydata(rx_power)