BGC Tools
Static Public Member Functions | Static Private Member Functions | Private Attributes
BGC.Mathematics.Fourier Class Reference

Support for Fourier Transforms. Borrows heavily from Mathnet.Numerics. More...

Collaboration diagram for BGC.Mathematics.Fourier:
Collaboration graph
[legend]

Static Public Member Functions

static void Forward (Complex32[] samples)
 
static void Inverse (Complex32[] spectrum)
 
static void Forward (Complex64[] samples)
 
static void Inverse (Complex64[] spectrum)
 

Static Private Member Functions

static void Radix2ForwardParallel (Complex32[] data)
 Radix-2 generic FFT for power-of-two sample vectors (Parallel Version). More...
 
static void Radix2InverseParallel (Complex32[] data)
 Radix-2 generic FFT for power-of-two sample vectors (Parallel Version). More...
 
static void Radix2Forward (Complex32[] data)
 Radix-2 generic FFT for power-of-two sized sample vectors. More...
 
static void Radix2Inverse (Complex32[] data)
 Radix-2 generic FFT for power-of-two sized sample vectors. More...
 
static void Radix2Reorder (Complex32[] samples)
 Radix-2 Reorder Helper Method More...
 
static void Radix2Step (Complex32[] samples, int exponentSign, int levelSize, int k)
 Radix-2 Step Helper Method More...
 
static void BluesteinForward (Complex32[] samples)
 
static void BluesteinInverse (Complex32[] spectrum)
 Bluestein generic FFT for arbitrary sized sample vectors. More...
 
static Complex32 [] BluesteinSequence32 (int n)
 Generate the bluestein sequence for the provided problem size. More...
 
static void Radix2ForwardParallel (Complex64[] data)
 Radix-2 generic FFT for power-of-two sample vectors (Parallel Version). More...
 
static void Radix2InverseParallel (Complex64[] data)
 Radix-2 generic FFT for power-of-two sample vectors (Parallel Version). More...
 
static void Radix2Forward (Complex64[] data)
 Radix-2 generic FFT for power-of-two sized sample vectors. More...
 
static void Radix2Inverse (Complex64[] data)
 Radix-2 generic FFT for power-of-two sized sample vectors. More...
 
static void Radix2Reorder (Complex64[] samples)
 Radix-2 Reorder Helper Method More...
 
static void Radix2Step (Complex64[] samples, int exponentSign, int levelSize, int k)
 Radix-2 Step Helper Method More...
 
static void BluesteinForward (Complex64[] samples)
 
static void BluesteinInverse (Complex64[] spectrum)
 Bluestein generic FFT for arbitrary sized sample vectors. More...
 
static Complex64 [] BluesteinSequence64 (int n)
 Generate the bluestein sequence for the provided problem size. More...
 
static void Rescale (Complex32[] samples)
 Fully rescale the FFT result. More...
 
static void Rescale (Complex64[] samples)
 Fully rescale the FFT result. More...
 
static void SwapRealImaginary (Complex32[] samples)
 Swap the real and imaginary parts of each sample. More...
 
static void SwapRealImaginary (Complex64[] samples)
 Swap the real and imaginary parts of each sample. More...
 

Private Attributes

const int BluesteinSequenceLengthThreshold = 46341
 Sequences with length greater than Math.Sqrt(Int32.MaxValue) + 1 will cause k*k in the Bluestein sequence to overflow (GH-286). More...
 

Detailed Description

Support for Fourier Transforms. Borrows heavily from Mathnet.Numerics.

Definition at line 41 of file Fourier.cs.

Member Function Documentation

◆ BluesteinForward() [1/2]

static void BGC.Mathematics.Fourier.BluesteinForward ( Complex32 []  samples)
inlinestaticprivate

Definition at line 250 of file Fourier.cs.

References BGC.Mathematics.Complex32.Conjugate().

