From 90a89f6f5ba15a983e1ea50e87d019bcd567ba2f Mon Sep 17 00:00:00 2001
From: sara <sara.halter@gmx.ch>
Date: Sat, 27 Nov 2021 21:51:50 +0100
Subject: =?UTF-8?q?FIR=20Filter=20Block=20in=20GNU=20Radio=20ink.=20fload?=
 =?UTF-8?q?=20variabeln=20m=C3=B6glichkeit=20erstellt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../grc/fadingui_multipath_fading.block.yml        | 13 ++++-
 src/gr-fadingui/python/multipath_fading.py         | 67 ++++++++++++++++------
 2 files changed, 58 insertions(+), 22 deletions(-)

(limited to 'src')

diff --git a/src/gr-fadingui/grc/fadingui_multipath_fading.block.yml b/src/gr-fadingui/grc/fadingui_multipath_fading.block.yml
index e116467..1d374ac 100644
--- a/src/gr-fadingui/grc/fadingui_multipath_fading.block.yml
+++ b/src/gr-fadingui/grc/fadingui_multipath_fading.block.yml
@@ -12,12 +12,19 @@ templates:
 #     * label (label shown in the GUI)
 #     * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
 parameters:
-- id: amplitudes
-  label: Amplitudes
-  dtype: raw
 - id: delays
   label: Delays
+  dtype: complex_vector
+- id: amplitudes
+  label: Amplitudes
   dtype: raw
+- id: los
+  label: LOS/NLOS
+  options: ['True', 'False']
+  option_labels: ['LOS', 'NLOS']
+  #default: 'False'
+  dtype: bool
+  #hide: ${ 'none' if los == 'False' else 'part' }
 
 #  Make one 'inputs' list entry per input and one 'outputs' list entry per output.
 #  Keys include:
diff --git a/src/gr-fadingui/python/multipath_fading.py b/src/gr-fadingui/python/multipath_fading.py
index 01f2dbe..02b3bb4 100644
--- a/src/gr-fadingui/python/multipath_fading.py
+++ b/src/gr-fadingui/python/multipath_fading.py
@@ -44,45 +44,74 @@ class multipath_fading(gr.sync_block):
         self.amplitudes = amplitudes
         self.delays = delays
         self.temp = [0]
-        # if los:
-        #     self.amplitudes.append(1)
-        #     self.delays.append(0)
-        self.los= 1
-        #self.fir = 
+        log.debug(los) #TO DO: True False unterscheidung 
+        if los == True:
+            self.los = 1
+            log.debug("Los True")
+        else: 
+            self.los = 0
+            log.debug("Los False")
+
+
+        
+        
 
     def work(self, input_items, output_items):
         """example: multiply with constant"""
         inp = input_items[0]
         oup = output_items[0]
         
-        if len(self.amplitudes) != len(self.delays):
+        if len(self.amplitudes) != len(self.delays):    # Test: Es muss gleich viele Werte für Delays und Amplituden haben.
             raise Exception("Amplitudes and Delay length dont match")
 
+
+        #TO DO negativ check 
+
+        
+
         #    raise Exception("Delay length can't be one")
         #if np.min(self.delays)<=1:
         #    raise Exception("Delay length can't be one")
-        max_len = np.max(self.delays)
-        sum_x = np.zeros(max_len)
-        for(a,d) in zip(self.amplitudes,self.delays):
+
+        #max_len = np.max(self.delays) #Max Werte herausfinden für länge 
+        #sum_x = np.zeros(max_len)
+
+        max_order = 2 * np.floor(np.max(self.delays)) + 1
+        max_samples = np.arange(0, max_order +1) 
+        max_len = len(max_samples) #Für Filter
+
+        sum_x = np.zeros(int(max_len))
+
+        for (a,d) in zip(self.amplitudes,self.delays):
             # if d-1 <= 0:
             #     x = np.concatenate([[a], np.zeros(max_len-1)])
-            # else:                
-            x = np.concatenate([np.zeros(d-1), [a], np.zeros(max_len-d)])
-            sum_x += x
+            # else:    
+            order = 2 * np.floor(d) + 1
+
+            skip = np.floor(d) - (order - 1) / 2 #M sollte immer 0 sein 
+            assert skip >= 0
+
+            samples = np.arange(0, order +1)  
+
+            h = a*(np.sinc(samples-d)) #sinc
+            h_len = np.concatenate([h, np.zeros(max_len-len(h))])
+
+            sum_x += h_len
+
+            #x = np.concatenate([np.zeros(d-1), [a], np.zeros(max_len-d)])
+            #sum_x += x
         
         sum_x[0] = self.los
