|
3 | 3 |
|
4 | 4 | #include "FloatArray.h" |
5 | 5 | #include "basicmaths.h" |
6 | | - |
| 6 | +/** |
| 7 | +* A structure defining a floating point complex number as two members of type float. |
| 8 | +*/ |
7 | 9 | struct ComplexFloat { |
| 10 | + /** |
| 11 | + The real part of the complex number. |
| 12 | + */ |
8 | 13 | float re; |
| 14 | + |
| 15 | + /** |
| 16 | + The imaginary part of the complex number. |
| 17 | + */ |
9 | 18 | float im; |
| 19 | + |
| 20 | + /** |
| 21 | + Get the magnitude of the complex number. |
| 22 | + Computes and returns the magnitude of the complex number. |
| 23 | + @return The magnitude of the complex number. |
| 24 | + */ |
10 | 25 | float getMagnitude(){ |
11 | 26 | return sqrtf(re*re+im*im); |
12 | 27 | } |
| 28 | + |
| 29 | + /** |
| 30 | + Get the phase of the complex number. |
| 31 | + Computes and returns the phase of the complex number. |
| 32 | + @return The phase of the complex number. |
| 33 | + */ |
13 | 34 | float getPhase(){ |
14 | 35 | return atan2(im,re); |
15 | 36 | } |
| 37 | + |
| 38 | + /** |
| 39 | + Set the phase of the complex number. |
| 40 | + Set the phase of the complex number, keeping the magnitude unaltered. |
| 41 | + @param phase The new phase of the complex number |
| 42 | + */ |
16 | 43 | void setPhase(float phase){ |
17 | 44 | float magnitude=getMagnitude(); |
18 | 45 | setPolar(magnitude, phase); |
19 | 46 | } |
| 47 | + |
| 48 | + /** |
| 49 | + Set the magnitude of the complex number. |
| 50 | + Set the magnitude of the complex number, keeping the phase unaltered. |
| 51 | + @param magnitude The new magnitude of the complex number |
| 52 | + */ |
20 | 53 | void setMagnitude(float magnitude){ |
21 | 54 | float phase=getPhase(); |
22 | 55 | setPolar(magnitude, phase); |
23 | 56 | } |
| 57 | + |
| 58 | + |
| 59 | + /** |
| 60 | + Set magnitude and phase of the complex number. |
| 61 | + @param magnitude The new magnitude of the complex number |
| 62 | + @param phase The new phase of the complex number |
| 63 | + */ |
24 | 64 | void setPolar(float magnitude, float phase){ |
25 | 65 | re=magnitude*cosf(phase); |
26 | 66 | im=magnitude*sinf(phase); |
|
0 commit comments