251  {
252  int n = samples.Length;
253  Complex32[] sequence = BluesteinSequence32(n);
254 
255  // Padding to power of two >= 2N–1 so we can apply Radix-2 FFT.
256  int m = ((n << 1) - 1).CeilingToPowerOfTwo();
257  Complex32[] b = new Complex32[m];
258  Complex32[] a = new Complex32[m];
259 
260  CommonParallel.Invoke(
261  () =>
262  {
263  // Build and transform padded sequence b_k = exp(I*Pi*k^2/N)
264  for (int i = 0; i < n; i++)
265  {
266  b[i] = sequence[i];
267  }
268 
269  for (int i = m - n + 1; i < b.Length; i++)
270  {
271  b[i] = sequence[m - i];
272  }
273 
274  Radix2Forward(b);
275  },
276  () =>
277  {
278  // Build and transform padded sequence a_k = x_k * exp(-I*Pi*k^2/N)
279  for (int i = 0; i < samples.Length; i++)
280  {
281  a[i] = sequence[i].Conjugate() * samples[i];
282  }
283 
284  Radix2Forward(a);
285  });
286 
287  for (int i = 0; i < a.Length; i++)
288  {
289  a[i] *= b[i];
290  }
291 
293 
294  float nbinv = 1.0f / m;
295  for (int i = 0; i < samples.Length; i++)
296  {
297  samples[i] = nbinv * sequence[i].Conjugate() * a[i];
298  }
299  }
static Complex32 [] BluesteinSequence32(int n)
Generate the bluestein sequence for the provided problem size.
Definition: Fourier.cs:322
static void Radix2InverseParallel(Complex32[] data)
Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).
Definition: Fourier.cs:152
static void Radix2Forward(Complex32[] data)
Radix-2 generic FFT for power-of-two sized sample vectors.
Definition: Fourier.cs:172
Here is the call graph for this function:

◆ BluesteinForward() [2/2]

static void BGC.Mathematics.Fourier.BluesteinForward ( Complex64 []  samples)
inlinestaticprivate

Definition at line 470 of file Fourier.cs.

References BGC.Mathematics.Complex64.Conjugate().

471  {
472  int n = samples.Length;
473  Complex64[] sequence = BluesteinSequence64(n);
474 
475  // Padding to power of two >= 2N–1 so we can apply Radix-2 FFT.
476  int m = ((n << 1) - 1).CeilingToPowerOfTwo();
477  Complex64[] b = new Complex64[m];
478  Complex64[] a = new Complex64[m];
479 
480  CommonParallel.Invoke(
481  () =>
482  {
483  // Build and transform padded sequence b_k = exp(I*Pi*k^2/N)
484  for (int i = 0; i < n; i++)
485  {
486  b[i] = sequence[i];
487  }
488 
489  for (int i = m - n + 1; i < b.Length; i++)
490  {
491  b[i] = sequence[m - i];
492  }
493 
494  Radix2Forward(b);
495  },
496  () =>
497  {
498  // Build and transform padded sequence a_k = x_k * exp(-I*Pi*k^2/N)
499  for (int i = 0; i < samples.Length; i++)
500  {
501  a[i] = sequence[i].Conjugate() * samples[i];
502  }
503 
504  Radix2Forward(a);
505  });
506 
507  for (int i = 0; i < a.Length; i++)
508  {
509  a[i] *= b[i];
510  }
511 
513 
514  float nbinv = 1.0f / m;
515  for (int i = 0; i < samples.Length; i++)
516  {
517  samples[i] = nbinv * sequence[i].Conjugate() * a[i];
518  }
519  }
static Complex64 [] BluesteinSequence64(int n)
Generate the bluestein sequence for the provided problem size.
Definition: Fourier.cs:536
static void Radix2InverseParallel(Complex32[] data)
Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).
Definition: Fourier.cs:152
static void Radix2Forward(Complex32[] data)
Radix-2 generic FFT for power-of-two sized sample vectors.
Definition: Fourier.cs:172
Here is the call graph for this function:

◆ BluesteinInverse() [1/2]

static void BGC.Mathematics.Fourier.BluesteinInverse ( Complex32 []  spectrum)
inlinestaticprivate

Bluestein generic FFT for arbitrary sized sample vectors.

Definition at line 304 of file Fourier.cs.

305  {
306  SwapRealImaginary(spectrum);
307  BluesteinForward(spectrum);
308  SwapRealImaginary(spectrum);
309  }
static void SwapRealImaginary(Complex32[] samples)
Swap the real and imaginary parts of each sample.
Definition: Fourier.cs:591
static void BluesteinForward(Complex32[] samples)
Definition: Fourier.cs:250

◆ BluesteinInverse() [2/2]

static void BGC.Mathematics.Fourier.BluesteinInverse ( Complex64 []  spectrum)
inlinestaticprivate

Bluestein generic FFT for arbitrary sized sample vectors.

Definition at line 524 of file Fourier.cs.

525  {
526  SwapRealImaginary(spectrum);
527  BluesteinForward(spectrum);
528  SwapRealImaginary(spectrum);
529  }
static void SwapRealImaginary(Complex32[] samples)
Swap the real and imaginary parts of each sample.
Definition: Fourier.cs:591
static void BluesteinForward(Complex32[] samples)
Definition: Fourier.cs:250