-        log.debug(sum_x)
-        
-        #H_int = fft(sum_x)
-
-        #h = ifft(H_int)
+        #log.debug(sum_x)
 
-        #h[0]=1
 
         y = np.convolve(inp, sum_x)
         
+        # signal_shifted = np.convolve(h, inp, mode='full')
+        # y = signal_shifted
+
+        #y+=np.concatenate([self.temp,np.zeros(len(y)-len(self.temp))])
         y+=np.concatenate([self.temp,np.zeros(len(y)-len(self.temp))])
-        
 
         oup[:] = y[:len(inp)]
         self.temp = y[len(inp):]        
-- 
cgit v1.2.1


From 7588ef396ffeb2422d5d2deacbb5c5443475bee1 Mon Sep 17 00:00:00 2001
From: Nao Pross <np@0hm.ch>
Date: Sun, 28 Nov 2021 00:14:41 +0100
Subject: Move GUI files into their dir

---
 src/gui.py     | 131 ---------------------------------------------------------
 src/gui/gui.py | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gui/net.py |  68 ++++++++++++++++++++++++++++++
 src/net.py     |  68 ------------------------------
 4 files changed, 199 insertions(+), 199 deletions(-)
 delete mode 100755 src/gui.py
 create mode 100755 src/gui/gui.py
 create mode 100644 src/gui/net.py
 delete mode 100644 src/net.py

(limited to 'src')

