diff options
author | andreas128 <Andreas> | 2017-04-02 10:46:49 +0100 |
---|---|---|
committer | andreas128 <Andreas> | 2017-04-02 10:46:49 +0100 |
commit | 2aa99f6275e2530a8dd4d3be270e9d7a3633cd66 (patch) | |
tree | 9bb6c05b6e17e3c00c4d68660cb47f846c4d66ba /src | |
parent | 3ee39e3ae187e76b252b5758c12bd35e5707e187 (diff) | |
download | ODR-StaticPrecorrection-2aa99f6275e2530a8dd4d3be270e9d7a3633cd66.tar.gz ODR-StaticPrecorrection-2aa99f6275e2530a8dd4d3be270e9d7a3633cd66.tar.bz2 ODR-StaticPrecorrection-2aa99f6275e2530a8dd4d3be270e9d7a3633cd66.zip |
Add two tone and mer measure
Diffstat (limited to 'src')
-rw-r--r-- | src/ReceiveDictTcp.py | 10 | ||||
-rw-r--r-- | src/dab_tuning_lib.py | 67 | ||||
-rw-r--r-- | src/dab_util.py | 10 | ||||
-rw-r--r-- | src/tcp_sync.py | 13 |
4 files changed, 89 insertions, 11 deletions
diff --git a/src/ReceiveDictTcp.py b/src/ReceiveDictTcp.py index 3feec31..784afb6 100644 --- a/src/ReceiveDictTcp.py +++ b/src/ReceiveDictTcp.py @@ -5,9 +5,10 @@ from Queue import Queue import sys class ReceiveDictTcp(object): - def __init__(self, host, port): + def __init__(self, host, port, verbose=False): self.host = host self.port = port + self.verbose = verbose self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind((self.host, self.port)) @@ -21,17 +22,18 @@ class ReceiveDictTcp(object): self.sock.listen(5) while True: client, address = self.sock.accept() - client.settimeout(0) - print("connecting to " + str(client) + " " + str(address)) + client.setblocking(1) + if self.verbose: print("connecting to " + str(client) + " " + str(address)) self.listenToClient(client,address) def listenToClient(self, client, address): size = 1024 while True: + if self.verbose: print("Try receiving") try: data = client.recv(size) if data: - # Set the response to echo back the recieved data + # Set the response to echo back the recieved data jresponse = data response = json.loads(jresponse) client.send(json.dumps(response)) diff --git a/src/dab_tuning_lib.py b/src/dab_tuning_lib.py index 8faafef..e5348b0 100644 --- a/src/dab_tuning_lib.py +++ b/src/dab_tuning_lib.py @@ -17,7 +17,6 @@ def calc_signal_sholder_ratio(fft, sampling_rate, debug = False, debug_path="", du.freq_to_fft_sample(-du.c["bw"]/2, fft_size, sampling_rate)) sholder = np.mean(fft[n_sholder[0]:n_sholder[1]]) - score = -sholder if debug == True: print(n_sig, n_sholder, n_noise) @@ -25,7 +24,69 @@ def calc_signal_sholder_ratio(fft, sampling_rate, debug = False, debug_path="", plt.plot((n_sig[0], n_sig[1]), (sig, sig), linewidth=5, color='g') plt.plot((n_noise[0], n_noise[1]), (noise, noise), linewidth=5, color='r') plt.plot((n_sholder[0], n_sholder[1]), (sholder, sholder), linewidth=5, color='y') - plt.savefig(debug_path + "/" + str(score) + suffix + ".png") + if debug_path: plt.savefig(debug_path + "/" + str(loss) + suffix + ".png") + plt.show() plt.clf() - return score + return sholder + +def calc_signal_sholder_peak_ratio(fft, sampling_rate, debug = False, debug_path="", suffix=""): + fft_size = fft.shape[0] + n_sig = (du.freq_to_fft_sample(-du.c["bw"]/2., fft_size, sampling_rate), + du.freq_to_fft_sample( du.c["bw"]/2., fft_size, sampling_rate)) + sig = np.mean(fft[n_sig[0]:n_sig[1]]) + + n_noise = (du.freq_to_fft_sample(-3000000., fft_size, sampling_rate), + du.freq_to_fft_sample(-2500000, fft_size, sampling_rate)) + noise = np.mean(fft[n_noise[0]:n_noise[1]]) + + n_sholder = (du.freq_to_fft_sample(-1500000, fft_size, sampling_rate), + du.freq_to_fft_sample(-du.c["bw"]/2, fft_size, sampling_rate)) + sholder = np.mean(fft[n_sholder[0]:n_sholder[1]]) + + loss = sholder/sig + + + if debug == True: + print(n_sig, n_sholder, n_noise) + plt.plot(fft) + plt.plot((n_sig[0], n_sig[1]), (sig, sig), linewidth=5, color='g') + plt.plot((n_noise[0], n_noise[1]), (noise, noise), linewidth=5, color='r') + plt.plot((n_sholder[0], n_sholder[1]), (sholder, sholder), linewidth=5, color='y') + if debug_path: plt.savefig(debug_path + "/" + str(loss) + suffix + ".png") + plt.show() + plt.clf() + + return loss + +def calc_max_in_freq_range(fft, sampling_rate, f_start, f_end, debug = False, debug_path="", suffix=""): + fft_size = fft.shape[0] + n_sig = (du.freq_to_fft_sample(f_start, fft_size, sampling_rate), + du.freq_to_fft_sample(f_end, fft_size, sampling_rate)) + sig = np.max(fft[n_sig[0]:n_sig[1]]) + + if debug == True: + print(n_sig) + plt.plot(fft) + plt.plot((n_sig[0], n_sig[1]), (sig, sig), linewidth=5, color='g') + if debug_path: plt.savefig(debug_path + "/" + str(loss) + suffix + ".png") + plt.show() + plt.clf() + + return sig + +def calc_mean_in_freq_range(fft, sampling_rate, f_start, f_end, debug = False, debug_path="", suffix=""): + fft_size = fft.shape[0] + n_sig = (du.freq_to_fft_sample(f_start, fft_size, sampling_rate), + du.freq_to_fft_sample(f_end, fft_size, sampling_rate)) + sig = np.mean(fft[n_sig[0]:n_sig[1]]) + + if debug == True: + print(n_sig) + plt.plot(fft) + plt.plot((n_sig[0], n_sig[1]), (sig, sig), linewidth=5, color='g') + if debug_path: plt.savefig(debug_path + "/" + str(loss) + suffix + ".png") + plt.show() + plt.clf() + + return sig diff --git a/src/dab_util.py b/src/dab_util.py index 8ab1e03..fbd1cc6 100644 --- a/src/dab_util.py +++ b/src/dab_util.py @@ -3,9 +3,13 @@ import scipy import matplotlib.pyplot as plt import fftconvolve -c = { - "bw":1536000 - } +c = {} +c["bw"]=1536000 +c["frame_ms"]=96 +c["frame_8192000"]=c["frame_ms"] * 8192 +c["frame_2048000"]=c["frame_ms"] * 2048 +c["sym_8192000"]=96./76*8192 +c["sym_2048000"]=96./76*2048 def calc_fft(signal, fft_size = 1024, sampling_rate = 1, plot = False): """returns one numpy array for the frequencies and one for the corresponding fft""" diff --git a/src/tcp_sync.py b/src/tcp_sync.py index 6a2e619..4a5a5b8 100644 --- a/src/tcp_sync.py +++ b/src/tcp_sync.py @@ -5,6 +5,7 @@ import Queue import time import socket import struct +import numpy as np class _TcpSyncClient(threading.Thread): """Thead for message polling""" @@ -54,7 +55,7 @@ class _TcpSyncClient(threading.Thread): if (len(s)) == self.packet_size: break if (len(s)) > self.packet_size: - print("received wrong size of length " + str(len(s))) + print("received wrong size of length " + str(len(s)) + " instead of " + str(self.packet_size)) time.sleep(0.01) return -1 @@ -96,6 +97,16 @@ class UhdSyncMsg(object): out.append(self.tcpa.queue.get()) return out + def get_msgs_fft(self, num): + """ + get received messages as string of integer + apply fftshift to message + """ + out = [] + while len(out) < num: + out.append(self.tcpa.queue.get()) + return [np.fft.fftshift(np.array(o)) for o in out] + def get_res(self): """get received messages as string of integer""" out = [] |