diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-05-12 15:01:08 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-05-12 15:01:08 +0200 |
commit | f69b4a1da493c73192aa0c86749bd6bcf396422d (patch) | |
tree | 3640f5f1dd1c239481bfabbb7b8e94701d306d27 | |
parent | 403ce1709cd8204769f43a2e6cc68c0286d0fb25 (diff) | |
download | dabmod-f69b4a1da493c73192aa0c86749bd6bcf396422d.tar.gz dabmod-f69b4a1da493c73192aa0c86749bd6bcf396422d.tar.bz2 dabmod-f69b4a1da493c73192aa0c86749bd6bcf396422d.zip |
Actually plot a spectrum in show_spectrum.py
-rwxr-xr-x | dpd/show_spectrum.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/dpd/show_spectrum.py b/dpd/show_spectrum.py index 477cd99..fcc682f 100755 --- a/dpd/show_spectrum.py +++ b/dpd/show_spectrum.py @@ -18,7 +18,7 @@ import sys import socket import struct import numpy as np -import matplotlib as mp +import matplotlib.pyplot as pp import scipy.signal SIZEOF_SAMPLE = 8 # complex floats @@ -90,6 +90,27 @@ 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") +fft_size = 4096 +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)) + +sampling_rate = 8192000 +freqs = np.fft.fftshift(np.fft.fftfreq(fft_size, d=1./sampling_rate)) + +fig = pp.figure() + +fig.suptitle("TX and RX spectrum") +ax1 = fig.add_subplot(211) +ax1.set_title("TX") +ax1.plot(freqs, tx_power) +ax2 = fig.add_subplot(212) +ax2.set_title("RX") +ax2.plot(freqs, rx_power) +pp.show() # The MIT License (MIT) # |