◆ BluesteinSequence32()

static Complex32 [] BGC.Mathematics.Fourier.BluesteinSequence32 ( int  n)
inlinestaticprivate

Generate the bluestein sequence for the provided problem size.

Parameters
nNumber of samples.
Returns
Bluestein sequence exp(I*Pi*k^2/N)

Definition at line 322 of file Fourier.cs.

323  {
324  float s = Mathf.PI / n;
325  Complex32[] sequence = new Complex32[n];
326 
327  // TODO: benchmark whether the second variation is significantly
328  // faster than the former one. If not just use the former one always.
330  {
331  for (int k = 0; k < sequence.Length; k++)
332  {
333  float t = (s * k) * k;
334  sequence[k] = new Complex32(Mathf.Cos(t), Mathf.Sin(t));
335  }
336  }
337  else
338  {
339  for (int k = 0; k < sequence.Length; k++)
340  {
341  float t = s * (k * k);
342  sequence[k] = new Complex32(Mathf.Cos(t), Mathf.Sin(t));
343  }
344  }
345 
346  return sequence;
347  }
const int BluesteinSequenceLengthThreshold
Sequences with length greater than Math.Sqrt(Int32.MaxValue) + 1 will cause k*k in the Bluestein sequ...
Definition: Fourier.cs:315

◆ BluesteinSequence64()

static Complex64 [] BGC.Mathematics.Fourier.BluesteinSequence64 ( int  n)
inlinestaticprivate

Generate the bluestein sequence for the provided problem size.

Parameters
nNumber of samples.
Returns
Bluestein sequence exp(I*Pi*k^2/N)

Definition at line 536 of file Fourier.cs.

537  {
538  float s = Mathf.PI / n;
539  Complex64[] sequence = new Complex64[n];
540 
541  // TODO: benchmark whether the second variation is significantly
542  // faster than the former one. If not just use the former one always.
544  {
545  for (int k = 0; k < sequence.Length; k++)
546  {
547  float t = (s * k) * k;
548  sequence[k] = new Complex64(Mathf.Cos(t), Mathf.Sin(t));
549  }
550  }
551  else
552  {
553  for (int k = 0; k < sequence.Length; k++)
554  {
555  float t = s * (k * k);
556  sequence[k] = new Complex64(Mathf.Cos(t), Mathf.Sin(t));
557  }
558  }
559 
560  return sequence;
561  }
const int BluesteinSequenceLengthThreshold
Sequences with length greater than Math.Sqrt(Int32.MaxValue) + 1 will cause k*k in the Bluestein sequ...
Definition: Fourier.cs:315

◆ Forward() [1/2]

static void BGC.Mathematics.Fourier.Forward ( Complex32 []  samples)
inlinestatic

Definition at line 43 of file Fourier.cs.

Referenced by BGC.Audio.Filters.CarlileShuffler._Initialize(), BGC.Audio.Filters.ConvolutionFilter._Initialize(), BGC.Audio.Filters.MultiConvolutionFilter._Initialize(), BGC.Audio.Visualization.Spectrogram.Decompose(), BGC.Audio.Filters.PhaseVocoder.Read(), BGC.Audio.Filters.ConvolutionFilter.Read(), BGC.Audio.Filters.FramedPhaseReencoder.Read(), BGC.Audio.Filters.MultiConvolutionFilter.Read(), BGC.Tests.TestOverlapAdd.TestNewFFTs(), and BGC.Audio.Filters.SinglePassPhaseReencoder.TimeShift().

44  {
45  if (samples.Length.IsPowerOfTwo())
46  {
47  if (samples.Length >= 1024)
48  {
49  Radix2ForwardParallel(samples);
50  }
51  else
52  {
53  Radix2Forward(samples);
54  }
55  }
56  else
57  {
58  BluesteinForward(samples);
59  }
60 
61  Rescale(samples);
62  }
static void Radix2ForwardParallel(Complex32[] data)
Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).
Definition: Fourier.cs:132
static void Rescale(Complex32[] samples)
Fully rescale the FFT result.
Definition: Fourier.cs:566
static void BluesteinForward(Complex32[] samples)
Definition: Fourier.cs:250
static void Radix2Forward(Complex32[] data)
Radix-2 generic FFT for power-of-two sized sample vectors.
Definition: Fourier.cs:172
Here is the caller graph for this function:

