diff options
author | Julian T <julian@jtle.dk> | 2020-09-23 17:53:34 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-09-23 17:53:34 +0200 |
commit | fef26c3cd47c1e6d3a9dc7592db5721b996ead6b (patch) | |
tree | 688162f271a9968b78bd53a3b52732121de85cb7 /sem5/sig | |
parent | 5de991dd326103647b28e7d95b92b32a9e1671b9 (diff) |
Added signal processing assignment
Diffstat (limited to 'sem5/sig')
-rw-r--r-- | sem5/sig/mm6/default.nix | 5 | ||||
-rw-r--r-- | sem5/sig/mm6/opg2.py | 30 | ||||
-rw-r--r-- | sem5/sig/mm6/opg3.py | 29 |
3 files changed, 64 insertions, 0 deletions
diff --git a/sem5/sig/mm6/default.nix b/sem5/sig/mm6/default.nix new file mode 100644 index 0000000..5ba7198 --- /dev/null +++ b/sem5/sig/mm6/default.nix @@ -0,0 +1,5 @@ +with import <nixpkgs> {}; +stdenv.mkDerivation { + name = "plotting"; + buildInputs = [ python38Packages.matplotlib python38Packages.numpy ]; +} diff --git a/sem5/sig/mm6/opg2.py b/sem5/sig/mm6/opg2.py new file mode 100644 index 0000000..38d65fe --- /dev/null +++ b/sem5/sig/mm6/opg2.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# 2020-09-23:s5/sig/mm6/opg/2 + +import matplotlib.pyplot as plt +import sys +import numpy as np + +lookahead = 100 +values = 50 + +res = np.empty(values) + +for n in range(values): + s = 0 + for k in range(lookahead): + h = np.exp(-k/8) + + x = 1 + if (n - k) < 0: + x = 0 + + s += x * h + res[n] = s + +x = np.arange(values) + +plt.plot(x, res) +plt.show() + + diff --git a/sem5/sig/mm6/opg3.py b/sem5/sig/mm6/opg3.py new file mode 100644 index 0000000..c338c49 --- /dev/null +++ b/sem5/sig/mm6/opg3.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# 2020-09-23:s5/sig/mm6/opg/3 #cc7f + +import matplotlib.pyplot as plt +import numpy as np +import sys + +# Load data +data = [] +with open(sys.argv[1], "r") as f: + for line in f: + data.append(float(line)) + +data = np.array(data) +datalen = len(data) + +x = np.arange(datalen) +before = plt.subplot(2, 1, 1) +after = plt.subplot(2, 1, 2) +before.plot(x, data) + +res = np.empty(datalen) + +for i in range(datalen): + last = res[i-1] if i > 0 else 0 + res[i] = np.exp(-1/8) * last + 1/8 * data[i] + +after.plot(x, res) +plt.show() |