I have two frequency maps obtained from numpy fft. Like so:
def fft(self):
Y = np.fft.fft(self.data) # fft computing and normalization
Y = 2.0/self.len * np.abs(Y[:self.len//2])
frq = np.arange(self.len) / self.duration # two sides frequency range
X = frq[range(self.len//2)] # one side frequency range
return FrequencyProfile(X, Y)
The bucket sizes of resulting frequency maps are different. I need to join them without losing the quality, because I use them for further sound generation.
I've tried bringing both to a standard bucket size:
# RESOLUTION is the size of the bucket, smaller than original
X1 = np.arange(int(np.min(X)), int(np.max(X)), RESOLUTION)
Y1 = np.interp(X1, X, Y)
And then subsequently add them like so:
def add(self, p):
f = [self.min_f(), self.max_f(), p.min_f(), p.max_f()]
# min_f, max_f return frequency extremes of the map
f.sort()
X = np.arange(f[0], f[3], RESOLUTION)
Y1 = np.zeros_like(X)
Y2 = np.zeros_like(X)
i1 = int(np.round(self.X[0] / RESOLUTION))
i2 = int(np.round(self.X[-1] / RESOLUTION)) + 1
np.copyto(Y1[i1:i2], self.Y)
i1 = int(np.round(p.X[0] / RESOLUTION))
i2 = int(np.round(p.X[-1] / RESOLUTION)) + 1
np.copyto(Y2[i1:i2], p.Y)
Y = Y1 + Y2
return FrequencyProfile(X, Y)
But the sound generated from the map differed greatly from the original, even though it looked right when plotted. Something was lost in the translation.
After searching all I could, I've failed to find a good solution. Do you know of any?