Problem description
I have employed the convolution theorem to calculate convolutions efficiently. Suppose there are two real signals s1 and s2 of length N each. Then I can obtain the convolution from
import numpy as np
import numpy.fft as fft
size = len(s1)
fft_size = int(2 ** np.ceil(np.log2(2 * size - 1))) #The size for the FFT algorithm
S1 = fft.rfft(s1, fft_size) #Take FTs
S2 = fft.rfft(s2, fft_size)
convolution = fft.irfft(S1 * S2) #Take IFT
However, if I have a k singals the fft_size must be modified to read
fft_size = int(2 ** np.ceil(np.log2(k * size - 1)))
in order to avoid circular overlap.
Unfortunately, I do not know k a priori. One option is to choose a maximum value k_max but I would prefer to not have to use large amounts of memory if not absolutely necessary and I would prefer to not evaluate the FT again every time k changes.
Question
Is it possible to do one of the following
- Take the FFT of the signal for
k=1and "zero pad in Fourier space" as necessary? - Prevent circular wrapping in the FFT?