diff --git a/src/gui.py b/src/gui.py
deleted file mode 100755
index b2cbebb..0000000
--- a/src/gui.py
+++ /dev/null
@@ -1,131 +0,0 @@
-#!/usr/bin/env python3
-
-# Python stdlib
-import sys
-
-# Grahical libraries
-from dearpygui.dearpygui import *
-import dearpygui._dearpygui as internal_dpg
-from dearpygui.demo import show_demo
-
-# Detect (unix) signals
-import signal
-
-# Mathematics
-import numpy as np
-
-# For debugging
-import logging
-
-# Remote resources
-import net
-
-#================================================
-# Debugging tools
-
-logging.basicConfig(format="[%(levelname)s] %(asctime)s %(message)s", level=logging.DEBUG)
-logger = logging.getLogger(__name__)
-
-#================================================
-# Initialize DearPyGUI
-
-create_context()
-create_viewport(title="Fading Demonstrator")
-setup_dearpygui()
-
-# Show demo for dev
-show_demo()
-
-
-#================================================
-# GUI Callback functions
-
-# Flow graph window
-def on_rx_node_link(sender, app_data):
-    link_id_1, link_id_2 = app_data
-    add_node_link(link_id_1, link_id_2, parent=sender)
-
-def on_rx_node_delink(sender, app_data):
-    link_id = app_data
-    delete_item(link_id)
-
-#================================================
-# Settings Window
-
-with window(label="Settings", width=200, height=400, pos=(25, 450), tag="sim_win"):
-    with child_window(autosize_x=True, height=100):
-        add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen)
-
-#================================================
-# Flow Graph Window
-
-with window(label="RX DSP Flow Graph", width=800, height=400, pos=(25,25), tag="rx_win"):
-    with node_editor(callback=on_rx_node_link, delink_callback=on_rx_node_delink):
-        with node(label="USRP Source", pos=(20,100)):
-            with node_attribute(tag="src_out", attribute_type=mvNode_Attr_Output):
-                add_text("Signal from antenna")
-
-        with node(label="Clock Sync", pos=(200,200)):
-            with node_attribute(tag="clksync_in", attribute_type=mvNode_Attr_Input):
-                add_text("Input")
-
-            with node_attribute(tag="clksync_out", attribute_type=mvNode_Attr_Output):
-                add_text("Synchronized")
-
-        with node(label="Equalizer", pos=(350,100)):
-            with node_attribute(tag="eq_in", attribute_type=mvNode_Attr_Input):
-                add_text("Input")
-
-            with node_attribute(attribute_type=mvNode_Attr_Static):
-                add_knob_float(label="Gain")
-
-            with node_attribute(tag="eq_out", attribute_type=mvNode_Attr_Output):
-                add_text("Equalized")
-
-        with node(label="Phase Locked Loop", pos=(600, 200)):
-            with node_attribute(tag="pll_in", attribute_type=mvNode_Attr_Input):
-                add_text("Input")
-
-            with node_attribute(tag="pll_out", attribute_type=mvNode_Attr_Output):
-                add_text("Locked")
-                add_knob_float(label="Loop BW")
-
-
-        add_node_link(get_alias_id("src_out"), get_alias_id("clksync_in"))
-        add_node_link(get_alias_id("clksync_out"), get_alias_id("eq_in"))
-        add_node_link(get_alias_id("eq_out"), get_alias_id("pll_in"))
-
-#================================================
-# Network plots Window
-
-recv_plot = net.network_plot(url="udp://localhost:31415", nsamples=100, label="Test", height=300, width=800)
-
-plots = {
-    recv_plot: "plt_ampl"
-}
-
-with window(label="Time domain plots", width=800, height=400, pos=(850,25)):
-    with recv_plot:
-        add_plot_axis(mvXAxis, label="Time")
-        add_plot_axis(mvYAxis, label="Amplitude", tag="plt_ampl")
-
-        add_line_series(recv_plot.x_data, recv_plot.y_data, parent="plt_ampl")
-
-#================================================
-# Start GUI and main loop
-
-# Start window and main loop
-show_viewport()
-
-# Main loop
-while is_dearpygui_running():
-    for plt, tag in plots.items():
-        plt.refresh_series(tag)
-
-    render_dearpygui_frame()
-
-#================================================
-# Close everything
-
-# clean up gui
-destroy_context()
diff --git a/src/gui/gui.py b/src/gui/gui.py
new file mode 100755
index 0000000..b2cbebb
--- /dev/null
+++ b/src/gui/gui.py
@@ -0,0 +1,131 @@
+#!/usr/bin/env python3
+
+# Python stdlib
+import sys
+
+# Grahical libraries
+from dearpygui.dearpygui import *
+import dearpygui._dearpygui as internal_dpg
+from dearpygui.demo import show_demo
+
+# Detect (unix) signals
+import signal
+
+# Mathematics
+import numpy as np
+
+# For debugging
+import logging
+
+# Remote resources
+import net
+
+#================================================
+# Debugging tools
+
+logging.basicConfig(format="[%(levelname)s] %(asctime)s %(message)s", level=logging.DEBUG)
+logger = logging.getLogger(__name__)
+
+#================================================
+# Initialize DearPyGUI
+
+create_context()
+create_viewport(title="Fading Demonstrator")
+setup_dearpygui()
+
+# Show demo for dev
+show_demo()
+
+
+#================================================
+# GUI Callback functions
+
+# Flow graph window
+def on_rx_node_link(sender, app_data):
+    link_id_1, link_id_2 = app_data
+    add_node_link(link_id_1, link_id_2, parent=sender)
+
+def on_rx_node_delink(sender, app_data):
+    link_id = app_data
+    delete_item(link_id)
+
+#================================================
+# Settings Window
+
+with window(label="Settings", width=200, height=400, pos=(25, 450), tag="sim_win"):
+    with child_window(autosize_x=True, height=100):
+        add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen)
+
+#================================================
+# Flow Graph Window
+
+with window(label="RX DSP Flow Graph", width=800, height=400, pos=(25,25), tag="rx_win"):
+    with node_editor(callback=on_rx_node_link, delink_callback=on_rx_node_delink):
+        with node(label="USRP Source", pos=(20,100)):
+            with node_attribute(tag="src_out", attribute_type=mvNode_Attr_Output):
+                add_text("Signal from antenna")
+
+        with node(label="Clock Sync", pos=(200,200)):
+            with node_attribute(tag="clksync_in", attribute_type=mvNode_Attr_Input):
+                add_text("Input")
+
+            with node_attribute(tag="clksync_out", attribute_type=mvNode_Attr_Output):
+                add_text("Synchronized")
+
+        with node(label="Equalizer", pos=(350,100)):
+            with node_attribute(tag="eq_in", attribute_type=mvNode_Attr_Input):
+                add_text("Input")
+
+            with node_attribute(attribute_type=mvNode_Attr_Static):
+                add_knob_float(label="Gain")
+
+            with node_attribute(tag="eq_out", attribute_type=mvNode_Attr_Output):
+                add_text("Equalized")
+
+        with node(label="Phase Locked Loop", pos=(600, 200)):
+            with node_attribute(tag="pll_in", attribute_type=mvNode_Attr_Input):
+                add_text("Input")
+
+            with node_attribute(tag="pll_out", attribute_type=mvNode_Attr_Output):
+                add_text("Locked")
+                add_knob_float(label="Loop BW")
+
+
+        add_node_link(get_alias_id("src_out"), get_alias_id("clksync_in"))
+        add_node_link(get_alias_id("clksync_out"), get_alias_id("eq_in"))
+        add_node_link(get_alias_id("eq_out"), get_alias_id("pll_in"))
+
+#================================================
+# Network plots Window
+
+recv_plot = net.network_plot(url="udp://localhost:31415", nsamples=100, label="Test", height=300, width=800)
+
+plots = {
+    recv_plot: "plt_ampl"
+}
+
+with window(label="Time domain plots", width=800, height=400, pos=(850,25)):
+    with recv_plot:
+        add_plot_axis(mvXAxis, label="Time")
+        add_plot_axis(mvYAxis, label="Amplitude", tag="plt_ampl")
+
+        add_line_series(recv_plot.x_data, recv_plot.y_data, parent="plt_ampl")
+
+#================================================
+# Start GUI and main loop
+
+# Start window and main loop
+show_viewport()
+
+# Main loop
+while is_dearpygui_running():
+    for plt, tag in plots.items():
+        plt.refresh_series(tag)
+
+    render_dearpygui_frame()
+
+#================================================
+# Close everything
+
+# clean up gui
+destroy_context()
diff --git a/src/gui/net.py b/src/gui/net.py
new file mode 100644
index 0000000..2c91bb8
--- /dev/null
+++ b/src/gui/net.py
@@ -0,0 +1,68 @@
+import select
+import socket
+from urllib.parse import urlparse
+
+import numpy as np
+from numpy_ringbuffer import RingBuffer
+import dearpygui.dearpygui as dpg
+
+
+class udpsource:
+    """
+    Creates an UDP listening socket
+    """
+    def __init__(self, url):
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        self.url = urlparse(url)
+
+    def __del__(self):
+        self.sock.close()
+
+    def bind(self):
+        self.sock.setblocking(False)
+        self.sock.bind((self.url.hostname, self.url.port))
+        # self.sock.listen()
+
+    def read(self, nbytes):
+        ready_to_read, ready_to_write, in_err = \
+                select.select([self.sock], [], [], 1)
+
+        if ready_to_read:
+            data = sock.recv(nbytes)
+            print(data)
+        else:
+            return None
+
+
+class network_plot(udpsource):
+    def __init__(self, url, nsamples, **kwargs):
+        udpsource.__init__(self, url)
+
+        self.nsamples = nsamples
+        self.plot = dpg.plot(**kwargs)
+
+        # create buffer and fill with zeroes
+        self.buffer = RingBuffer(capacity=nsamples, dtype=(float, 2))
+        for i in range(nsamples):
+            # TODO: remove random data used for testing
+            self.buffer.append(np.array([i, 1 + np.random.rand() / 5]))
+
+        self.bind()
+
+    def __enter__(self):
+        return self.plot.__enter__()
+
+    def __exit__(self, t, val, tb):
+        self.plot.__exit__(t, val, tb)
+
+    @property
+    def x_data(self):
+        return np.array(self.buffer[:,0])
+
+    @property
+    def y_data(self):
+        return np.array(self.buffer[:,1])
+
+    def refresh_series(self, tag):
+        dpg.set_value(tag, [self.x_data, self.y_data])
+        pass
diff --git a/src/net.py b/src/net.py
deleted file mode 100644
index 2c91bb8..0000000
--- a/src/net.py
+++ /dev/null
@@ -1,68 +0,0 @@
-import select
-import socket
-from urllib.parse import urlparse
-
-import numpy as np
-from numpy_ringbuffer import RingBuffer
-import dearpygui.dearpygui as dpg
-
-
-class udpsource:
-    """
-    Creates an UDP listening socket
-    """
-    def __init__(self, url):
-        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        self.url = urlparse(url)
-
-    def __del__(self):
-        self.sock.close()
-
-    def bind(self):
-        self.sock.setblocking(False)
-        self.sock.bind((self.url.hostname, self.url.port))
-        # self.sock.listen()
-
-    def read(self, nbytes):
-        ready_to_read, ready_to_write, in_err = \
-                select.select([self.sock], [], [], 1)
-
-        if ready_to_read:
-            data = sock.recv(nbytes)
-            print(data)
-        else:
-            return None
-
-
-class network_plot(udpsource):
-    def __init__(self, url, nsamples, **kwargs):
-        udpsource.__init__(self, url)
-
-        self.nsamples = nsamples
-        self.plot = dpg.plot(**kwargs)
-
-        # create buffer and fill with zeroes
-        self.buffer = RingBuffer(capacity=nsamples, dtype=(float, 2))
-        for i in range(nsamples):
-            # TODO: remove random data used for testing
-            self.buffer.append(np.array([i, 1 + np.random.rand() / 5]))
-
-        self.bind()
-
-    def __enter__(self):
-        return self.plot.__enter__()
-
-    def __exit__(self, t, val, tb):
-        self.plot.__exit__(t, val, tb)
-
-    @property
-    def x_data(self):
-        return np.array(self.buffer[:,0])
-
-    @property
-    def y_data(self):
-        return np.array(self.buffer[:,1])
-
-    def refresh_series(self, tag):
-        dpg.set_value(tag, [self.x_data, self.y_data])
-        pass
-- 
cgit v1.2.1