# Design of FIR Filters with Arbitrary Magnitude and Phase Responses

I found many information in this thesis "Algorithms for the Constrained Design of Digital Filters with Arbitrary Magnitude and Phase Responses",i want to understand it.

This question is a continuation of a previous question(Complex Least Squares Approximation).

$$H(e^{j\omega})=\sum_{n=0}^{N-1}h[n]e^{-jn\omega}=\mathbf{c}^H(\omega)\cdot \mathbf{h}\tag{1}$$

I want to approximate (1) by the following desired frequency response:

$$D(\omega)=M(\omega)e^{jP(\omega)}\tag{2}$$

My problem with this specifications :

• Frequency domain specification is not symmetrical (linear phase filter with not symmetric impulse response),with order of filter and constant group delay, constant weighting function .

1-Before to start the design filter, must be know the problem is linear or no,does this have relation by 'h'?

In the case of FIR filters, we formulate the design problem using the complex least squares .The passband error function is

$$E(\mathbf{h})=\int_{\omega_1}^{\omega_2}| H(e^{j\omega})-D(e^{j\omega})|^2d\omega \tag{3}$$

How can i solve the integral in this case?or what is the steps which allow me to formulate an equation by least squares?

In complex leastsquares there is continuous and discrete approximation .However, often these integrals cannot be solved analytically.In this case one either has to resort to numerical integration or formulate the problem a priori as a discrete approximation problem. What is the better for (3)?use the continuous or discrete approximation?

For the sake of clarity, let me point out that you do not approximate $(1)$ by $(2)$, but the other way around: you approximate a desired frequency response, i.e., your specification, by the filter's frequency response, and this is done by choosing the coefficients in the vector $\mathbf{h}$ such that some error measure (e.g., least squares) is minimized.

Since the frequency response $(1)$ is linear in $\mathbf{h}$, the problem is a linear least squares problem, which can be solved by solving a system of linear equations. This is true for the continuous error measure $(3)$ as well as for the discrete error measure

$$E(\mathbf{h})=\sum_{k=1}^K|H(e^{j\omega_k})-D(e^{j\omega_k})|^2\tag{1}$$

where $K$ is the number of discrete frequency points $\omega_k$. In general we require $K\gg N$, where $N$ is the number of FIR filter coefficients in the vector $\mathbf{h}$.

In the general case it is more convenient to use the discrete error measure $(1)$. There are only a few special cases in which the integral of the continuous error measure (Eq. $(3)$ in your question) can be solved analytically, otherwise you have to resort to numerical approximations anyway. And even if an analytical solution is available, the difference when minimizing the discrete error measure is negligible if the number of frequency points $K$ is sufficiently large.

Minimizing the discrete squared error $(1)$ is equivalent to solving the following overdetermined linear system of equations in a least squares sense:

$$H(e^{j\omega_k})\stackrel{!}{=}D(e^{j\omega_k}),\qquad k=1,2,\ldots,K\tag{2}$$

Formulation $(2)$ is convenient because many software packages such as Matlab have syntactically elegant and computationally efficient methods to solve such systems.

I've implemented a complex FIR filter design based on solving $(2)$ in the (extremely simple) Matlab/Octave function cfirls.m.

• L :thank you for your answer, i have a question ,how can i find the least-squares error from the function 'cfirls.m'? Aug 13, 2018 at 13:48
• @K.n90: The function doesn't return the error. You can compute it by evaluating the expression given by Eq. (1) in my answer. Aug 13, 2018 at 14:05
• L:what is the better to plot the function ,use the plot or fvtool? Aug 13, 2018 at 16:25
• @K.n90: Just a matter of preference, I always use 'plot'. Try both and see what you like better. Aug 13, 2018 at 16:26
• L:i have a problem in design the filter,if i used 'h=cfirls(N,f,d,w)' , frequency response is H=hexp(-jpi*f*(0:(N-1)))', i don't get a best design ,how can i solve the problem ? Aug 14, 2018 at 10:43