oldexamplecode
Dependencies: mbed
complexmath.h@0:6863633bf8a4, 2017-03-24 (annotated)
- Committer:
- rik
- Date:
- Fri Mar 24 11:22:30 2017 +0000
- Revision:
- 0:6863633bf8a4
oldexamplecode;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rik | 0:6863633bf8a4 | 1 | |
rik | 0:6863633bf8a4 | 2 | // This file contains an implementation of complex mathmatics |
rik | 0:6863633bf8a4 | 3 | // i.e. definition of a complex unit and basic operationds such as magnitude, phase, addition and multiplication |
rik | 0:6863633bf8a4 | 4 | |
rik | 0:6863633bf8a4 | 5 | #pragma once |
rik | 0:6863633bf8a4 | 6 | #ifndef _COMPLEX_MATH_H |
rik | 0:6863633bf8a4 | 7 | #define _COMPLEX_MATH_H |
rik | 0:6863633bf8a4 | 8 | |
rik | 0:6863633bf8a4 | 9 | #include "LookupTables.h" |
rik | 0:6863633bf8a4 | 10 | #include <math.h> // only for sqrt, not for cos sin |
rik | 0:6863633bf8a4 | 11 | |
rik | 0:6863633bf8a4 | 12 | struct complex_num{ |
rik | 0:6863633bf8a4 | 13 | float imaginary; |
rik | 0:6863633bf8a4 | 14 | float real; |
rik | 0:6863633bf8a4 | 15 | }; |
rik | 0:6863633bf8a4 | 16 | |
rik | 0:6863633bf8a4 | 17 | // Complex adition and multiplication |
rik | 0:6863633bf8a4 | 18 | complex_num complex_add(complex_num A, complex_num B); |
rik | 0:6863633bf8a4 | 19 | complex_num complex_multiply(complex_num A, complex_num B); |
rik | 0:6863633bf8a4 | 20 | |
rik | 0:6863633bf8a4 | 21 | // Retrieve the phase and magnitude of a complex number (polar form) |
rik | 0:6863633bf8a4 | 22 | float complex_phase(complex_num A); |
rik | 0:6863633bf8a4 | 23 | float complex_magnitude(complex_num A); |
rik | 0:6863633bf8a4 | 24 | |
rik | 0:6863633bf8a4 | 25 | // Transform polar form to a complex number (phase in radians) |
rik | 0:6863633bf8a4 | 26 | complex_num complex_transform(float phase, float magnitude); |
rik | 0:6863633bf8a4 | 27 | |
rik | 0:6863633bf8a4 | 28 | // Complex conjugate |
rik | 0:6863633bf8a4 | 29 | complex_num complex_conjugate(complex_num A); |
rik | 0:6863633bf8a4 | 30 | |
rik | 0:6863633bf8a4 | 31 | #endif |