-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSignal.hs
728 lines (690 loc) · 26.7 KB
/
Signal.hs
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
{-# LANGUAGE ViewPatterns #-}
--------------------------------------------------------------------------------
-- |
-- Module : ArrayFire.Signal
-- Copyright : David Johnson (c) 2019-2020
-- License : BSD 3
-- Maintainer : David Johnson <djohnson.m@gmail.com>
-- Stability : Experimental
-- Portability : GHC
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft.htm)
--
--------------------------------------------------------------------------------
module ArrayFire.Signal where
import Data.Complex
import ArrayFire.FFI
import ArrayFire.Internal.Signal
import ArrayFire.Internal.Types
-- | 'approx1' interpolates data along the first dimensions
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__approx1.htm)
--
-- Interpolation is performed assuming input data is equally spaced with indices in the range [0, n). The positions are sampled with respect to data at these locations.
--
-- >>> input = vector 3 [10,20,30]
-- >>> positions = vector 5 [0.0, 0.5, 1.0, 1.5, 2.0]
-- >>> approx1 @Double input positions Cubic 0.0
-- ArrayFire Array
-- [5 1 1 1]
-- 10.0000 13.7500 20.0000 26.2500 30.0000
--
approx1
:: AFType a
=> Array a
-- ^ the input array
-> Array a
-- ^ array contains the interpolation locations
-> InterpType
-- ^ is the interpolation type, it can take one of the values defined by 'InterpType'
-> Float
-- ^ is the value that will set in the output array when certain index is out of bounds
-> Array a
-- ^ is the array with interpolated values
approx1 arr1 arr2 (fromInterpType -> i1) f =
op2 arr1 arr2 (\p x y -> af_approx1 p x y i1 f)
-- | approx2 performs interpolation on data along the first and second dimensions.
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__approx2.htm)
--
-- Interpolation is performed assuming input data is equally spaced with indices in the range [0, n) along each dimension. The positions are sampled with respect to data at these locations.
--
-- >>> input = matrix @Double (3,3) [ [ 1.0,1.0,1.0 ], [ 2.0, 2.0, 2.0 ], [ 3.0,3.0,3.0 ] ]
-- >>> positions1 = matrix @Double (2,2) [ [ 0.5,1.5 ],[ 0.5,1.5 ] ]
-- >>> positions2 = matrix @Double (2,2) [ [ 0.5,0.5 ],[ 1.5,1.5 ] ]
-- >>> approx2 @Double input positions1 positions2 Cubic 0.0
-- ArrayFire Array
-- [2 2 1 1]
-- 1.3750 1.3750
-- 2.6250 2.6250
--
approx2
:: AFType a
=> Array a
-- ^ is the input array
-> Array a
-- ^ array contains the interpolation locations for first dimension
-> Array a
-- ^ array contains the interpolation locations for second dimension
-> InterpType
-- ^ is the interpolation type, it can take one of the values defined by 'InterpType'
-> Float
-- ^ is the value that will set in the output array when certain index is out of bounds
-> Array a
-- ^ is the array with interpolated values
approx2 arr1 arr2 arr3 (fromInterpType -> i1) f =
op3 arr1 arr2 arr3 (\p x y z -> af_approx2 p x y z i1 f)
-- DMJ: Where did these functions go? Were they removed?
-- http://arrayfire.org/docs/group__approx__mat.htm
-- approx1Uniform
-- :: AFType a
-- => Array a
-- -> Array a
-- -> Int
-- -> Double
-- -> Double
-- -> InterpType
-- -> Float
-- -> Array a
-- approx1Uniform arr1 arr2 (fromIntegral -> i1) d1 d2 (fromInterpType -> interp) f =
-- op2 arr1 arr2 (\p x y -> af_approx1_uniform p x y i1 d1 d2 interp f)
-- approx2Uniform
-- :: AFType a
-- => Array a
-- -> Array a
-- -> Int
-- -> Double
-- -> Double
-- -> Array a
-- -> Int
-- -> Double
-- -> Double
-- -> InterpType
-- -> Float
-- -> Array a
-- approx2Uniform arr1 arr2 (fromIntegral -> i1) d1 d2 arr3 (fromIntegral -> i2) d3 d4 (fromInterpType -> interp) f =
-- op3 arr1 arr2 arr3 (\p x y z -> af_approx2_uniform p x y i1 d1 d2 z i2 d3 d4 interp f)
-- | Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft.htm#ga64d0db9e59c9410ba738591ad146a884)
--
-- The Fast Fourier Transform (FFT) is an efficient algorithm to compute the discrete Fourier transform (DFT) of a signal or array. This is most commonly used to convert data in the time (or space) domain to the frequency domain, Then, the inverse FFT (iFFT) is used to return the data to the original domain.
--
-- >>> fft (vector @Double 10 [1..]) 2.0 10
-- ArrayFire Array
-- [2 2 1 1]
-- 1.3750 1.3750
-- 2.6250 2.6250
--
fft
:: (AFType a, Fractional a)
=> Array a
-- ^ input 'Array'
-> Double
-- ^ the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals - used to either truncate or pad the input signals.
-> Array a
-- ^ is the transformed array
fft a d (fromIntegral -> x) =
op1 a (\j k -> af_fft j k d x)
-- | Fast Fourier Transform (in-place)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft.htm#gaa2f03c9ee1cb80dc184c0b0a13176da1)
--
-- C Interface for fast fourier transform on one dimensional signals.
--
-- *Note* The input in must be a complex array
--
fftInPlace
:: (AFType a, Fractional a)
=> Array (Complex a)
-- ^ is the input array on entry and the output of 1D forward fourier transform at exit
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> IO ()
fftInPlace a d = a `inPlace` (flip af_fft_inplace d)
-- | Fast Fourier Transform (2-dimensional)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft2.htm#gaab3fb1ed398e208a615036b4496da611)
--
-- C Interface for fast fourier transform on two dimensional signals.
--
fft2
:: AFType a
=> Array a
-- ^ the input array
-> Double
-- ^ the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along second dimension - used to either truncate/pad the input
-> Array a
-- ^ the transformed array
fft2 a d x y =
op1 a (\j k -> af_fft2 j k d (fromIntegral x) (fromIntegral y))
-- | Fast Fourier Transform (2-dimensional, in-place)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft2.htm#gacdeebb3f221ae698833dc4900a172b8c)
--
-- C Interface for fast fourier transform on two dimensional signals.
--
-- *Note* The input in must be a complex array
--
fft2_inplace
:: (Fractional a, AFType a)
=> Array (Complex a)
-- ^ input array on entry and the output of 2D forward fourier transform on exit
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> IO ()
fft2_inplace a d = a `inPlace` (flip af_fft2_inplace d)
-- | Fast Fourier Transform (3-dimensional)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft3.htm#ga5138ef1740ece0fde2c796904d733c12)
--
-- C Interface for fast fourier transform on three dimensional signals.
--
fft3
:: AFType a
=> Array a
-- ^ the input array
-> Double
-- ^ the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along second dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along third dimension - used to either truncate/pad the input
-> Array a
-- ^ the transformed array
fft3 a d x y z =
op1 a (\j k -> af_fft3 j k d (fromIntegral x) (fromIntegral y) (fromIntegral z))
-- | Fast Fourier Transform (3-dimensional, in-place)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft2.htm#gacdeebb3f221ae698833dc4900a172b8c)
--
-- C Interface for fast fourier transform on three dimensional signals.
--
-- *Note* The input in must be a complex array
--
fft3_inplace
:: (Fractional a, AFType a)
=> Array (Complex a)
-- ^ input array on entry and the output of 3D forward fourier transform on exit
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> IO ()
fft3_inplace a d = a `inPlace` (flip af_fft3_inplace d)
-- | Inverse Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__ifft.htm#ga2d62c120b474b3b937b0425c994645fe)
--
-- C Interface for inverse fast fourier transform on one dimensional signals.
--
ifft
:: AFType a
=> Array a
-- ^ the input array
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals - used to either truncate or pad the input signals
-> Array a
-- ^ the transformed array
ifft a d x =
op1 a (\j k -> af_ifft j k d (fromIntegral x))
-- | Inverse Fast Fourier Transform (in-place)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__ifft.htm#ga827379bef0e2cadb382c1b6301c91429)
--
-- C Interface for fast fourier transform on one dimensional signals.
--
ifft_inplace
:: (AFType a, Fractional a)
=> Array (Complex a)
-- ^ is the input array on entry and the output of 1D forward fourier transform at exit
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> IO ()
ifft_inplace a d = a `inPlace` (flip af_ifft_inplace d)
-- | Inverse Fast Fourier Transform (2-dimensional signals)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__ifft2.htm#ga7cd29c6a35c19240635b62cc5c30dc4f)
--
-- C Interface for inverse fast fourier transform on two dimensional signals.
--
ifft2
:: AFType a
=> Array a
-- ^ the input array
-> Double
-- ^ the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along second dimension - used to either truncate/pad the input
-> Array a
-- ^ the transformed array
ifft2 a d x y =
op1 a (\j k -> af_ifft2 j k d (fromIntegral x) (fromIntegral y))
-- | Inverse Fast Fourier Transform (2-dimensional, in-place)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__ifft2.htm#ga9e6a165d44306db4552a56d421ce5d05)
--
-- C Interface for fast fourier transform on two dimensional signals.
--
ifft2_inplace
:: (AFType a, Fractional a)
=> Array (Complex a)
-- ^ is the input array on entry and the output of 1D forward fourier transform at exit
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> IO ()
ifft2_inplace a d = a `inPlace` (flip af_ifft2_inplace d)
-- | Inverse Fast Fourier Transform (3-dimensional)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__ifft3.htm)
--
-- C Interface for inverse fast fourier transform on three dimensional signals.
--
ifft3
:: AFType a
=> Array a
-- ^ the input array
-> Double
-- ^ the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along second dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along third dimension - used to either truncate/pad the input
-> Array a
-- ^ the transformed array
ifft3 a d x y z =
op1 a (\j k -> af_ifft3 j k d (fromIntegral x) (fromIntegral y) (fromIntegral z))
-- | Inverse Fast Fourier Transform (3-dimensional, in-place)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__ifft3.htm#ga439a7a49723bc6cf77cf4fe7f8dfe334)
--
-- C Interface for fast fourier transform on two dimensional signals.
--
ifft3_inplace
:: (AFType a, Fractional a)
=> Array (Complex a)
-- ^ is the input array on entry and the output of 1D forward fourier transform at exit
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> IO ()
ifft3_inplace a d = a `inPlace` (flip af_ifft3_inplace d)
-- | Real to Complex Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__r2c.htm#ga7486f342182a18e773f14cc2ab4cb551)
--
-- C Interface for real to complex fast fourier transform for one dimensional signals.
--
-- The first dimension of the output will be of size (pad0 / 2) + 1. The second dimension of the output will be pad1. The third dimension of the output will be pad 2.
--
fftr2c
:: (Fractional a, AFType a)
=> Array a
-- ^ is a real array
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Array a
-- ^ is a complex array containing the non redundant parts of in.
fftr2c a d x =
op1 a (\j k -> af_fft_r2c j k d (fromIntegral x))
-- | Real to Complex Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__r2c.htm#ga7486f342182a18e773f14cc2ab4cb551)
--
-- C Interface for real to complex fast fourier transform for two dimensional signals.
--
-- The first dimension of the output will be of size (pad0 / 2) + 1. The second dimension of the output will be pad1. The third dimension of the output will be pad 2.
--
fft2r2c
:: (Fractional a, AFType a)
=> Array a
-- ^ is a real array
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along second dimension - used to either truncate/pad the input
-> Array a
-- ^ is a complex array containing the non redundant parts of in.
fft2r2c a d x y =
op1 a (\j k -> af_fft2_r2c j k d (fromIntegral x) (fromIntegral y))
-- | Real to Complex Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__r2c.htm#gab4ca074b54218b74d8cfbda63d38be51)
--
-- C Interface for real to complex fast fourier transform for three dimensional signals.
--
-- The first dimension of the output will be of size (pad0 / 2) + 1. The second dimension of the output will be pad1. The third dimension of the output will be pad 2.
--
fft3r2c
:: (Fractional a, AFType a)
=> Array a
-- ^ is a real array
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Int
-- ^ is the length of output signals along first dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along second dimension - used to either truncate/pad the input
-> Int
-- ^ is the length of output signals along third dimension - used to either truncate/pad the input
-> Array a
-- ^ is a complex array containing the non redundant parts of in.
fft3r2c a d x y z =
op1 a (\j k -> af_fft3_r2c j k d (fromIntegral x) (fromIntegral y) (fromIntegral z))
-- | Complex to Real Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__c2r.htm#gaa5efdfd84213a4a07d81a5d534cde5ac)
--
-- C Interface for complex to real fast fourier transform for one dimensional signals.
--
-- The first dimension of the output will be 2 * dim0 - 1 if is_odd is true else 2 * dim0 - 2 where dim0 is the first dimension of the input. The remaining dimensions are unchanged.
--
fftc2r
:: AFType a
=> Array a
-- ^ is a complex array containing only the non redundant parts of the signals.
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Bool
-- ^ is a flag signifying if the output should be even or odd size
-> Array a
-- ^ is a real array containing the output of the transform.
fftc2r a cm (fromIntegral . fromEnum -> cd) = op1 a (\x y -> af_fft_c2r x y cm cd)
-- | Complex to Real Fast Fourier Transform (2-dimensional)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__c2r.htm#gaaa7da16f226cacaffced631e08da4493)
--
-- C Interface for complex to real fast fourier transform for two dimensional signals.
--
-- The first dimension of the output will be 2 * dim0 - 1 if is_odd is true else 2 * dim0 - 2 where dim0 is the first dimension of the input. The remaining dimensions are unchanged.
--
fft2C2r
:: AFType a
=> Array a
-- ^ is a complex array containing only the non redundant parts of the signals.
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Bool
-- ^ is a flag signifying if the output should be even or odd size
-> Array a
-- ^ is a real array containing the output of the transform.
fft2C2r a cm (fromIntegral . fromEnum -> cd) = op1 a (\x y -> af_fft2_c2r x y cm cd)
-- | Complex to Real Fast Fourier Transform (3-dimensional)
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__c2r.htm#gaa9b3322d9ffab15268919e1f114bed24)
--
-- C Interface for complex to real fast fourier transform for three dimensional signals.
--
-- The first dimension of the output will be 2 * dim0 - 1 if is_odd is true else 2 * dim0 - 2 where dim0 is the first dimension of the input. The remaining dimensions are unchanged.
--
fft3C2r
:: AFType a
=> Array a
-- ^ is a complex array containing only the non redundant parts of the signals.
-> Double
-- ^ is the normalization factor with which the input is scaled after the transformation is applied
-> Bool
-- ^ is a flag signifying if the output should be even or odd size
-> Array a
-- ^ is a real array containing the output of the transform.
fft3C2r a cm (fromIntegral . fromEnum -> cd) = op1 a (\x y -> af_fft3_c2r x y cm cd)
-- | Convolution Integral for one dimensional data
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__convolve1.htm#ga25d77b794463b5cd72cd0b7f4af140d7)
--
-- C Interface for convolution on one dimensional signals.
--
-- *Note* The default parameter of domain, AF_CONV_AUTO, heuristically switches between frequency and spatial domain.
--
convolve1
:: AFType a
=> Array a
-- ^ the input signal
-> Array a
-- ^ the signal that shall be flipped for the convolution operation
-> ConvMode
-- ^ indicates if the convolution should be expanded or not(where output size equals input)
-> ConvDomain
-- ^ specifies if the convolution should be performed in frequency os spatial domain
-> Array a
-- ^ convolved array
convolve1 a b (toConvMode -> cm) (fromConvDomain -> cd) = op2 a b (\x y z -> af_convolve1 x y z cm cd)
-- | Convolution Integral for two dimensional data
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__convolve2.htm#ga25d77b794463b5cd72cd0b7f4af140d7)
--
-- C Interface for convolution on two dimensional signals.
--
-- *Note* The default parameter of domain, AF_CONV_AUTO, heuristically switches between frequency and spatial domain.
--
convolve2
:: AFType a
=> Array a
-- ^ the input signal
-> Array a
-- ^ the signal that shall be flipped for the convolution operation
-> ConvMode
-- ^ indicates if the convolution should be expanded or not(where output size equals input)
-> ConvDomain
-- ^ specifies if the convolution should be performed in frequency os spatial domain
-> Array a
-- ^ convolved array
convolve2 a b (toConvMode -> cm) (fromConvDomain -> cd) = op2 a b (\x y z -> af_convolve2 x y z cm cd)
-- | Convolution Integral for three dimensional data
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__convolve3.htm#ga25d77b794463b5cd72cd0b7f4af140d7)
--
-- C Interface for convolution on three dimensional signals.
--
-- *Note* The default parameter of domain, AF_CONV_AUTO, heuristically switches between frequency and spatial domain.
--
convolve3
:: AFType a
=> Array a
-- ^ the input signal
-> Array a
-- ^ the signal that shall be flipped for the convolution operation
-> ConvMode
-- ^ indicates if the convolution should be expanded or not(where output size equals input)
-> ConvDomain
-- ^ specifies if the convolution should be performed in frequency os spatial domain
-> Array a
-- ^ convolved array
convolve3 a b (toConvMode -> cm) (fromConvDomain -> cd) =
op2 a b (\x y z -> af_convolve3 x y z cm cd)
-- | C Interface for separable convolution on two dimensional signals.
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__convolve.htm#gaeb6ba88155cf3ef29d93f97b147e372f)
--
-- C Interface for separable convolution on two dimensional signals.
--
-- *Note* The default parameter of domain, AF_CONV_AUTO, heuristically switches between frequency and spatial domain.
--
convolve2Sep
:: AFType a
=> Array a
-- ^ filter that has to be applied along the coloumns
-> Array a
-- ^ filter that has to be applied along the rows
-> Array a
-- ^ the input array
-> ConvMode
-- ^ indicates if the convolution should be expanded or not(where output size equals input)
-> Array a
-- ^ convolved array
convolve2Sep a b c (toConvMode -> d) = op3 a b c (\x y z j -> af_convolve2_sep x y z j d)
-- DMJ: did this get removed? Can't find in latest docs
-- fftConvolve1
-- :: AFType a
-- => Array a
-- -> Array a
-- -> ConvMode
-- -> Array a
-- fftConvolve1 a b (toConvMode -> c) = op2 a b (\x y z -> af_fft_convolve1 x y z c)
-- | 2D Convolution using Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__convolve2.htm#gab52ebe631d8358cdef1b5c8a95550556)
--
-- A convolution is a common operation between a source array, a, and a filter (or kernel) array b. The answer to the convolution is the same as computing the coefficients in polynomial multiplication, if a and b are the coefficients.
--
-- C Interface for FFT-based convolution on two dimensional signals.
--
fftConvolve2
:: AFType a
=> Array a
-- ^ is the input signal
-> Array a
-- ^ is the signal that shall be used for the convolution operation
-> ConvMode
-- ^ indicates if the convolution should be expanded or not(where output size equals input)
-> Array a
-- ^ is convolved array
fftConvolve2 a b (toConvMode -> c) = op2 a b (\x y z -> af_fft_convolve2 x y z c)
-- | 3D Convolution using Fast Fourier Transform
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft__convolve3.htm)
--
-- A convolution is a common operation between a source array, a, and a filter (or kernel) array b. The answer to the convolution is the same as computing the coefficients in polynomial multiplication, if a and b are the coefficients.
--
-- C Interface for FFT-based convolution on three dimensional signals.
--
fftConvolve3
:: AFType a
=> Array a
-- ^ is the input signal
-> Array a
-- ^ is the signal that shall be used for the convolution operation
-> ConvMode
-- ^ indicates if the convolution should be expanded or not(where output size equals input)
-> Array a
-- ^ is convolved array
fftConvolve3 a b (toConvMode -> c) = op2 a b (\x y z -> af_fft_convolve3 x y z c)
-- | Finite Impulse Filter.
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fir.htm#ga2a850e69775eede4709e0d607bba240b)
--
-- Finite impulse filters take an input x and a co-efficient array b to generate an output y such that:
--
-- C Interface for finite impulse response filter.
--
fir
:: AFType a
=> Array a
-- ^ is the input signal to the filter
-> Array a
-- ^ is the array containing the coefficients of the filter
-> Array a
-- ^ is the output signal from the filter
fir a b = op2 a b af_fir
-- | Infinite Impulse Filter.
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__iir.htm#ga7adcc364da0a66cdfd2bb351215456c4)
--
-- Infinite impulse filters take an input x and a feedforward array b, feedback array a to generate an output y such that:
--
-- C Interface for infinite impulse response filter.
--
-- *Note* The feedforward coefficients are currently limited to a length of 512
--
iir
:: AFType a
=> Array a
-- ^ the array containing the feedforward coefficient
-> Array a
-- ^ is the array containing the feedback coefficients
-> Array a
-- ^ is the input signal to the filter
-> Array a
-- ^ the output signal from the filter
iir a b c = op3 a b c af_iir
-- | Median Filter
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__image__func__medfilt.htm#gaaf3f62f2de0f4dc315b831e494e1b2c0)
--
-- A median filter is similar to the arbitrary filter except that instead of a weighted sum, the median value of the pixels covered by the kernel is returned.
--
-- C Interface for median filter.
--
medFilt
:: AFType a
=> Array a
-- ^ 'Array' is the input image
-> Int
-> Int
-> BorderType
-> Array a
-- ^ 'Array' is the processed image
medFilt a l w (fromBorderType -> b) =
a `op1` (\x y -> af_medfilt x y (fromIntegral l) (fromIntegral w) b)
-- | 1D Median Filter
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__image__func__medfilt.htm#gad108ea62cbbb5371bd14a17d06384359)
--
-- A median filter is similar to the arbitrary filter except that instead of a weighted sum, the median value of the pixels covered by the kernel is returned.
--
-- C Interface for 1D median filter.
--
medFilt1
:: AFType a
=> Array a
-- ^ 'Array' is the input signal
-> Int
-- ^ Is the kernel width
-> BorderType
-- ^ value will decide what happens to border when running filter in their neighborhood. It takes one of the values [AF_PAD_ZERO | AF_PAD_SYM]
-> Array a
-- ^ 'Array' is the processed signal
medFilt1 a w (fromBorderType -> b) =
a `op1` (\x y -> af_medfilt1 x y (fromIntegral w) b)
-- | 2D Median Filter
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__image__func__medfilt.htm#ga2cb99dca5842f74f6b9cd28eb187a9cd)
--
-- A median filter is similar to the arbitrary filter except that instead of a weighted sum, the median value of the pixels covered by the kernel is returned.
--
-- C Interface for 2D median filter.
--
medFilt2
:: AFType a
=> Array a
-- ^ 'Array' is the input image
-> Int
-- ^ the kernel height
-> Int
-- ^ the kernel width
-> BorderType
-- ^ value will decide what happens to border when running filter in their neighborhood. It takes one of the values [AF_PAD_ZERO | AF_PAD_SYM]
-> Array a
-- ^ 'Array' is the processed image
medFilt2 a l w (fromBorderType -> b) =
a `op1` (\x y -> af_medfilt2 x y (fromIntegral l) (fromIntegral w) b)
-- | C Interface for setting plan cache size.
--
-- [ArrayFire Docs](http://arrayfire.org/docs/group__signal__func__fft.htm#ga4ddef19b43d9a50c97b1a835df60279a)
--
-- This function doesn't do anything if called when CPU backend is active. The plans associated with the most recently used array sizes are cached.
--
-- >>> setFFTPlanCacheSize 2
-- ()
--
setFFTPlanCacheSize
:: Int
-- ^ is the number of plans that shall be cached
-> IO ()
setFFTPlanCacheSize =
afCall . af_set_fft_plan_cache_size . fromIntegral