From 11b5c8d5cae4859d10a9634cb1779ab8ada595f3 Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Fri, 29 Jul 2016 16:36:53 +0200 Subject: [PATCH 1/2] =?UTF-8?q?spa=C3=9F=20mit=20frequenzmodulation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frequenzmodulation.m | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 frequenzmodulation.m diff --git a/frequenzmodulation.m b/frequenzmodulation.m new file mode 100644 index 0000000..3eb2dfa --- /dev/null +++ b/frequenzmodulation.m @@ -0,0 +1,57 @@ + +#d = [ 1 0 1 0 1 0 0 1 0 1 1 ]; +datalen = 30; +d = rand(1,datalen) < 0.5; +n = 0:datalen-1; +Tb = 0.2; +fa = 2000; +freq = [ 50 30 ]; +signallen = (datalen*Tb-1/fa) +t = 0:(1/fa):signallen; +f = freq(d(floor(t/Tb)+1)+1); +phi = cumsum(2*pi*f)/fa; +s = cos(phi); + +subplot(4,1,1) +stem(n,d) +subplot(4,1,2) +plot(t,s) +axis([0 signallen -1 1]) + +[b,a] = butter(5,2*mean(freq)/fa); + +slow = filter(b,a,s); +st = abs(slow); + +[b2,a2] = butter(10,2*(min(freq)*0.8)/fa); +hk = filter(b2,a2,st); + +subplot(4,1,3) +cla; hold on; +plot(t,slow,'k') +plot(t,st,'g') +plot(t,hk,'r') +hold off +axis([0 signallen -1 1]) + +mt = zeros(size(n)); +for i = 1:datalen + ts = (i-1) * Tb; + te = i * Tb; + tf = t > ts & t < te; + mt(i) = mean(hk(tf)); +endfor +hold on; +stem((n+0.5)*Tb,mt,'r'); +hold off; + +thr = (min(mt) + max(mt)) / 2; + +ds = mt > thr; + +subplot(4,1,4) +err = ds != d; +cla; hold on; +stem(n(~err),ds(~err)) +stem(n(err),ds(err),'rx') +hold off; \ No newline at end of file From aece5b5da49b9f217c7395a8993ad8679edf7c4c Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Thu, 4 Aug 2016 19:41:56 +0200 Subject: [PATCH 2/2] Prime factorization in clojure. --- primefactors.clj | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 primefactors.clj diff --git a/primefactors.clj b/primefactors.clj new file mode 100644 index 0000000..49c5f5c --- /dev/null +++ b/primefactors.clj @@ -0,0 +1,13 @@ +(defn factors [x] + (if (== x 1) + '() + (let [f + (first + (filter (fn [e] (zero? (mod x e))) + (range 2 (+ x 1)) + ) + )] + (conj (factors (/ x f)) f) + ) + ) +) \ No newline at end of file