Skip to content
Snippets Groups Projects
Commit 41fec00b authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Lehrmaterialien, Beispiele und Tafelbild 1.7.2019

parent 5ea8cbeb
No related branches found
No related tags found
No related merge requests found
Showing
with 2950 additions and 0 deletions
../common/Zeichen_123.pdf
\ No newline at end of file
This diff is collapsed.
File added
% ad-20180701.pdf - Lecture Slides on Algorithms and Data Structures in C/C++
% Copyright (C) 2018, 2019 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Steganographie, Hardwarenahe Algorithmen
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{rotating}
\usepackage{pdftricks}
\usepackage{amsfonts}
\begin{psinputs}
\usepackage[latin1]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage{graphicx}
\usepackage{pstricks,pst-circ,pst-plot}
\psset{unit=0.6cm}
\psset{linewidth=0.03}
\end{psinputs}
\newcommand{\underconstruction}{%
\begin{picture}(0,0)(0,3)
\color{black}
\put(7,-2.2){\makebox(0,0)[b]{\includegraphics[width=1.5cm]{Zeichen_123.pdf}}}
\put(7,-2.5){\makebox(0,0)[t]{\shortstack{Änderungen\\vorbehalten}}}
\end{picture}}
\lstdefinestyle{math}{basicstyle=\footnotesize\color{structure},
language={},
columns=fixed,
moredelim=**[is][\color{darkred}]{¡}{¿},
moredelim=**[is][\color{darkgreen}]{°}{¿}}
\title{Algorithmen und Datenstrukturen in C/C++}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{1.\ Juli 2019}
\begin{document}
\maketitleframe
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\item[\textbf{3}] \textbf{Datenorganisation}
\item[\textbf{4}] \textbf{Datenkodierung}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
\begin{itemize}
\color{red}
\item[5.1] Zeichnen von Linien
\item[5.2] CORDIC
\item[5.3] FFT
\end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
% \begin{itemize}
% \item Wegfindung, \dots
% \end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\setcounter{section}{4}
\section{Hardwarenahe Algorithmen}
\setcounter{subsection}{1}
\subsection{CORDIC}
\begin{frame}
\showsection
\showsubsection
Coordinate Rotation Digital Computer
\begin{itemize}
\item
Wie berechnet man einen Sinus?
\item
möglichst effizient
\item
möglichst viel in Hardware
\arrowitem
Drehmatrizen, Tabelle
\end{itemize}
\end{frame}
\subsection{FFT}
\begin{frame}
\showsection
\showsubsection
Fast Fourier Transform
\begin{itemize}
\item
Frequenzanalyse einer Funktion
\arrowitem
rekursiver Algorithmus
\item
Anwendung: Frequenzfilterung
\item
Anwendung: partielle Differentialgleichungen
\end{itemize}
\end{frame}
\begin{frame}
\showsubsection
\textbf{Anwendung: Frequenzanalyse}
Beispiel: Probleme bei Signalübertragung verstehen
\medskip
Amplitudenmodulation
\begin{center}
\includegraphics[width=12cm]{am.png}
\end{center}
\smallskip
Frequenzmodulation
\begin{center}
\includegraphics[width=12cm]{fm.png}
\end{center}
\smallskip
Phasenmodulation
\begin{center}
\includegraphics[width=12cm]{pm.png}
\end{center}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\textbf{Verschiedene Basen}
\medskip
\newcommand{\vect}[3]{\left(\begin{array}{c}#1\\#2\\#3\end{array}\right)}
\newcommand{\fvec}[1]{\left(\begin{array}{c}\begin{picture}(0.2,1)\hspace{-0.11cm}
\put(0.1,#1){\circle*{0.1}}
\end{picture}\hspace{-0.2cm}\end{array}\right)}
\newcommand{\fr}[2]{{\textstyle\frac{#1}{#2}}}
\begin{onlyenv}<1> % <1-6>
Vektoren in $\mathbb{R}^3$:
\begingroup
\footnotesize
\begin{displaymath}
2\vect101
+ 3\vect01{-1}
+ 5\vect{-1}10
=\vect{-3}8{-1} % \visible<2->{=\vect{-3}8{-1}}
\end{displaymath}
% \pause\pause
\begin{displaymath}
= -3\vect100 + 8\vect010 - 1\vect001
\end{displaymath}
\endgroup
\end{onlyenv}%
\begin{onlyenv}<2->
Funktion als Vektor:
% \alt<7->{\vspace{-0.8cm}}{\vspace{-0.1cm}}
\begin{center}
\begin{picture}(9,2)
\thicklines
\put(0,0){\line(3,2){3}}
\put(3,2){\line(3,-2){3}}
\put(6,0){\line(3,2){3}}
\end{picture}
\end{center}
\end{onlyenv}
\begin{onlyenv}<2>
\vspace{0.5cm}
\begin{quote}
\hspace{0.1cm}$=$\\[0.5cm]
\begin{rotate}{90}
\begin{minipage}[t]{2cm}
\small
\vspace{0.3cm}
\begin{displaymath}
\left(\begin{array}{c}
-1\\-0.75\\-0.5\\-0.25\\0\\0.25\\0.5\\0.75\\
1\\0.75\\0.5\\0.25\\0\\-0.25\\-0.5\\-0.75\\
-1\\-0.75\\-0.5\\-0.25\\0\\0.25\\0.5\\0.75\\
1
\end{array}\right)
\end{displaymath}
\end{minipage}
\end{rotate}
\end{quote}
\end{onlyenv}%
% \begin{onlyenv}<6->
% \begin{displaymath}
% = \fvec{0.0} + \fvec{0.3} + \fvec{0.6}
% + \fvec{0.9} + \fvec{0.6} + \fvec{0.3}
% + \fvec{0.0} + \fvec{0.3} + \fvec{0.6}
% + \fvec{0.9}
% \end{displaymath}
% \end{onlyenv}
\begin{onlyenv}<3->
\vspace{-0.3cm}
\begin{eqnarray*}
=&&\hspace{-0.75cm}
\begin{minipage}{10cm}
\begin{pdfpic}
\psset{unit=1pt}
\begin{pspicture}(0,0)(400,45)
\psplot[plotpoints=200]{0}{270}{x 2 mul cos -15 mul}
\end{pspicture}
\end{pdfpic}
\end{minipage}\\[-0.2cm]
+~\fr19&&\hspace{-0.75cm}
\begin{minipage}{10cm}
\begin{pdfpic}
\psset{unit=1pt}
\begin{pspicture}(0,0)(400,45)
\psplot[plotpoints=200]{0}{270}{x 6 mul cos -10 mul}
\end{pspicture}
\end{pdfpic}
\end{minipage}\\[-0.1cm]
+~\fr1{25}&&\hspace{-0.75cm}
\begin{minipage}{10cm}
\begin{pdfpic}
\psset{unit=1pt}
\begin{pspicture}(0,0)(400,45)
\psplot[plotpoints=200]{0}{270}{x 10 mul cos -5 mul}
\end{pspicture}
\end{pdfpic}
\end{minipage}\\
+~\fr1{49}&&\hspace{-0.5cm}\dots
% \hspace{7cm}\mbox{\visible<9->{\newterm{Fourier-Entwicklung}}}
\hspace{7cm}\mbox{\newterm{Fourier-Analyse}}
\end{eqnarray*}
\vspace{-0.3cm}
\end{onlyenv}
\end{frame}
\begin{frame}
\showsubsection
\textbf{Anwendung: Frequenzanalyse}
Beispiel: Probleme bei Signalübertragung verstehen
\medskip
Amplitudenmodulation
\begin{center}
\includegraphics[width=12cm]{am.png}
\end{center}
\smallskip
Frequenzmodulation
\begin{center}
\includegraphics[width=12cm]{fm.png}
\end{center}
\smallskip
Phasenmodulation
\begin{center}
\includegraphics[width=12cm]{pm.png}
\end{center}
\smallskip
\textarrow\ Der Übergang erzeugt Beiträge in ganz anderen Frequenzen!
\end{frame}
\begin{frame}
\showsubsection
\textbf{Anwendung: partielle Differentialgleichungen lösen}
Beispiel: Schrödinger-Gleichung
\begin{displaymath}
\textstyle
i \hbar \frac{\partial}{\partial t} \psi(x,t)
= - \frac{\hbar^2}{2m} \alt<2->{\,\frac{\partial^2}{\partial x^2}}{\nabla^2} \psi(x,t) + V(x,t)\,\psi(x,t)
\end{displaymath}
\pause[3]
Fouriertransformation:\\
Ableitung wird zu Multiplikation (und umgekehrt)
\begin{displaymath}
\textstyle
i \hbar \frac{\partial}{\partial t} \psi(p,t)
= \frac{p^2}{2m} \psi(x,t) + V\bigl(i\hbar\frac{\partial}{\partial p},t\bigr)\,\psi(p,t)
\end{displaymath}
\textarrow\ partielle wird zu gewöhnlicher Differentialgleichung\\
\textarrow\ mit Standardverfahren lösbar
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\item[\textbf{3}] \textbf{Datenorganisation}
\item[\textbf{4}] \textbf{Datenkodierung}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
\begin{itemize}
\color{medgreen}
\item[5.1] Zeichnen von Linien
\item[5.2] CORDIC
\item[5.3] FFT
\end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
% \begin{itemize}
% \item Wegfindung, \dots
% \end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\end{document}
20190701/am.png

2.69 KiB

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#define WIDTH 1024
#define HEIGHT 768
#define STEP 64
unsigned char *display_mem;
void clear_display (void)
{
for (int i = 0; i < WIDTH * HEIGHT / 8; i++)
display_mem[i] = 0;
}
void draw_point (int x, int y)
{
int i = y * WIDTH / 8;
i += x / 8;
display_mem[i] |= 1 << (7 - x % 8);
}
void draw_line (int x0, int y0, int x1, int y1)
{
int p = y1 - y0;
int q = x1 - x0;
int r = q / 2;
int y = y0;
for (int x = x0; x <= x1; x++)
{
draw_point (x, y);
r += p;
if (r >= q)
{
y++;
r -= q;
}
}
}
void draw_vertical_line (int x, int y0, int y1)
{
for (int y = y0; y <= y1; y++)
draw_point (x, y);
}
void draw_horizontal_line (int x0, int x1, int y)
{
for (int x = x0; x <= x1; x++)
draw_point (x, y);
}
void draw_circle (int x0, int y0, int r)
{
for (int x = x0 - r; x <= x0 + r; x++)
{
int y = y0 + sqrt (r * r - (x - x0) * (x - x0));
draw_point (x, y);
y = y0 - sqrt (r * r - (x - x0) * (x - x0));
draw_point (x, y);
}
}
void draw (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
clear_display ();
draw_circle (WIDTH / 2, HEIGHT / 2, WIDTH / 3);
glBitmap (WIDTH, HEIGHT, 0.0, 0.0, 0.0, 0.0, display_mem);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
display_mem = malloc (WIDTH * HEIGHT / 8);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (WIDTH, HEIGHT);
(void) glutCreateWindow ("Test");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#define WIDTH 1024
#define HEIGHT 768
#define STEP 64
unsigned char *display_mem;
void clear_display (void)
{
for (int i = 0; i < WIDTH * HEIGHT / 8; i++)
display_mem[i] = 0;
}
void draw_point (int x, int y)
{
int i = y * WIDTH / 8;
i += x / 8;
display_mem[i] |= 1 << (7 - x % 8);
}
void draw_line (int x0, int y0, int x1, int y1)
{
int p = y1 - y0;
int q = x1 - x0;
int r = q / 2;
int y = y0;
for (int x = x0; x <= x1; x++)
{
draw_point (x, y);
r += p;
if (r >= q)
{
y++;
r -= q;
}
}
}
void draw_vertical_line (int x, int y0, int y1)
{
for (int y = y0; y <= y1; y++)
draw_point (x, y);
}
void draw_horizontal_line (int x0, int x1, int y)
{
for (int x = x0; x <= x1; x++)
draw_point (x, y);
}
void draw_circle (int x0, int y0, int r)
{
int y = y0 + r;
for (int x = x0; x <= x0 + r; x++)
{
draw_point (x, y);
if ((x - x0) * (x - x0) + (y - y0) * (y - y0) > r * r)
y--;
}
// for (int x = x0 - r; x <= x0 + r; x++)
// {
// int y = y0 + sqrt (r * r - (x - x0) * (x - x0));
// draw_point (x, y);
// y = y0 - sqrt (r * r - (x - x0) * (x - x0));
// draw_point (x, y);
// }
}
void draw (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
clear_display ();
draw_circle (WIDTH / 2, HEIGHT / 2, WIDTH / 3);
glBitmap (WIDTH, HEIGHT, 0.0, 0.0, 0.0, 0.0, display_mem);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
display_mem = malloc (WIDTH * HEIGHT / 8);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (WIDTH, HEIGHT);
(void) glutCreateWindow ("Test");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#define WIDTH 1024
#define HEIGHT 768
#define STEP 64
unsigned char *display_mem;
void clear_display (void)
{
for (int i = 0; i < WIDTH * HEIGHT / 8; i++)
display_mem[i] = 0;
}
void draw_point (int x, int y)
{
int i = y * WIDTH / 8;
i += x / 8;
display_mem[i] |= 1 << (7 - x % 8);
}
void draw_line (int x0, int y0, int x1, int y1)
{
int p = y1 - y0;
int q = x1 - x0;
int r = q / 2;
int y = y0;
for (int x = x0; x <= x1; x++)
{
draw_point (x, y);
r += p;
if (r >= q)
{
y++;
r -= q;
}
}
}
void draw_vertical_line (int x, int y0, int y1)
{
for (int y = y0; y <= y1; y++)
draw_point (x, y);
}
void draw_horizontal_line (int x0, int x1, int y)
{
for (int x = x0; x <= x1; x++)
draw_point (x, y);
}
void draw_circle (int x0, int y0, int r)
{
int dy = r;
for (int dx = 0; dx <= r; dx++)
{
draw_point (x0 + dx, y0 - dy);
draw_point (x0 + dx, y0 + dy);
draw_point (x0 - dx, y0 - dy);
draw_point (x0 - dx, y0 + dy);
draw_point (x0 + dy, y0 - dx);
draw_point (x0 + dy, y0 + dx);
draw_point (x0 - dy, y0 - dx);
draw_point (x0 - dy, y0 + dx);
if (dx * dx + dy * dy > r * r)
dy--;
}
}
void draw (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
clear_display ();
draw_circle (WIDTH / 2, HEIGHT / 2, WIDTH / 3);
glBitmap (WIDTH, HEIGHT, 0.0, 0.0, 0.0, 0.0, display_mem);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
display_mem = malloc (WIDTH * HEIGHT / 8);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (WIDTH, HEIGHT);
(void) glutCreateWindow ("Test");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#define WIDTH 1024
#define HEIGHT 768
#define STEP 64
unsigned char *display_mem;
void clear_display (void)
{
for (int i = 0; i < WIDTH * HEIGHT / 8; i++)
display_mem[i] = 0;
}
void draw_point (int x, int y)
{
int i = y * WIDTH / 8;
i += x / 8;
display_mem[i] |= 1 << (7 - x % 8);
}
void draw_line (int x0, int y0, int x1, int y1)
{
int p = y1 - y0;
int q = x1 - x0;
int r = q / 2;
int y = y0;
for (int x = x0; x <= x1; x++)
{
draw_point (x, y);
r += p;
if (r >= q)
{
y++;
r -= q;
}
}
}
void draw_vertical_line (int x, int y0, int y1)
{
for (int y = y0; y <= y1; y++)
draw_point (x, y);
}
void draw_horizontal_line (int x0, int x1, int y)
{
for (int x = x0; x <= x1; x++)
draw_point (x, y);
}
void draw_circle (int x0, int y0, int r)
{
int dy = r;
int r2w2 = r * 141421 / 200000; // ~1/2 sqrt(2)
for (int dx = 0; dx <= r2w2; dx++)
{
draw_point (x0 + dx, y0 - dy);
draw_point (x0 + dx, y0 + dy);
draw_point (x0 - dx, y0 - dy);
draw_point (x0 - dx, y0 + dy);
draw_point (x0 + dy, y0 - dx);
draw_point (x0 + dy, y0 + dx);
draw_point (x0 - dy, y0 - dx);
draw_point (x0 - dy, y0 + dx);
if (dx * dx + dy * dy > r * r)
dy--;
}
}
void draw (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
clear_display ();
draw_circle (WIDTH / 2, HEIGHT / 2, WIDTH / 3);
glBitmap (WIDTH, HEIGHT, 0.0, 0.0, 0.0, 0.0, display_mem);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
display_mem = malloc (WIDTH * HEIGHT / 8);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (WIDTH, HEIGHT);
(void) glutCreateWindow ("Test");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#define WIDTH 1024
#define HEIGHT 768
#define STEP 64
unsigned char *display_mem;
void clear_display (void)
{
for (int i = 0; i < WIDTH * HEIGHT / 8; i++)
display_mem[i] = 0;
}
void draw_point (int x, int y)
{
int i = y * WIDTH / 8;
i += x / 8;
display_mem[i] |= 1 << (7 - x % 8);
}
void draw_line (int x0, int y0, int x1, int y1)
{
int p = y1 - y0;
int q = x1 - x0;
int r = q / 2;
int y = y0;
for (int x = x0; x <= x1; x++)
{
draw_point (x, y);
r += p;
if (r >= q)
{
y++;
r -= q;
}
}
}
void draw_vertical_line (int x, int y0, int y1)
{
for (int y = y0; y <= y1; y++)
draw_point (x, y);
}
void draw_horizontal_line (int x0, int x1, int y)
{
for (int x = x0; x <= x1; x++)
draw_point (x, y);
}
void draw_circle (int x0, int y0, int r)
{
int dy = r;
int dy2 = dy * dy;
int r2 = r * r;
int r2w2 = r * 141421 / 200000; // ~1/2 sqrt(2)
for (int dx = 0; dx <= r2w2; dx++)
{
draw_point (x0 + dx, y0 - dy);
draw_point (x0 + dx, y0 + dy);
draw_point (x0 - dx, y0 - dy);
draw_point (x0 - dx, y0 + dy);
draw_point (x0 + dy, y0 - dx);
draw_point (x0 + dy, y0 + dx);
draw_point (x0 - dy, y0 - dx);
draw_point (x0 - dy, y0 + dx);
if (dx * dx + dy2 > r2)
{
dy--;
dy2 = dy * dy;
}
}
}
void draw (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
clear_display ();
draw_circle (WIDTH / 2, HEIGHT / 2, WIDTH / 3);
glBitmap (WIDTH, HEIGHT, 0.0, 0.0, 0.0, 0.0, display_mem);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
display_mem = malloc (WIDTH * HEIGHT / 8);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (WIDTH, HEIGHT);
(void) glutCreateWindow ("Test");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>
#define WIDTH 1024
#define HEIGHT 768
#define STEP 64
unsigned char *display_mem;
void clear_display (void)
{
for (int i = 0; i < WIDTH * HEIGHT / 8; i++)
display_mem[i] = 0;
}
void draw_point (int x, int y)
{
int i = y * WIDTH / 8;
i += x / 8;
display_mem[i] |= 1 << (7 - x % 8);
}
void draw_line (int x0, int y0, int x1, int y1)
{
int p = y1 - y0;
int q = x1 - x0;
int r = q / 2;
int y = y0;
for (int x = x0; x <= x1; x++)
{
draw_point (x, y);
r += p;
if (r >= q)
{
y++;
r -= q;
}
}
}
void draw_vertical_line (int x, int y0, int y1)
{
for (int y = y0; y <= y1; y++)
draw_point (x, y);
}
void draw_horizontal_line (int x0, int x1, int y)
{
for (int x = x0; x <= x1; x++)
draw_point (x, y);
}
void draw_circle (int x0, int y0, int r)
{
int dy = r;
int dy2 = dy * dy;
int ddy2 = dy2 - (dy - 1) * (dy - 1);
int r2 = r * r;
int r2w2 = r * 141421 / 200000; // ~1/2 sqrt(2)
for (int dx = 0, dx2 = 0, ddx2 = 1; dx <= r2w2; dx++, dx2 += ddx2, ddx2 += 2)
{
draw_point (x0 + dx, y0 - dy);
draw_point (x0 + dx, y0 + dy);
draw_point (x0 - dx, y0 - dy);
draw_point (x0 - dx, y0 + dy);
draw_point (x0 + dy, y0 - dx);
draw_point (x0 + dy, y0 + dx);
draw_point (x0 - dy, y0 - dx);
draw_point (x0 - dy, y0 + dx);
if (dx2 + dy2 > r2)
{
dy--;
dy2 -= ddy2;
ddy2 -= 2;
}
}
}
void draw (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT);
clear_display ();
draw_circle (WIDTH / 2, HEIGHT / 2, WIDTH / 3);
glBitmap (WIDTH, HEIGHT, 0.0, 0.0, 0.0, 0.0, display_mem);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
display_mem = malloc (WIDTH * HEIGHT / 8);
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (WIDTH, HEIGHT);
(void) glutCreateWindow ("Test");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
//
// author="Tony Kirke"
// Copyright (c) 1993-1998 Tony Kirke
/*
* SPUC - Signal processing using C++ - A DSP library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <spuc.h>
#include <cordic.h>
namespace SPUC {
// allocates memory and determine arctans for use in the CORDIC algorithm
cordic::cordic(int n) {
int i;
stages = n;
arctan_lut = new double[stages+2];
stage = new complex<long>[stages+2];
for (i=0;i<=stages;i++) arctan_lut[i] = atan(1.0/(double)(1<<i));
}
// This routine performs multiple rotations of the form:
// x[i+1] = cos(angle[i]) { x[i] - y[i] tan(angle[i]) }
// y[i+1] = cos(angle[i]) { y[i] + x[i] tan(angle[i]) }
// where tan(angle[i]) = 2^-i, with i being an integer. Thus allowing
// implementation by shifting and adding (or subtracting).
// Each stage shifts by either a positive or negative angle.
complex <long> cordic::rotate(complex <long> in, double angle)
{
int i;
// Initial rotation, with left shift
if (angle > PI) {
stage[0].re = (-in.re << stages);
stage[0].im = (-in.im << stages);
angle -= PI;
} else {
stage[0] = in << stages;
}
if (angle > PI/2) {
stage[1].re = -stage[0].im;
stage[1].im = stage[0].re;
angle -= PI/2;
} else {
stage[1] = stage[0];
}
// Subsequent rotations, with right shifts
for (i=0;i<=stages;i++) {
long sign = (angle < 0) ? -1 : 1;
stage[i+2].re = stage[i+1].re - sign*(stage[i+1].im >>i);
stage[i+2].im = stage[i+1].im + sign*(stage[i+1].re >>i);
angle -= sign*arctan_lut[i];
}
return(stage[stages]);
}
// This routine performs multiple rotations of the form:
// x[i+1].re = { x[i].re -/+ x[i].im * tan(angle[i]) }
// x[i+1].im = { x[i].im +/- x[i].re * tan(angle[i]) }
// where tan(angle[i]) = 2^-i, with i being an integer.
// The -/+ is determined by the current SIGN of x[i].im
// in such a way that the angle of x[i] is reduced in
// each step. The final step will hold the approximation
// of the magnitude of x in the real part of x[stages].
complex<long> cordic::vector(complex<long> in)
{
int i;
// Rotate into 1st Quadrant
if (in.real()<0) {
if (in.imag()<0) {
stage[0] = -in << stages;
vector_angle = -PI;
} else {
stage[0].re = in.im << stages;
stage[0].im = -in.re << stages;
vector_angle = -PI/2;
}
} else {
if (in.imag()<0) {
stage[0].re = -in.im << stages;
stage[0].im = in.re << stages;
vector_angle = -3*PI/2;
} else {
stage[0] = in << stages;
vector_angle = 0;
}
}
// Subsequent rotations, with right shifts
for (i=0;i<stages;i++) {
long sign = (stage[i].im < 0) ? -1 : 1;
stage[i+1].re = stage[i].re - sign*(stage[i].im >>i);
stage[i+1].im = stage[i].im + sign*(stage[i].re >>i);
vector_angle -= sign*arctan_lut[i];
}
return(stage[stages].re);
}
} // namespace SPUC
//
// author="Tony Kirke"
// Copyright (c) 1993-1998 Tony Kirke
/*
* SPUC - Signal processing using C++ - A DSP library
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CRDC
#define CRDC
#include <math.h>
#include <complex.h>
namespace SPUC {
/*!
\addtogroup miscfunc Miscellaneous DSP classes
*/
/*!
\brief Cordic rotator
\ingroup miscfunc
*/
//!
//! Performs CORDIC rotations
//! To rotate a vector through an angle of theta, we calculate:
//!
//! x' = x cos(theta) - y sin(theta)
//! y' = x sin(theta) + y cos(theta)
//! Can be easily modified for hyperbolic and other functions
//! \image html cordic.gif
class cordic
{
public:
double* arctan_lut;
complex<long>* stage;
int stages;
double vector_angle;
//! initializes tables and constants for the CORDIC algorithm
cordic(int n=7);
//! Returns magnitude through CORDIC vectoring
long vector_mag(complex <long> in) {
vector(in);
}
//! Returns arg through CORDIC vectoring
double vector_arg(complex <long> in) {
vector(in);
return(vector_angle);
}
complex <long> rotate(complex <long> in, double angle);
protected:
//! Cordic vectoring calculates arg and magnitude
complex<long> vector(complex <long> in);
};
} // namespace SPUC
#endif
20190701/cordic.jpg

503 KiB

20190701/difference.png

86.3 KiB

/* FFT - Fast Fourier Transform
Copyright (C) 2012 Peter Gerwinski <http://www.peter.gerwinski.de>
This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <fftw3.h>
#define N 0x20000
int main (int argc, char **argv)
{
fftw_complex *audio_data = fftw_malloc (sizeof (fftw_complex) * N);
fftw_plan plan_forward = fftw_plan_dft_1d (N, audio_data, audio_data, FFTW_FORWARD, FFTW_MEASURE);
fftw_plan plan_backward = fftw_plan_dft_1d (N, audio_data, audio_data, FFTW_BACKWARD, FFTW_MEASURE);
FILE *f = fopen ("minutenwalzer-ausschnitt-mono.raw", "rb");
if (!f)
{
fprintf (stderr, "%s: could not open source file\n", argv[0]);
exit (1);
}
for (int i = 0; i < N; i++)
{
int16_t audio_value;
fread (&audio_value, sizeof (int16_t), 1, f);
audio_data[i][0] = audio_value / 32768.0;
audio_data[i][1] = 0.0;
}
fclose (f);
fftw_execute (plan_forward);
for (int i = 0; i < N; i++)
{
audio_data[i][0] *= sqrt (1.0 / N);
audio_data[i][1] *= sqrt (1.0 / N);
}
f = fopen ("minutenwalzer-ausschnitt-fft.raw", "wb");
if (!f)
{
fprintf (stderr, "%s: could not open destination file\n", argv[0]);
exit (1);
}
for (int i = 0; i < N; i++)
{
int j = i < N / 2 ? i + N / 2 : i - N / 2;
int16_t audio_value = audio_data[j][0] * 32768.0;
fwrite (&audio_value, sizeof (int16_t), 1, f);
}
fclose (f);
for (int i = 0; i < N * 985 / 2000; i++)
{
int j = N / 2 + i;
audio_data[j][0] = audio_data[j][1] = 0.0;
j = N / 2 - i - 1;
audio_data[j][0] = audio_data[j][1] = 0.0;
}
f = fopen ("minutenwalzer-ausschnitt-fft-tiefpass.raw", "wb");
if (!f)
{
fprintf (stderr, "%s: could not open destination file\n", argv[0]);
exit (1);
}
for (int i = 0; i < N; i++)
{
int j = i < N / 2 ? i + N / 2 : i - N / 2;
int16_t audio_value = audio_data[j][0] * 32768.0;
fwrite (&audio_value, sizeof (int16_t), 1, f);
}
fclose (f);
fftw_execute (plan_backward);
for (int i = 0; i < N; i++)
{
audio_data[i][0] *= 5.0 * sqrt (1.0 / N);
audio_data[i][1] *= 5.0 * sqrt (1.0 / N);
}
f = fopen ("minutenwalzer-ausschnitt-tiefpass.raw", "wb");
if (!f)
{
fprintf (stderr, "%s: could not open destination file\n", argv[0]);
exit (1);
}
for (int i = 0; i < N; i++)
{
int16_t audio_value = audio_data[i][0] * 32768.0;
fwrite (&audio_value, sizeof (int16_t), 1, f);
}
fclose (f);
fftw_destroy_plan (plan_forward);
fftw_destroy_plan (plan_backward);
fftw_free (audio_data);
}
20190701/fm.png

5.92 KiB

File added
File added
Dies ist ein - streng geheimer - Test.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment