circularConvolution function
Returns the circular convolution of real arrays a
and b
.
a
and b
will be zero padded or truncated to length
, which defaults to
the length of the larger array.
Returns the result as a newly allocated Float64List, and doesn't modify the input arrays. Also allocates 2 Float64x2Lists along the way.
If your input arrays are very different lengths, a naive convolution may be faster than this FFT based algorithm.
Implementation
Float64List circularConvolution(
List<double> a,
List<double> b, [
int length = 0,
]) {
if (length <= 0) {
length = math.max(a.length, b.length);
}
final fft = FFT(length);
final aa = ComplexArray.fromRealArray(a, length);
final bb = ComplexArray.fromRealArray(b, length);
fft
..inPlaceFft(aa)
..inPlaceFft(bb);
aa.complexMultiply(bb);
return fft.realInverseFft(aa);
}