◆ Forward() [2/2]

static void BGC.Mathematics.Fourier.Forward ( Complex64 []  samples)
inlinestatic

Definition at line 86 of file Fourier.cs.

87  {
88  if (samples.Length.IsPowerOfTwo())
89  {
90  if (samples.Length >= 1024)
91  {
92  Radix2ForwardParallel(samples);
93  }
94  else
95  {
96  Radix2Forward(samples);
97  }
98  }
99  else
100  {
101  BluesteinForward(samples);
102  }
103 
104  Rescale(samples);
105  }
static void Radix2ForwardParallel(Complex32[] data)
Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).
Definition: Fourier.cs:132
static void Rescale(Complex32[] samples)
Fully rescale the FFT result.
Definition: Fourier.cs:566
static void BluesteinForward(Complex32[] samples)
Definition: Fourier.cs:250
static void Radix2Forward(Complex32[] data)
Radix-2 generic FFT for power-of-two sized sample vectors.
Definition: Fourier.cs:172

◆ Inverse() [1/2]

static void BGC.Mathematics.Fourier.Inverse ( Complex32 []  spectrum)
inlinestatic

Definition at line 64 of file Fourier.cs.

Referenced by BGC.Audio.Filters.CarlileShuffler._Initialize(), BGC.Audio.Synthesis.NoiseAudioClip._Initialize(), BGC.Audio.Synthesis.STMAudioClip._Initialize(), BGC.Audio.AnalyticStreams.AnalyticNoiseStream.Initialize(), BGC.Audio.Synthesis.FrequencyDomainToneComposer.Read(), BGC.Audio.Filters.PhaseVocoder.Read(), BGC.Audio.Filters.ConvolutionFilter.Read(), BGC.Audio.Filters.FramedPhaseReencoder.Read(), BGC.Audio.Filters.MultiConvolutionFilter.Read(), BGC.Tests.TestOverlapAdd.TestNewFFTs(), and BGC.Audio.Filters.SinglePassPhaseReencoder.TimeShift().

65  {
66  if (spectrum.Length.IsPowerOfTwo())
67  {
68  if (spectrum.Length >= 1024)
69  {
70  Radix2InverseParallel(spectrum);
71  }
72  else
73  {
74  Radix2Inverse(spectrum);
75  }
76  }
77  else
78  {
79  BluesteinInverse(spectrum);
80  }
81 
82  //Asymmetrical rescaling...
83  //Rescale(spectrum);
84  }
static void Radix2InverseParallel(Complex32[] data)
Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).
Definition: Fourier.cs:152
static void Radix2Inverse(Complex32[] data)
Radix-2 generic FFT for power-of-two sized sample vectors.
Definition: Fourier.cs:187
static void BluesteinInverse(Complex32[] spectrum)
Bluestein generic FFT for arbitrary sized sample vectors.
Definition: Fourier.cs:304
Here is the caller graph for this function:

◆ Inverse() [2/2]

static void BGC.Mathematics.Fourier.Inverse ( Complex64 []  spectrum)
inlinestatic

Definition at line 107 of file Fourier.cs.

108  {
109  if (spectrum.Length.IsPowerOfTwo())
110  {
111  if (spectrum.Length >= 1024)
112  {
113  Radix2InverseParallel(spectrum);
114  }
115  else
116  {
117  Radix2Inverse(spectrum);
118  }
119  }
120  else
121  {
122  BluesteinInverse(spectrum);
123  }
124 
125  //Asymmetrical rescaling...
126  //Rescale(spectrum);
127  }
static void Radix2InverseParallel(Complex32[] data)
Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).
Definition: Fourier.cs:152
static void Radix2Inverse(Complex32[] data)
Radix-2 generic FFT for power-of-two sized sample vectors.
Definition: Fourier.cs:187
static void BluesteinInverse(Complex32[] spectrum)
Bluestein generic FFT for arbitrary sized sample vectors.
Definition: Fourier.cs:304

◆ Radix2Forward() [1/2]

