aboutsummaryrefslogtreecommitdiff
path: root/sem5/sig/eksamnen/fir-plot.m
diff options
context:
space:
mode:
Diffstat (limited to 'sem5/sig/eksamnen/fir-plot.m')
-rw-r--r--sem5/sig/eksamnen/fir-plot.m37
1 files changed, 37 insertions, 0 deletions
diff --git a/sem5/sig/eksamnen/fir-plot.m b/sem5/sig/eksamnen/fir-plot.m
new file mode 100644
index 0000000..3148b9b
--- /dev/null
+++ b/sem5/sig/eksamnen/fir-plot.m
@@ -0,0 +1,37 @@
+clear
+
+M = 28;
+
+for i=0:999,
+ omega(i+1) = pi * i / 999;
+end;
+
+
+for i=0:999,
+ sum_t = 0;
+ sum_b = 0;
+
+ for k=1:M/2,
+ % h får altid M/2 så det kan optimeres ud.
+ h = ((sin((pi/4) * k)) / (pi * k));
+
+ a = 2 * h;
+ % Hamming:
+ a = a * (0.54 - 0.46 * cos( 2 * pi * (k + (M/2)) / (M)));
+
+ sum_t = sum_t + a * cos(k * omega(i+1));
+ sum_b = sum_b + a;
+ end;
+
+ % Når k=0
+ sum_t = sum_t + 0.25;
+ sum_b = sum_b + 0.25;
+
+ amp(i+1) = sum_t / sum_b;
+
+end;
+
+plot(omega, 20 * log10(abs(amp)), 3/16 * pi, -1, "+", 3/8 * pi, -10, "+")
+grid;
+xlabel("Frequency");
+ylabel("Amplitude [dB]"); \ No newline at end of file