# Design Filter with Arbitrary Magnitude and Phase Response in Matlab

Does anyone know of a way to design a filter with arbitrary magnitude and phase response in Matlab?

• also, if your filter is causal, you can't do whatever magnitude and phase you want. you might have to toss is some constant delay or linear-phase term in the phase, just to get a causal impulse response. if it's causal, then $\Re\left\{H[k]\right\}$ and $\Im\left\{H[k]\right\}$ are a Hilbert transform pair. May 4 '15 at 1:22
• What do you actually mean by arbitrary magnitude and phase response, do you mean that you can specify the filter in the frequency domain as a function, or only specify a finite number of points? Jun 3 '15 at 3:04

for FIR, the simplest way is to inverse FFT you two-sided complex frequency response:

$$h[n] = \operatorname{iFFT} \left\{ H[k] \right\}$$

(use a Kaiser window to window the FIR to a length that is acceptable to implement.)

so first divide your complex frequency response into real and imaginary parts:

$$H_r[k] = |H[k]| \cos\left(\arg\{H[k]\} \right)$$ $$H_i[k] = |H[k]| \sin\left(\arg\{H[k]\} \right)$$

send both $H_r[k]$ and $H_i[k]$ to the Parks-McClellan or Least Squares optimal FIR designer, but set ftype to 'hilbert' for $H_i[k]$.

sum the two resulting real-valued FIRs to get your result.

lastly, if you want to design an IIR to an arbitrary magnitude and phase spec, then that's a much bigger problem and consideration. maybe use Prony to design to your impulse response $h[n]$ or use Matt's dissertation that i first learned of now, or use Greg Berchin's FDLS. i dunno. no quick solution for you there.

• I'm trying to find more information on the method that devides the response in real and imaginary parts and designs filters for them separately. It sounds promising for my application but I wonder what this technique is called and why it works. Aug 20 '18 at 11:39
• I wonder the same things. It doesn't work for me at all. Feb 25 at 20:46
• What did you do? Feb 26 at 13:06

There's a PhD thesis with exactly this phrase in its title (including Matlab programs):

Algorithms for the Constrained Design of Digital Filters with Arbitrary Magnitude and Phase Responses

• at first i thought it was in Deutsche (it's not, thankfully for me) but the next obstacle is reading it without reading it online. do you have it in .pdf, Matt? May 4 '15 at 0:56