static void BGC.Mathematics.Fourier.Radix2Forward ( Complex32 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sized sample vectors.

Definition at line 172 of file Fourier.cs.

173  {
174  Radix2Reorder(data);
175  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
176  {
177  for (int k = 0; k < levelSize; k++)
178  {
179  Radix2Step(data, -1, levelSize, k);
180  }
181  }
182  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2Forward() [2/2]

static void BGC.Mathematics.Fourier.Radix2Forward ( Complex64 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sized sample vectors.

Definition at line 393 of file Fourier.cs.

394  {
395  Radix2Reorder(data);
396  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
397  {
398  for (int k = 0; k < levelSize; k++)
399  {
400  Radix2Step(data, -1, levelSize, k);
401  }
402  }
403  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2ForwardParallel() [1/2]

static void BGC.Mathematics.Fourier.Radix2ForwardParallel ( Complex32 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).

Definition at line 132 of file Fourier.cs.

133  {
134  Radix2Reorder(data);
135  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
136  {
137  int size = levelSize;
138 
139  CommonParallel.For(0, size, 64, (u, v) =>
140  {
141  for (int i = u; i < v; i++)
142  {
143  Radix2Step(data, -1, size, i);
144  }
145  });
146  }
147  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2ForwardParallel() [2/2]

static void BGC.Mathematics.Fourier.Radix2ForwardParallel ( Complex64 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).

Definition at line 353 of file Fourier.cs.

354  {
355  Radix2Reorder(data);
356  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
357  {
358  int size = levelSize;
359 
360  CommonParallel.For(0, size, 64, (u, v) =>
361  {
362  for (int i = u; i < v; i++)
363  {
364  Radix2Step(data, -1, size, i);
365  }
366  });
367  }
368  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2Inverse() [1/2]

static void BGC.Mathematics.Fourier.Radix2Inverse ( Complex32 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sized sample vectors.

Definition at line 187 of file Fourier.cs.

188  {
189  Radix2Reorder(data);
190  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
191  {
192  for (int k = 0; k < levelSize; k++)
193  {
194  Radix2Step(data, 1, levelSize, k);
195  }
196  }
197  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2Inverse() [2/2]

static void BGC.Mathematics.Fourier.Radix2Inverse ( Complex64 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sized sample vectors.

Definition at line 408 of file Fourier.cs.

409  {
410  Radix2Reorder(data);
411  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
412  {
413  for (int k = 0; k < levelSize; k++)
414  {
415  Radix2Step(data, 1, levelSize, k);
416  }
417  }
418  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2InverseParallel() [1/2]

static void BGC.Mathematics.Fourier.Radix2InverseParallel ( Complex32 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).

Definition at line 152 of file Fourier.cs.

153  {
154  Radix2Reorder(data);
155  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
156  {
157  int size = levelSize;
158 
159  CommonParallel.For(0, size, 64, (u, v) =>
160  {
161  for (int i = u; i < v; i++)
162  {
163  Radix2Step(data, 1, size, i);
164  }
165  });
166  }
167  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2InverseParallel() [2/2]

static void BGC.Mathematics.Fourier.Radix2InverseParallel ( Complex64 []  data)
inlinestaticprivate

Radix-2 generic FFT for power-of-two sample vectors (Parallel Version).

Definition at line 373 of file Fourier.cs.

374  {
375  Radix2Reorder(data);
376  for (int levelSize = 1; levelSize < data.Length; levelSize *= 2)
377  {
378  int size = levelSize;
379 
380  CommonParallel.For(0, size, 64, (u, v) =>
381  {
382  for (int i = u; i < v; i++)
383  {
384  Radix2Step(data, 1, size, i);
385  }
386  });
387  }
388  }
static void Radix2Reorder(Complex32[] samples)
Radix-2 Reorder Helper Method
Definition: Fourier.cs:202
static void Radix2Step(Complex32[] samples, int exponentSign, int levelSize, int k)
Radix-2 Step Helper Method
Definition: Fourier.cs:233

◆ Radix2Reorder() [1/2]

static void BGC.Mathematics.Fourier.Radix2Reorder ( Complex32 []  samples)
inlinestaticprivate

Radix-2 Reorder Helper Method

Definition at line 202 of file Fourier.cs.

203  {
204  int j = 0;
205  for (int i = 0; i < samples.Length - 1; i++)
206  {
207  if (i < j)
208  {
209  Complex32 temp = samples[i];
210  samples[i] = samples[j];
211  samples[j] = temp;
212  }
213 
214  int m = samples.Length;
215 
216  do
217  {
218  m >>= 1;
219  j ^= m;
220  }
221  while ((j & m) == 0);
222  }
223  }

◆ Radix2Reorder() [2/2]

static void BGC.Mathematics.Fourier.Radix2Reorder ( Complex64 []  samples)
inlinestaticprivate

Radix-2 Reorder Helper Method

Definition at line 423 of file Fourier.cs.

424  {
425  int j = 0;
426  for (int i = 0; i < samples.Length - 1; i++)
427  {
428  if (i < j)
429  {
430  Complex64 temp = samples[i];
431  samples[i] = samples[j];
432  samples[j] = temp;
433  }
434 
435  int m = samples.Length;
436 
437  do
438  {
439  m >>= 1;
440  j ^= m;
441  }
442  while ((j & m) == 0);
443  }
444  }

◆ Radix2Step() [1/2]

static void BGC.Mathematics.Fourier.Radix2Step ( Complex32 []  samples,
int  exponentSign,
int  levelSize,
int  k 
)
inlinestaticprivate

Radix-2 Step Helper Method

Parameters
samplesSample vector.
exponentSignFourier series exponent sign.
levelSizeLevel Group Size.
kIndex inside of the level.

Definition at line 233 of file Fourier.cs.

234  {
235  // Twiddle Factor
236  float exponent = (exponentSign * k) * Mathf.PI / levelSize;
237  Complex32 w = new Complex32(Mathf.Cos(exponent), Mathf.Sin(exponent));
238 
239  int step = levelSize << 1;
240  for (int i = k; i < samples.Length; i += step)
241  {
242  Complex32 ai = samples[i];
243  Complex32 t = w * samples[i + levelSize];
244  samples[i] = ai + t;
245  samples[i + levelSize] = ai - t;
246  }
247  }

◆ Radix2Step() [2/2]

static void BGC.Mathematics.Fourier.Radix2Step ( Complex64 []  samples,
int  exponentSign,
int  levelSize,
int  k 
)
inlinestaticprivate

Radix-2 Step Helper Method

Parameters
samplesSample vector.
exponentSignFourier series exponent sign.
levelSizeLevel Group Size.
kIndex inside of the level.

Definition at line 454 of file Fourier.cs.

455  {
456  // Twiddle Factor
457  float exponent = (exponentSign * k) * Mathf.PI / levelSize;
458  Complex64 w = new Complex64(Mathf.Cos(exponent), Mathf.Sin(exponent));
459 
460  int step = levelSize << 1;
461  for (int i = k; i < samples.Length; i += step)
462  {
463  Complex64 ai = samples[i];
464  Complex64 t = w * samples[i + levelSize];
465  samples[i] = ai + t;
466  samples[i + levelSize] = ai - t;
467  }
468  }

◆ Rescale() [1/2]

static void BGC.Mathematics.Fourier.Rescale ( Complex32 []  samples)
inlinestaticprivate

Fully rescale the FFT result.

Definition at line 566 of file Fourier.cs.

567  {
568  float scalingFactor = 1f / samples.Length;
569  for (int i = 0; i < samples.Length; i++)
570  {
571  samples[i] *= scalingFactor;
572  }
573  }

◆ Rescale() [2/2]

static void BGC.Mathematics.Fourier.Rescale ( Complex64 []  samples)
inlinestaticprivate

Fully rescale the FFT result.

Definition at line 578 of file Fourier.cs.

579  {
580  float scalingFactor = 1f / samples.Length;
581  for (int i = 0; i < samples.Length; i++)
582  {
583  samples[i] *= scalingFactor;
584  }
585  }

◆ SwapRealImaginary() [1/2]

static void BGC.Mathematics.Fourier.SwapRealImaginary ( Complex32 []  samples)
inlinestaticprivate

Swap the real and imaginary parts of each sample.

Parameters
samplesSample Vector.

Definition at line 591 of file Fourier.cs.

592  {
593  for (int i = 0; i < samples.Length; i++)
594  {
595  samples[i] = new Complex32(samples[i].Imaginary, samples[i].Real);
596  }
597  }

◆ SwapRealImaginary() [2/2]

static void BGC.Mathematics.Fourier.SwapRealImaginary ( Complex64 []  samples)
inlinestaticprivate

Swap the real and imaginary parts of each sample.

Parameters
samplesSample Vector.

Definition at line 603 of file Fourier.cs.

604  {
605  for (int i = 0; i < samples.Length; i++)
606  {
607  samples[i] = new Complex64(samples[i].Imaginary, samples[i].Real);
608  }
609  }

Field Documentation

◆ BluesteinSequenceLengthThreshold

const int BGC.Mathematics.Fourier.BluesteinSequenceLengthThreshold = 46341
private

Sequences with length greater than Math.Sqrt(Int32.MaxValue) + 1 will cause k*k in the Bluestein sequence to overflow (GH-286).

Definition at line 315 of file Fourier.cs.


The documentation for this class was generated from the following file: