# Not able to reach minimum phase using Hilbert transform

My problem is pretty simple, I've designed a magnitude response and I would like to find the corresponding minimum phase filter. I'm using the code below and unless there is a bug my eyes don't want to see, I'm pretty confident on the methodology.

nbTaps = 100;
fs = 96000;
desiredMagn_dB = [0 0 -100 -100];
f = [0 24000 26000 fs/2];

FIRFreq = (0:nbTaps/2)*fs / nbTaps;

FIRMagn = interp1(f, 10.^(desiredMagn_dB./20), FIRFreq);
FIRMagn = [FIRMagn fliplr(FIRMagn(2:end-1))];

minPhase = -imag(hilbert(log(FIRMagn)));

freqResp = FIRMagn.*exp(1i.*minPhase);

FIRCoefs = ifft(freqResp, 'symmetric');


And yet, my filter has not a minimal phase, since I have zeros outside the unit circle. I am a little bit lost, here, and I would like to understand why is so? or where I am wrong?

EDIT from r b-j:

nbTaps = 16384;
fs = 96000;
desiredMagn_dB = [0 0 -100 -100];
f = [0 24000 26000 fs/2];

FIRFreq = (0:nbTaps/2)*fs / nbTaps;

FIRMagn = interp1(f, 10.^(desiredMagn_dB./20), FIRFreq);
FIRMagn = [FIRMagn fliplr(FIRMagn(2:end-1))];

minPhase = -imag(hilbert(log(FIRMagn)));

freqResp = FIRMagn.*exp(1i.*minPhase);

FIRCoefs = ifft(freqResp, 'symmetric');

figure(1)
plot(20*log10(FIRMagn))
figure(2)
plot(minPhase)
figure(3)
plot(FIRCoefs)


i don't see anything unexpected.

• as a quick response, i am not sure about the minus sign on the instruction minPhase = -imag(hilbert(log(FIRMagn))); it appears that Julius Smith has some MATLAB code. i dunno what interp1() does and i would increase nbTaps and i would simply scale your dB representation to nepers and send that directly to the hilbert() operator. – robert bristow-johnson May 10 at 18:27
• okay, the minus sign is correct. i just checked. – robert bristow-johnson May 10 at 19:01
• Julie, i just ran your script with nbTaps=1024; i don't see what's wrong. – robert bristow-johnson May 10 at 19:07
• Thank you Robert for your answer. Two things I don't understand. First, to be sure I have a minimum phase, I run the Matlab function "isminphase" which answers no with 100 taps or 16834. – Julie May 13 at 10:23
• Second, if you zoom in FIRCoefs: figure(3) plot(FIRCoefs) axis([1 length(FIRCoefs) -.001 .001]) You will see a "replica" in the middle of the IR. Why? and where is it coming from? I would have expected a smoothed decline until the end of the impulse response. – Julie May 13 at 10:28