OpenWareLaboratory
ComplexShortArray.h
Go to the documentation of this file.
1 #ifndef __ComplexShortArray_h__
2 #define __ComplexShortArray_h__
3 
4 #include "ShortArray.h"
5 
9 struct ComplexShort {
13  int16_t re;
14 
18  int16_t im;
19 
25  int16_t getMagnitude();
26 
32  int16_t getPhase();
33 
39  void setPhase(int16_t phase){
40  int16_t magnitude = getMagnitude();
41  setPolar(magnitude, phase);
42  }
43 
49  void setMagnitude(int16_t magnitude){
50  int16_t phase = getPhase();
51  setPolar(magnitude, phase);
52  }
53 
59  void setPolar(int16_t magnitude, int16_t phase);
60 
61  bool operator==(const ComplexShort& other) const {
62  return re == other.re && im == other.im;
63  }
64 
65  bool operator!=(const ComplexShort& other) const {
66  return re != other.re || im != other.im;
67  }
68 };
69 
70 class ComplexShortArray : public SimpleArray<ComplexShort> {
71 public:
74  SimpleArray(data, size) {}
75 
82  int16_t re(const int i){
83  return data[i].re;
84  }
85 
91  int16_t im(const int i){
92  return data[i].im;
93  }
94 
95  void clear(){
96  setAll(0);
97  }
98 
104  int16_t mag(const int i);
105 
110  void getMagnitudeValues(ShortArray destination);
111 
117  int16_t mag2(const int i);
118 
123  void getMagnitudeSquaredValues(ShortArray destination);
124 
130 
137 
144 
151 
158  void add(ComplexShortArray operand2, ComplexShortArray destination);
159 
165  void add(ComplexShortArray operand2);
166 
173  void subtract(ComplexShortArray operand2, ComplexShortArray destination);
174 
180  void subtract(ComplexShortArray operand2);
181 
187 
192  unsigned int getMaxMagnitudeIndex();
193 
205  ComplexShortArray subArray(unsigned int offset, unsigned int length);
206 
211 
216 
220  void scale(int16_t factor);
221 
229  static ComplexShortArray create(unsigned int size);
230 
237  static void destroy(ComplexShortArray);
238 
243  void setAll(ComplexShort value);
244 
249  void setAll(int16_t value);
250 
256  void setAll(int16_t valueRe, int16_t valueIm);
257 
263  void setPolar(ShortArray magnitude, ShortArray phase);
264 
272  void setPolar(ShortArray magnitude, ShortArray phase, int offset, int count);
273 
278  void setPhase(ShortArray phase);
279 
286  void setPhase(ShortArray phase, int offset, int count);
287 
293  void setPhase(ShortArray phase, ComplexShortArray destination);
294 
305  void setPhase(ShortArray phase, int offset, int count, ComplexShortArray destination);
306 
307 
312  void setMagnitude(ShortArray magnitude);
313 
320  void setMagnitude(ShortArray magnitude, int offset, int count);
321 
327  void setMagnitude(ShortArray magnitude, ComplexShortArray destination);
328 
339  void setMagnitude(ShortArray magnitude, int offset, int count, ComplexShortArray destination);
340 };
341 #endif // __ComplexShortArray_h__
void getComplexConjugateValues(ComplexShortArray destination)
The complex conjugate values of the element of the array.
int16_t mag(const int i)
The magnitude of an element of the array.
void subtract(ComplexShortArray operand2)
In-place element-wise difference between complex arrays.
void setPhase(ShortArray phase)
Set the phase of the elements of the array, leaving the magnitude unchanged.
void setPhase(ShortArray phase, int offset, int count)
Set the phase of a range of elements of the array, leaving the magnitude unchanged.
int16_t im(const int i)
The imaginary part of an element of the array.
void getRealValues(ShortArray buf)
Get the real part of the elements of the array.
void setPhase(ShortArray phase, ComplexShortArray destination)
Set the phase of the elements of an array, using the magnitude from the current array.
void add(ComplexShortArray operand2, ComplexShortArray destination)
Element-wise sum between complex arrays.
void complexByComplexMultiplication(ComplexShortArray operand2, ComplexShortArray result)
Complex by complex multiplication between arrays.
static ComplexShortArray create(unsigned int size)
Creates a new ComplexShortArray.
ComplexShortArray subArray(unsigned int offset, unsigned int length)
A subset of the array.
void setMagnitude(ShortArray magnitude, int offset, int count, ComplexShortArray destination)
Set the magnitude of a range of the elements of an array, using the phases from the current array.
void complexDotProduct(ComplexShortArray operand2, ComplexShort &result)
Complex dot product between arrays.
void subtract(ComplexShortArray operand2, ComplexShortArray destination)
Element-wise difference between complex arrays.
void add(ComplexShortArray operand2)
In-place element-wise sum between complex arrays.
ComplexShortArray(ComplexShort *data, size_t size)
void setMagnitude(ShortArray magnitude, int offset, int count)
Set the magnitude of a range of elements of the array, leaving the phase unchanged.
void setMagnitude(ShortArray magnitude, ComplexShortArray destination)
Set the magnitude of the elements of an array, using the phase from the current array.
int16_t getMaxMagnitudeValue()
The value of the element with the maximum magnitude in the array.
void getMagnitudeSquaredValues(ShortArray destination)
The squared magnitudes of the elements of the array.
void scale(int16_t factor)
Array by scalar multiplication.
int16_t mag2(const int i)
The magnitude squared of an element of the array.
unsigned int getMaxMagnitudeIndex()
The index of the element with the maximum magnitude in the array.
void getImaginaryValues(ShortArray buf)
Get the imaginary part of the elements of the array.
void complexByRealMultiplication(ShortArray operand2, ComplexShortArray result)
Complex by real multiplication between arrays.
void setPolar(ShortArray magnitude, ShortArray phase, int offset, int count)
Set a range of elements in the array using polar coordinates.
void setPolar(ShortArray magnitude, ShortArray phase)
Set all the elements in the array using polar coordinates.
static void destroy(ComplexShortArray)
Destroys a ComplexShortArray created with the create() method.
void getMagnitudeValues(ShortArray destination)
The magnitudes of the elements of the array.
int16_t re(const int i)
The real part of an element of the array.
void setMagnitude(ShortArray magnitude)
Set the magnitude of the elements of the array, leaving the phase unchanged.
void setPhase(ShortArray phase, int offset, int count, ComplexShortArray destination)
Set the phase of a range of the elements of an array, using the magnitude from the current array.
void setAll(ComplexShort value)
Set all the elements in the array.
This class contains useful methods for manipulating arrays of int16_ts.
Definition: ShortArray.h:12
SimpleArray holds a pointer to an array and the array size, and is designed to be passed by value.
Definition: SimpleArray.h:14
A structure defining a fixed point complex number as two members of type int16_t.
bool operator!=(const ComplexShort &other) const
void setPhase(int16_t phase)
Set the phase of the complex number.
void setPolar(int16_t magnitude, int16_t phase)
Set magnitude and phase of the complex number.
int16_t re
The real part of the complex number.
int16_t getMagnitude()
Get the magnitude of the complex number.
int16_t getPhase()
Get the phase of the complex number.
void setMagnitude(int16_t magnitude)
Set the magnitude of the complex number.
int16_t im
The imaginary part of the complex number.
bool operator==(const ComplexShort &other) const