I try to design a FIR All-pass filter with random phase in the frequency domain. I am a bit confused by my result and am not sure if the reason is a programming error or a misconception about convolution and impulse response of myself. I use Python and Numpy:
import numpy as np mag = np.ones(129) # magnitude is unitiy phase = np.zeros(129) random_numbers = (np.random.rand(128)-0.5)*2.0 phase[1:] = random_numbers * np.pi # phase is random except for dc offset spec = mag*np.exp(phase * 1j) # get spectrum from magnitude and phase coefficients = np.fft.irfft(spec) # do inverse fft to get coefficents, result is of length 256
If I do a fft on my coefficients the magnitude looks nearly right. My first question: Why is the highest frequency suppressed?
And secondly, if I use my coefficients for convolving with an impulse, I thought that should reproduce the coefficients? But it does not. Why are there these "random variations" around 1.0?
impulse = np.zeros(256, dtype=np.float64) # create impulse impulse[256/2] = 1.0 result = np.convolve(impulse, coefficients, "same") # convolve it
Any explanations or hints are much appreciated!