aboutsummaryrefslogtreecommitdiffstats
path: root/lab2/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'lab2/scripts')
-rw-r--r--lab2/scripts/filter.py24
-rw-r--r--lab2/scripts/gensin.m23
-rw-r--r--lab2/scripts/requirements.txt8
-rw-r--r--lab2/scripts/test_nyquist.m4
-rw-r--r--lab2/scripts/test_nyquist.m~4
5 files changed, 63 insertions, 0 deletions
diff --git a/lab2/scripts/filter.py b/lab2/scripts/filter.py
new file mode 100644
index 0000000..c35f75e
--- /dev/null
+++ b/lab2/scripts/filter.py
@@ -0,0 +1,24 @@
+from math import sqrt
+import matplotlib.pyplot as plt
+
+
+a0 = sqrt(2)
+b0 = 1/sqrt(2)
+
+y = [0, 0, 0]
+x = [1]
+
+result = [0]
+
+for i in range(0, 8):
+ y[0] = a0 * y[1] - y[2] + b0 * x[0]
+ result.append(y[0])
+ y[2] = y[1]
+ y[1] = y[0]
+ x[0] = 0
+
+plt.plot(result)
+plt.title("Filter Output")
+plt.ylabel("y: sin(x)")
+plt.xlabel("x: sample")
+plt.show()
diff --git a/lab2/scripts/gensin.m b/lab2/scripts/gensin.m
new file mode 100644
index 0000000..ae8b6d7
--- /dev/null
+++ b/lab2/scripts/gensin.m
@@ -0,0 +1,23 @@
+% Generates a discrete sine wave with the following properties
+
+% A: Amplitude
+% F0: frequency
+% fs: sampling frequency
+% theta: initial phase
+% nstart: first sample index
+% nend: last sample index
+function x = gensin(A, F0, fs, theta, nstart, nend)
+
+% zero the column vector to the right size
+fullSeries = zeros(nend-nstart+1, 1);
+
+% go through all the elements until the end
+for i = 1:nend
+ % apply the sine wave for every element
+ fullSeries(i) = A*sin(2*pi*F0*i/fs + theta);
+end
+
+% set the result to the window that was passed in by the user
+x = fullSeries(nstart:nend);
+
+end \ No newline at end of file
diff --git a/lab2/scripts/requirements.txt b/lab2/scripts/requirements.txt
new file mode 100644
index 0000000..6d456f7
--- /dev/null
+++ b/lab2/scripts/requirements.txt
@@ -0,0 +1,8 @@
+cycler==0.10.0
+matplotlib==2.1.2
+numpy==1.14.0
+pyparsing==2.2.0
+python-dateutil==2.6.1
+pytz==2017.3
+six==1.11.0
+tabulate==0.8.2
diff --git a/lab2/scripts/test_nyquist.m b/lab2/scripts/test_nyquist.m
new file mode 100644
index 0000000..30d63c5
--- /dev/null
+++ b/lab2/scripts/test_nyquist.m
@@ -0,0 +1,4 @@
+wave39 = gensin(1, 3900, 96000, 0, 1, 400);
+wave41 = gensin(0.1, 4100, 96000, 0, 1, 400);
+
+plot(wave39+wave41) \ No newline at end of file
diff --git a/lab2/scripts/test_nyquist.m~ b/lab2/scripts/test_nyquist.m~
new file mode 100644
index 0000000..1d4c541
--- /dev/null
+++ b/lab2/scripts/test_nyquist.m~
@@ -0,0 +1,4 @@
+wave39 = gensin(1, 3900, 96000, 0, 1, 100);
+wave41 =
+
+plot(wave) \ No newline at end of file