From 7b3657a77eeec57f2dd21de6fdc36e5240560c8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <andreas.mueller@ost.ch>
Date: Fri, 13 May 2022 15:13:30 +0200
Subject: improvements

---
 buch/papers/fm/anim/Makefile      | 12 +++++
 buch/papers/fm/anim/animation.tex | 85 +++++++++++++++++++++++++++++++++
 buch/papers/fm/anim/fm.m          | 98 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 buch/papers/fm/anim/Makefile
 create mode 100644 buch/papers/fm/anim/animation.tex
 create mode 100644 buch/papers/fm/anim/fm.m

(limited to 'buch/papers/fm/anim')

diff --git a/buch/papers/fm/anim/Makefile b/buch/papers/fm/anim/Makefile
new file mode 100644
index 0000000..f4c7850
--- /dev/null
+++ b/buch/papers/fm/anim/Makefile
@@ -0,0 +1,12 @@
+#
+# Makefile
+#
+# (c) 2022 Prof Dr Andreas Müller
+#
+all:	animation.pdf
+
+parts.tex:	fm.m
+	octave fm.m
+
+animation.pdf:	animation.tex parts.tex
+	pdflatex animation.tex
diff --git a/buch/papers/fm/anim/animation.tex b/buch/papers/fm/anim/animation.tex
new file mode 100644
index 0000000..4a6f428
--- /dev/null
+++ b/buch/papers/fm/anim/animation.tex
@@ -0,0 +1,85 @@
+%
+% animation.tex
+%
+% (c) 2022 Prof Dr Andreas Müller,
+%
+\documentclass[aspectratio=169]{beamer}
+\usepackage[utf8]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{epic}
+\usepackage{color}
+\usepackage{array}
+\usepackage{ifthen}
+\usepackage{lmodern}
+\usepackage{amsmath}
+\usepackage{amssymb}
+\usepackage{nccmath}
+\usepackage{mathtools}
+\usepackage{adjustbox}
+\usepackage{multimedia}
+\usepackage{verbatim}
+\usepackage{wasysym}
+\usepackage{stmaryrd}
+\usepackage{tikz}
+\usetikzlibrary{shapes.geometric}
+\usetikzlibrary{decorations.pathreplacing}
+\usetikzlibrary{calc}
+\usetikzlibrary{arrows}
+\usetikzlibrary{3d}
+\usetikzlibrary{arrows,shapes,math,decorations.text,automata}
+\usepackage{pifont}
+\usepackage[all]{xy}
+\usepackage[many]{tcolorbox}
+\mode<beamer>{%
+\usetheme[hideothersubsections,hidetitle]{Hannover}
+}
+\beamertemplatenavigationsymbolsempty
+\begin{document}
+
+\def\spektrum#1#2{
+\only<#1>{
+	\begin{scope}
+	\color{red}
+	\input{#2}
+	\end{scope}
+}
+}
+
+\begin{frame}
+\begin{center}
+\begin{tikzpicture}[>=latex,thick]
+\def\df{0.37}
+\def\da{1}
+
+\draw[->,color=gray] (0,-0.1) -- (0,6.3) [right] coordinate[label={right:$a$}];
+
+\foreach \a in {1,...,5}{
+	\draw[color=gray!50] (-6,{(6-\a)*\da}) -- (6,{(6-\a)*\da});
+}
+\draw[color=gray!50] (-6,{6*\da}) -- (6,{6*\da});
+\foreach \f in {-15,-10,-5,5,10,15}{
+	\draw[color=gray!50] ({\f*\df},0) -- ({\f*\df},{6*\da});
+}
+
+\input{parts.tex}
+
+\draw[->] (-6.1,0) -- (6.9,0) coordinate[label={$f$}];
+\foreach \f in {-16,...,16}{
+	\draw ({\f*\df},-0.05) -- ({\f*\df},0.05);
+}
+\foreach \f in {-15,-10,-5,5,10,15}{
+	\node at ({\f*\df},-0.1) [below] {$\f f_m$};
+	\draw ({\f*\df},-0.1) -- ({\f*\df},0.1);
+}
+\node at (0,-0.1) [below] {$0$};
+
+\foreach \a in {1,...,5}{
+	\node at (6,{(6-\a)*\da}) [right] {$-\a$};
+}
+\node at (6,{6*\da}) [right] {$\phantom{-}0$};
+
+\end{tikzpicture}
+\end{center}
+\end{frame}
+
+\end{document}
diff --git a/buch/papers/fm/anim/fm.m b/buch/papers/fm/anim/fm.m
new file mode 100644
index 0000000..9062818
--- /dev/null
+++ b/buch/papers/fm/anim/fm.m
@@ -0,0 +1,98 @@
+#
+# fm.m -- animation frequenzspektrum
+#
+# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
+#
+global fc;
+fc = 1e6;
+global width;
+width = 16;
+global fm;
+fm = 1000;
+global gamma;
+gamma = 2;
+global resolution;
+resolution = 300;
+
+function retval = spektrum(beta, fm)
+	global width;
+	global fc;
+	retval = zeros(2 * width + 1, 2);
+	center = width + 1;
+	for k = (0:width)
+		retval(center - k, 1) = fc - k * fm;
+		retval(center + k, 1) = fc + k * fm;
+		a = besselj(k, beta);
+		retval(center - k, 2) = a;
+		retval(center + k, 2) = a;
+	endfor
+endfunction
+
+function drawspectrum(fn, spectrum, foffset, fscale, beta)
+	n = size(spectrum)(1,1);
+	for i = (1:n)
+		f = (spectrum(i, 1) - foffset)/fscale;
+		a = log10(spectrum(i, 2)) + 6;
+		if (a < 0) 
+			a = 0;
+		end
+		fprintf(fn, "\\draw[line width=3.5pt] ");
+		fprintf(fn, "({%.2f*\\df},0) -- ({%.2f*\\df},{%.5f*\\da});\n",
+			f, f, abs(a));
+		fprintf(fn, "\\node at ({-15*\\df},5.5) [right] {$\\beta = %.3f$};", beta);
+	endfor
+endfunction
+
+function drawhull(fn, beta)
+	global resolution;
+	fprintf(fn, "\\begin{scope}\n");
+	fprintf(fn, "\\clip ({-16.5*\\df},0) rectangle ({16.5*\\df},{6*\\da});\n");
+	p = zeros(resolution, 2);
+	for k = (1:resolution)
+		nu = 16.5 * (k - 1) / resolution;
+		p(k,1) = nu;
+		y = log10(abs(besselj(nu, beta))) + 6;
+		p(k,2) = y;
+	end
+	fprintf(fn, "\\draw[color=blue] ({%.4f*\\df},{%.5f*\\da})",
+		p(1,1), p(1,2));
+	for k = (2:resolution)
+		fprintf(fn, "\n    -- ({%.4f*\\df},{%.5f*\\da})",
+			p(k,1), p(k,2));
+	endfor
+	fprintf(fn, ";\n\n");
+	fprintf(fn, "\\draw[color=blue] ({%.4f*\\df},{%.5f*\\da})",
+		p(1,1), p(1,2));
+	for k = (2:resolution)
+		fprintf(fn, "\n    -- ({%.4f*\\df},{%.5f*\\da})",
+			-p(k,1), p(k,2));
+	endfor
+	fprintf(fn, ";\n\n");
+	fprintf(fn, "\\end{scope}\n");
+endfunction
+
+function animation(betamin, betamax, steps)
+	global fm;
+	global fc;
+	global gamma;
+	fa = fopen("parts.tex", "w");
+	for k = (1:steps)
+		% add entry to parts.tex
+		fprintf(fa, "\\spektrum{%d}{texfiles/a%04d.tex}\n", k, k);
+		% compute beta
+		x = (k - 1) / (steps - 1);
+		beta = betamin + (betamax - betamin) * (x ^ gamma);
+		% create a new file
+		name = sprintf("texfiles/a%04d.tex", k);
+		fn = fopen(name, "w");
+		% write the hull
+		drawhull(fn, beta);
+		% compute and write the spectrum
+		spectrum = spektrum(beta, fm);
+		drawspectrum(fn, spectrum, fc, fm, beta);
+		fclose(fn);
+	endfor
+	fclose(fa);
+endfunction
+
+animation(0.001,10.1,200)
-- 
cgit v1.2.1