summaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
Diffstat (limited to 'prog')
-rw-r--r--prog/fourier/.gdb_history7
-rw-r--r--prog/fourier/.gitignore2
-rw-r--r--prog/fourier/dft.c101
-rw-r--r--prog/fourier/ldft.c8
-rw-r--r--prog/inventar/.gitignore1
-rw-r--r--prog/inventar/h.php8
-rw-r--r--prog/inventar/index.php82
7 files changed, 209 insertions, 0 deletions
diff --git a/prog/fourier/.gdb_history b/prog/fourier/.gdb_history
new file mode 100644
index 0000000..b3967fe
--- /dev/null
+++ b/prog/fourier/.gdb_history
@@ -0,0 +1,7 @@
+bt
+list
+p najv
+p val
+quit
+q
+quit
diff --git a/prog/fourier/.gitignore b/prog/fourier/.gitignore
new file mode 100644
index 0000000..90989b8
--- /dev/null
+++ b/prog/fourier/.gitignore
@@ -0,0 +1,2 @@
+a.out
+core
diff --git a/prog/fourier/dft.c b/prog/fourier/dft.c
new file mode 100644
index 0000000..598a7b3
--- /dev/null
+++ b/prog/fourier/dft.c
@@ -0,0 +1,101 @@
+// v stdin piši S8 zvočne podatke z 8000 vzorci na sekundo
+// frekvence:
+// 2100 Hz BAND
+// 800 Hz MONI
+// 1000 Hz CALL
+// 1450 Hz VFO/MR
+// 1750 Hz A/B
+// DTMF:
+// 1209 Hz 1336 Hz 1477 Hz 1633 Hz
+// 697 1 2 3 A
+// 770 4 5 6 B
+// 852 7 8 9 C
+// 941 * 0 # D
+// ffmpeg -f alsa -ac 1 -i hw:5 -f s8 -ar 8000 - | ./a.out
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <complex.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/param.h> // for MIN, MAX
+int main (void) {
+ if (setvbuf(stdout, NULL, _IOFBF, 0))
+ error_at_line(1, errno, __FILE__, __LINE__, "setvbuf");
+#define SAMPLES 256
+ int samples[SAMPLES] = { 0 };
+ double povprečje = 0;
+ int frekvence[] = {1209, 1336, 1477, 1633, 697, 770, 852, 941, 2100, 800, 1000, 1450, 1750};
+ #define FREKVENC 13
+ // int frekvence[] = {2100, 800, 1000, 1450, 1750, 1208, 1209, 1210, 1335, 1336, 1337, 1476, 1477, 1478, 1632, 1633, 1634, 696, 697, 698, 769, 770, 771, 851, 852, 853, 940, 941, 942};
+/* #define FREKVENC 60
+ int frekvence[FREKVENC+1];
+ for (int i = 0; i < FREKVENC; i++)
+ // frekvence[i] = 1000-(FREKVENC*10/2)+i*10;
+ frekvence[i] = i*100; */
+ complex sums[FREKVENC] = { 0 };
+ unsigned sample = 0;
+ int received = 0;
+ char znak = '\0';
+ while ((received = getchar()) != EOF) {
+ unsigned char intermed = received;
+ char recvd = *(char *) &intermed;
+ povprečje = (povprečje*SAMPLES+abs(recvd)-abs(samples[sample % SAMPLES]))/SAMPLES;
+ if (!(sample % SAMPLES))
+ printf("\033[2J\npovprečje: %f\n", povprečje);
+ for (int frekvenca = 0; frekvenca < FREKVENC; frekvenca++) {
+#define RATE 8000
+ // sums[frekvenca] -= (complex) samples[sample % SAMPLES]*cpow(M_E, (complex) -2*M_PI*I*(complex) frekvence[frekvenca]/(complex) RATE);
+ sums[frekvenca] += recvd*cpow(M_E, -2*M_PI*I*frekvence[frekvenca]*sample/RATE);
+ sums[frekvenca] -= samples[sample % SAMPLES]*cpow(M_E, -2*M_PI*I*frekvence[frekvenca]*(sample-SAMPLES)/RATE);
+ if (!(sample % SAMPLES)) {
+ printf("%d\t", frekvence[frekvenca]);
+ // for (int i = 0; i < pow(cabs(sums[frekvenca])/100, 2)/100; i++)
+ for (int i = 0; i < cabs(sums[frekvenca])/256; i++)
+ printf("#");
+ printf("\n");
+ }
+ }
+ if (!(sample % SAMPLES)) {
+ int najv[3] = {0};
+ double val[3] = {0};
+ for (int i = 0; i < FREKVENC; i++)
+ for (int j = 0; j < 3; j++)
+ if (cabs(sums[i]) > val[j]) {
+ for (int k = 2; k > j; k--) {
+ najv[k] = najv[k-1];
+ val[k] = val[k-1];
+ }
+ najv[j] = i;
+ val[j] = cabs(sums[i]);
+ break;
+ }
+ char trenutni = '\0';
+ if (val[1] > val[0]/3 && val[2] < val[1]/3) {
+ int večja = MAX(frekvence[najv[0]], frekvence[najv[1]]);
+ int manjša = MIN(frekvence[najv[0]], frekvence[najv[1]]);
+ char znaki[4][4] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}};
+ int getidx (int freq) {
+ int i;
+ for (i = 0; i < 8; i++)
+ if (freq == frekvence[i])
+ return i%4;
+ return -1;
+ }
+ if (getidx(manjša) == -1 || getidx(večja) == -1)
+ trenutni = '\0';
+ else
+ trenutni = znaki[getidx(manjša)][getidx(večja)];
+ }
+ if (val[1] < val[0]/3 && najv[0] > 7) {
+ char znaki[] = "PSZVM";
+ trenutni = znaki[najv[0]-8];
+ }
+ if (znak == trenutni && znak)
+ printf("tipka: %c\n", znak);
+ znak = trenutni;
+ fflush(stdout);
+ }
+ samples[sample++ % SAMPLES] = recvd;
+ }
+}
diff --git a/prog/fourier/ldft.c b/prog/fourier/ldft.c
new file mode 100644
index 0000000..1420bc8
--- /dev/null
+++ b/prog/fourier/ldft.c
@@ -0,0 +1,8 @@
+// lying discrete fourier transformation
+// this has no mathematical proofs behind it
+// key difference is that it operates in a sliding window mode without holding the window buffer itself
+// instead it works in a faucet way, with a single scalar complex state for every frequency that you want to monitor stored and operates with this state one sample at a time
+// absolute value of the state directly correlates with freqency domain ordinate value
+// temelji na diskretni fourierjevi transformaciji in na weighted moving average
+// namesto izhodnega vektorja ob množenju ...
+// nvm najprej bom poizkusil narediti dft po krščansko, potem se bomo šli glupe optimizacije
diff --git a/prog/inventar/.gitignore b/prog/inventar/.gitignore
new file mode 100644
index 0000000..dd5199b
--- /dev/null
+++ b/prog/inventar/.gitignore
@@ -0,0 +1 @@
+*db
diff --git a/prog/inventar/h.php b/prog/inventar/h.php
new file mode 100644
index 0000000..2cba303
--- /dev/null
+++ b/prog/inventar/h.php
@@ -0,0 +1,8 @@
+<?php
+header("Content-Security-Policy: script-src 'none'"); // disable js
+$db = new PDO("sqlite:db", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
+if (!$db)
+ die("db: " . htmlspecialchars($e->getMessage()));
+$ro = new PDO("sqlite:db", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::SQLITE_ATTR_OPEN_FLAGS => PDO::SQLITE_OPEN_READONLY]);
+if (!$ro)
+ die("ro: " . htmlspecialchars($e->getMessage()));
diff --git a/prog/inventar/index.php b/prog/inventar/index.php
new file mode 100644
index 0000000..4dd38dd
--- /dev/null
+++ b/prog/inventar/index.php
@@ -0,0 +1,82 @@
+<?php
+$auth = ["test" => "test"];
+if ((isset($_REQUEST["prijava"]) && (empty($_SERVER["PHP_AUTH_USER"]) || $auth[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])) || (isset($_SERVER['PHP_AUTH_USER']) && $auth[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW'])) {
+ header("WWW-Authenticate: Basic realm=inventar");
+ header("HTTP/1.0 401 Neprijavljen");
+ die("401");
+}
+?>
+<style>
+table, td, tr, th {
+ border: 1px solid red;
+}
+</style>
+<form>
+<input autofocus placeholder="where expression" name=q value="<?= htmlspecialchars($_REQUEST["q"]) ?>" />
+<input type=submit />
+</form>
+<table>
+<?php
+if (empty($_SERVER['PHP_AUTH_USER']))
+ echo "<a href=?prijava=1>prijava</a>";
+else
+ echo "<form method=post><input type=submit name=dodaj value='dodaj stvar kot {$_SERVER['PHP_AUTH_USER']}' /></form>";
+require_once "h.php";
+$passed = [];
+if (!empty($_POST["izbriši"]))
+ $db->exec("delete from stvari where lastnik = '{$_SERVER["PHP_AUTH_USER"]}' and id = '{$_POST["id"]}'");
+if (!empty($_POST["dodaj"]) && !empty($_SERVER["PHP_AUTH_USER"]))
+ $db->exec("insert into stvari (lastnik) values ('{$_SERVER["PHP_AUTH_USER"]}')");
+foreach ($_POST as $k => $v)
+ if (is_numeric($k)) {
+ foreach ($_POST as $k2 => $v2) {
+ $sp = strpos($k2, $k);
+ if ($sp) {
+ $passed[] = substr($k2, 0, $sp);
+ }
+ }
+ $par = [];
+ foreach ($passed as $p) {
+ if (!str_contains(strtolower($p), "id"))
+ $par[] = "'" . SQLite3::escapeString($p) . "' = '" . SQLite3::escapeString($_POST[$p . $k]) . "'";
+ }
+ $s = "update stvari set " . implode(", ", $par) . " where lastnik='{$_SERVER["PHP_AUTH_USER"]}' and id={$k}";
+ $db->exec($s);
+ }
+if (!empty($_REQUEST["q"]))
+ $ret = $ro->query("select * from stvari where " . $_REQUEST["q"]);
+else
+ $ret = $ro->query("select * from stvari");
+$i = 0;
+foreach ($ret as $row) {
+ if ($i == 0)
+ foreach ($row as $k => $v)
+ if ($k != "id" && !is_numeric($k))
+ echo "<th>$k</th>";
+ echo "<form method=post><tr>";
+ foreach ($row as $k => $v) {
+ if ($k == "id" || is_numeric($k))
+ continue;
+ echo "<td id=$k$i>";
+ $ok = false;
+ foreach (["input", "name"] as $w)
+ if (!str_contains(strtolower($v), $w))
+ $ok = true;
+ if ($k == "slika" && !empty($v))
+ echo "<img src=$v></img>";
+ if ($k == "lastnik" && $v == $_SERVER['PHP_AUTH_USER']) {
+ echo "<input type=submit value=shrani name={$row["id"]} />";
+ echo "<input type=hidden name=id value={$row["id"]} />";
+ echo "<input type=submit value=izbriši name=izbriši /></td>";
+ }
+ $last = true;
+ if ($row["lastnik"] == $_SERVER['PHP_AUTH_USER'] && $k != "lastnik") {
+ echo "<input name=$k{$row["id"]} value=" . htmlspecialchars($v) . " />";
+ $last = false;
+ } else
+ if ($last && $k != "slika")
+ echo "$v</td>";
+ }
+ echo "</form></tr>";
+ $i++;
+}