forked from SciSharp/Numpy.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnp.fft.gen.cs
More file actions
539 lines (523 loc) · 24.6 KB
/
np.fft.gen.cs
File metadata and controls
539 lines (523 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
// Copyright (c) 2019 by the SciSharp Team
// Code generated by CodeMinion: https://github.com/SciSharp/CodeMinion
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Python.Runtime;
using Numpy.Models;
using Python.Included;
namespace Numpy
{
public static partial class np
{
public static partial class fft {
/// <summary>
/// Compute the one-dimensional discrete Fourier Transform for real input.<br></br>
///
/// This function computes the one-dimensional n-point discrete Fourier
/// Transform (DFT) of a real-valued array by means of an efficient algorithm
/// called the Fast Fourier Transform (FFT).<br></br>
///
/// Notes
///
/// When the DFT is computed for purely real input, the output is
/// Hermitian-symmetric, i.e.<br></br>
/// the negative frequency terms are just the complex
/// conjugates of the corresponding positive-frequency terms, and the
/// negative-frequency terms are therefore redundant.<br></br>
/// This function does not
/// compute the negative frequency terms, and the length of the transformed
/// axis of the output is therefore n//2 + 1.<br></br>
///
/// When A = rfft(a) and fs is the sampling frequency, A[0] contains
/// the zero-frequency term 0*fs, which is real due to Hermitian symmetry.<br></br>
///
/// If n is even, A[-1] contains the term representing both positive
/// and negative Nyquist frequency (+fs/2 and -fs/2), and must also be purely
/// real.<br></br>
/// If n is odd, there is no term at fs/2; A[-1] contains
/// the largest positive frequency (fs/2*(n-1)/n), and is complex in the
/// general case.<br></br>
///
/// If the input a contains an imaginary part, it is silently discarded.
/// </summary>
/// <param name="a">
/// Input array
/// </param>
/// <param name="n">
/// Number of points along transformation axis in the input to use.<br></br>
///
/// If n is smaller than the length of the input, the input is cropped.<br></br>
///
/// If it is larger, the input is padded with zeros.<br></br>
/// If n is not given,
/// the length of the input along the axis specified by axis is used.
/// </param>
/// <param name="axis">
/// Axis over which to compute the FFT.<br></br>
/// If not given, the last axis is
/// used.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The truncated or zero-padded input, transformed along the axis
/// indicated by axis, or the last one if axis is not specified.<br></br>
///
/// If n is even, the length of the transformed axis is (n/2)+1.
/// If n is odd, the length is (n+1)/2.
/// </returns>
public static NDarray rfft(NDarray a, int? n = null, int? axis = -1, string norm = null)
=> NumPy.Instance.fft_rfft(a, n:n, axis:axis, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the inverse of the n-point DFT for real input.<br></br>
///
/// This function computes the inverse of the one-dimensional n-point
/// discrete Fourier Transform of real input computed by rfft.<br></br>
///
/// In other words, irfft(rfft(a), len(a)) == a to within numerical
/// accuracy.<br></br>
/// (See Notes below for why len(a) is necessary here.)
///
/// The input is expected to be in the form returned by rfft, i.e.<br></br>
/// the
/// real zero-frequency term followed by the complex positive frequency terms
/// in order of increasing frequency.<br></br>
/// Since the discrete Fourier Transform of
/// real input is Hermitian-symmetric, the negative frequency terms are taken
/// to be the complex conjugates of the corresponding positive frequency terms.<br></br>
///
/// Notes
///
/// Returns the real valued n-point inverse discrete Fourier transform
/// of a, where a contains the non-negative frequency terms of a
/// Hermitian-symmetric sequence.<br></br>
/// n is the length of the result, not the
/// input.<br></br>
///
/// If you specify an n such that a must be zero-padded or truncated, the
/// extra/removed values will be added/removed at high frequencies.<br></br>
/// One can
/// thus resample a series to m points via Fourier interpolation by:
/// a_resamp = irfft(rfft(a), m).
/// </summary>
/// <param name="a">
/// The input array.
/// </param>
/// <param name="n">
/// Length of the transformed axis of the output.<br></br>
///
/// For n output points, n//2+1 input points are necessary.<br></br>
/// If the
/// input is longer than this, it is cropped.<br></br>
/// If it is shorter than this,
/// it is padded with zeros.<br></br>
/// If n is not given, it is determined from
/// the length of the input along the axis specified by axis.
/// </param>
/// <param name="axis">
/// Axis over which to compute the inverse FFT.<br></br>
/// If not given, the last
/// axis is used.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The truncated or zero-padded input, transformed along the axis
/// indicated by axis, or the last one if axis is not specified.<br></br>
///
/// The length of the transformed axis is n, or, if n is not given,
/// 2*(m-1) where m is the length of the transformed axis of the
/// input.<br></br>
/// To get an odd number of output points, n must be specified.
/// </returns>
public static NDarray irfft(NDarray a, int? n = null, int? axis = -1, string norm = null)
=> NumPy.Instance.fft_irfft(a, n:n, axis:axis, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the 2-dimensional FFT of a real array.<br></br>
///
/// Notes
///
/// This is really just rfftn with different default behavior.<br></br>
///
/// For more details see rfftn.
/// </summary>
/// <param name="a">
/// Input array, taken to be real.
/// </param>
/// <param name="s">
/// Shape of the FFT.
/// </param>
/// <param name="axes">
/// Axes over which to compute the FFT.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The result of the real 2-D FFT.
/// </returns>
public static NDarray rfft2(NDarray a, int[] s = null, int[] axes = null, string norm = null)
=> NumPy.Instance.fft_rfft2(a, s:s, axes:axes, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the 2-dimensional inverse FFT of a real array.<br></br>
///
/// Notes
///
/// This is really irfftn with different defaults.<br></br>
///
/// For more details see irfftn.
/// </summary>
/// <param name="a">
/// The input array
/// </param>
/// <param name="s">
/// Shape of the inverse FFT.
/// </param>
/// <param name="axes">
/// The axes over which to compute the inverse fft.<br></br>
///
/// Default is the last two axes.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The result of the inverse real 2-D FFT.
/// </returns>
public static NDarray irfft2(NDarray a, int[] s = null, int[] axes = null, string norm = null)
=> NumPy.Instance.fft_irfft2(a, s:s, axes:axes, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the N-dimensional discrete Fourier Transform for real input.<br></br>
///
/// This function computes the N-dimensional discrete Fourier Transform over
/// any number of axes in an M-dimensional real array by means of the Fast
/// Fourier Transform (FFT).<br></br>
/// By default, all axes are transformed, with the
/// real transform performed over the last axis, while the remaining
/// transforms are complex.<br></br>
///
/// Notes
///
/// The transform for real input is performed over the last transformation
/// axis, as by rfft, then the transform over the remaining axes is
/// performed as by fftn.<br></br>
/// The order of the output is as for rfft for the
/// final transformation axis, and as for fftn for the remaining
/// transformation axes.<br></br>
///
/// See fft for details, definitions and conventions used.
/// </summary>
/// <param name="a">
/// Input array, taken to be real.
/// </param>
/// <param name="s">
/// Shape (length along each transformed axis) to use from the input.<br></br>
///
/// (s[0] refers to axis 0, s[1] to axis 1, etc.).<br></br>
///
/// The final element of s corresponds to n for rfft(x, n), while
/// for the remaining axes, it corresponds to n for fft(x, n).<br></br>
///
/// Along any axis, if the given shape is smaller than that of the input,
/// the input is cropped.<br></br>
/// If it is larger, the input is padded with zeros.<br></br>
///
/// if s is not given, the shape of the input along the axes specified
/// by axes is used.
/// </param>
/// <param name="axes">
/// Axes over which to compute the FFT.<br></br>
/// If not given, the last len(s)
/// axes are used, or all axes if s is also not specified.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The truncated or zero-padded input, transformed along the axes
/// indicated by axes, or by a combination of s and a,
/// as explained in the parameters section above.<br></br>
///
/// The length of the last axis transformed will be s[-1]//2+1,
/// while the remaining transformed axes will have lengths according to
/// s, or unchanged from the input.
/// </returns>
public static NDarray rfftn(NDarray a, int[] s = null, int[] axes = null, string norm = null)
=> NumPy.Instance.fft_rfftn(a, s:s, axes:axes, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the inverse of the N-dimensional FFT of real input.<br></br>
///
/// This function computes the inverse of the N-dimensional discrete
/// Fourier Transform for real input over any number of axes in an
/// M-dimensional array by means of the Fast Fourier Transform (FFT).<br></br>
/// In
/// other words, irfftn(rfftn(a), a.shape) == a to within numerical
/// accuracy.<br></br>
/// (The a.shape is necessary like len(a) is for irfft,
/// and for the same reason.)
///
/// The input should be ordered in the same way as is returned by rfftn,
/// i.e.<br></br>
/// as for irfft for the final transformation axis, and as for ifftn
/// along all the other axes.<br></br>
///
/// Notes
///
/// See fft for definitions and conventions used.<br></br>
///
/// See rfft for definitions and conventions used for real input.
/// </summary>
/// <param name="a">
/// Input array.
/// </param>
/// <param name="s">
/// Shape (length of each transformed axis) of the output
/// (s[0] refers to axis 0, s[1] to axis 1, etc.).<br></br>
/// s is also the
/// number of input points used along this axis, except for the last axis,
/// where s[-1]//2+1 points of the input are used.<br></br>
///
/// Along any axis, if the shape indicated by s is smaller than that of
/// the input, the input is cropped.<br></br>
/// If it is larger, the input is padded
/// with zeros.<br></br>
/// If s is not given, the shape of the input along the
/// axes specified by axes is used.
/// </param>
/// <param name="axes">
/// Axes over which to compute the inverse FFT.<br></br>
/// If not given, the last
/// len(s) axes are used, or all axes if s is also not specified.<br></br>
///
/// Repeated indices in axes means that the inverse transform over that
/// axis is performed multiple times.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The truncated or zero-padded input, transformed along the axes
/// indicated by axes, or by a combination of s or a,
/// as explained in the parameters section above.<br></br>
///
/// The length of each transformed axis is as given by the corresponding
/// element of s, or the length of the input in every axis except for the
/// last one if s is not given.<br></br>
/// In the final transformed axis the length
/// of the output when s is not given is 2*(m-1) where m is the
/// length of the final transformed axis of the input.<br></br>
/// To get an odd
/// number of output points in the final axis, s must be specified.
/// </returns>
public static NDarray irfftn(NDarray a, int[] s = null, int[] axes = null, string norm = null)
=> NumPy.Instance.fft_irfftn(a, s:s, axes:axes, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the FFT of a signal that has Hermitian symmetry, i.e., a real
/// spectrum.<br></br>
///
/// Notes
///
/// hfft/ihfft are a pair analogous to rfft/irfft, but for the
/// opposite case: here the signal has Hermitian symmetry in the time
/// domain and is real in the frequency domain.<br></br>
/// So here it’s hfft for
/// which you must supply the length of the result if it is to be odd.
/// </summary>
/// <param name="a">
/// The input array.
/// </param>
/// <param name="n">
/// Length of the transformed axis of the output.<br></br>
/// For n output
/// points, n//2 + 1 input points are necessary.<br></br>
/// If the input is
/// longer than this, it is cropped.<br></br>
/// If it is shorter than this, it is
/// padded with zeros.<br></br>
/// If n is not given, it is determined from the
/// length of the input along the axis specified by axis.
/// </param>
/// <param name="axis">
/// Axis over which to compute the FFT.<br></br>
/// If not given, the last
/// axis is used.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The truncated or zero-padded input, transformed along the axis
/// indicated by axis, or the last one if axis is not specified.<br></br>
///
/// The length of the transformed axis is n, or, if n is not given,
/// 2*m - 2 where m is the length of the transformed axis of
/// the input.<br></br>
/// To get an odd number of output points, n must be
/// specified, for instance as 2*m - 1 in the typical case,
/// </returns>
public static NDarray hfft(NDarray a, int? n = null, int? axis = -1, string norm = null)
=> NumPy.Instance.fft_hfft(a, n:n, axis:axis, norm:norm);
}
public static partial class fft {
/// <summary>
/// Compute the inverse FFT of a signal that has Hermitian symmetry.<br></br>
///
/// Notes
///
/// hfft/ihfft are a pair analogous to rfft/irfft, but for the
/// opposite case: here the signal has Hermitian symmetry in the time
/// domain and is real in the frequency domain.<br></br>
/// So here it’s hfft for
/// which you must supply the length of the result if it is to be odd:
/// </summary>
/// <param name="a">
/// Input array.
/// </param>
/// <param name="n">
/// Length of the inverse FFT, the number of points along
/// transformation axis in the input to use.<br></br>
/// If n is smaller than
/// the length of the input, the input is cropped.<br></br>
/// If it is larger,
/// the input is padded with zeros.<br></br>
/// If n is not given, the length of
/// the input along the axis specified by axis is used.
/// </param>
/// <param name="axis">
/// Axis over which to compute the inverse FFT.<br></br>
/// If not given, the last
/// axis is used.
/// </param>
/// <param name="norm">
/// Normalization mode (see numpy.fft).<br></br>
/// Default is None.
/// </param>
/// <returns>
/// The truncated or zero-padded input, transformed along the axis
/// indicated by axis, or the last one if axis is not specified.<br></br>
///
/// The length of the transformed axis is n//2 + 1.
/// </returns>
public static NDarray ihfft(NDarray a, int? n = null, int? axis = -1, string norm = null)
=> NumPy.Instance.fft_ihfft(a, n:n, axis:axis, norm:norm);
}
public static partial class fft {
/// <summary>
/// Return the Discrete Fourier Transform sample frequencies.<br></br>
///
/// The returned float array f contains the frequency bin centers in cycles
/// per unit of the sample spacing (with zero at the start).<br></br>
/// For instance, if
/// the sample spacing is in seconds, then the frequency unit is cycles/second.<br></br>
///
/// Given a window length n and a sample spacing d:
/// </summary>
/// <param name="n">
/// Window length.
/// </param>
/// <param name="d">
/// Sample spacing (inverse of the sampling rate).<br></br>
/// Defaults to 1.
/// </param>
/// <returns>
/// Array of length n containing the sample frequencies.
/// </returns>
public static NDarray fftfreq(int n, float? d = 1.0f)
=> NumPy.Instance.fft_fftfreq(n, d:d);
}
public static partial class fft {
/// <summary>
/// Return the Discrete Fourier Transform sample frequencies
/// (for usage with rfft, irfft).<br></br>
///
/// The returned float array f contains the frequency bin centers in cycles
/// per unit of the sample spacing (with zero at the start).<br></br>
/// For instance, if
/// the sample spacing is in seconds, then the frequency unit is cycles/second.<br></br>
///
/// Given a window length n and a sample spacing d:
///
/// Unlike fftfreq (but like scipy.fftpack.rfftfreq)
/// the Nyquist frequency component is considered to be positive.
/// </summary>
/// <param name="n">
/// Window length.
/// </param>
/// <param name="d">
/// Sample spacing (inverse of the sampling rate).<br></br>
/// Defaults to 1.
/// </param>
/// <returns>
/// Array of length n//2 + 1 containing the sample frequencies.
/// </returns>
public static NDarray rfftfreq(int n, float? d = 1.0f)
=> NumPy.Instance.fft_rfftfreq(n, d:d);
}
public static partial class fft {
/// <summary>
/// Shift the zero-frequency component to the center of the spectrum.<br></br>
///
/// This function swaps half-spaces for all axes listed (defaults to all).<br></br>
///
/// Note that y[0] is the Nyquist component only if len(x) is even.
/// </summary>
/// <param name="x">
/// Input array.
/// </param>
/// <param name="axes">
/// Axes over which to shift.<br></br>
/// Default is None, which shifts all axes.
/// </param>
/// <returns>
/// The shifted array.
/// </returns>
public static NDarray fftshift(NDarray x, int[] axes = null)
=> NumPy.Instance.fft_fftshift(x, axes:axes);
}
public static partial class fft {
/// <summary>
/// The inverse of fftshift.<br></br>
/// Although identical for even-length x, the
/// functions differ by one sample for odd-length x.
/// </summary>
/// <param name="x">
/// Input array.
/// </param>
/// <param name="axes">
/// Axes over which to calculate.<br></br>
/// Defaults to None, which shifts all axes.
/// </param>
/// <returns>
/// The shifted array.
/// </returns>
public static NDarray ifftshift(NDarray x, int[] axes = null)
=> NumPy.Instance.fft_ifftshift(x, axes:axes);
}
}
}