I'm trying to convert a noisy input to fft and extract the signal using a local average.
By the way, after the transformation of fft, it was found that the values of adjacent times of the same frequency and adjacent frequencies of the same time often have a negative correlation. However, when comparing the absolute values of fft, it was confirmed that there was a positive correlation. However, the question arises if it is possible to convert this absolute value back to fft. Is it possible?
It doesn't have to produce exactly the same fft, but humans shouldn't be able to tell the two sounds apart. For example, considering fft as a suitable floating-point matrix, it seems that it is difficult to distinguish if the rotation matrix is multiplied by a matrix.
import scipy.io.wavfile as wav
import scipy.signal
import numpy as np
def fft_to_psd_to_fft(fft):
# fft to psd
psd = abs(fft)
# psd to fft
... # what I want to know
return fft
def rotation_transform(fft):
theta = np.random.randn()
rot_fft = np.einsum("FTC,Cc->FTc", np.stack([fft.real, fft.imag], axis = -1), np.asarray(
[[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]]
))
return rot_fft[..., 0] + 1j * rot_fft[..., 1]
wav to fft
samplerate, samples = wav.read(file_input_path)
frequencies, times, spectrogram = scipy.signal.stft(samples, samplerate, nperseg=511)
what I want to know
spectrogram = fft_to_psd_to_fft(spectrogram)
example case of using rotation matrix
spectrogram = rotation_transform(spectrogram)
fft to wav
r_times, r_samples = scipy.signal.istft(spectrogram, samplerate)
data = np.clip(r_samples, -231, 231 - 1)
data = data.astype(np.int32)
wav.write(file_output_path, samplerate, data)