0
$\begingroup$

I'm new in DSP. I want to design single pass band FIR filter using LS method. I have this information :

  • one pass band $[-0.1\pi , 0.3\pi]$

  • two stop bands $[-\pi , -0.18\pi]$, $[0.38\pi, \pi]$

  • weighting constant in :

    pass band : $a = 1$ and stop band $b_1=b_2=2$.

In this case, can I use Matlab's firls function? Because we have negative frequency and f is a vector of pairs of frequency points, specified in the range between $0$ and $1$.

$\endgroup$
7
  • $\begingroup$ the short answer is no. $\endgroup$
    – user28715
    Commented Jan 1, 2018 at 16:36
  • $\begingroup$ @StanleyPawlukiewicz hm: this design is symmetrical, just not to f=0; a simple low pass design that's then rotated to be centered around $0.1\pi$ would work, wouldn't it? $\endgroup$ Commented Jan 2, 2018 at 13:46
  • $\begingroup$ @Marcus Müller that's the long answer $\endgroup$
    – user28715
    Commented Jan 2, 2018 at 13:52
  • $\begingroup$ @StanleyPawlukiewicz maybe one of us should actually give that "long" answer as answer; I think you should be the one to get the credit :) But if you don't feel like typing right now, I can write that answer, too. $\endgroup$ Commented Jan 2, 2018 at 14:03
  • 1
    $\begingroup$ @MarcusMüller: Very good! I didn't even notice because I thought it was so straightforward to directly design the complex filter (a two-liner), but this is of course nice for people who want/need to use built-in functions only. Of course, they still need to be fearless enough to implement complex modulation ... $\endgroup$
    – Matt L.
    Commented Jan 2, 2018 at 14:11

1 Answer 1

5
$\begingroup$

As mentioned in a comment, you can't use firls directly because this function only designs real-valued filters with (conjugate) symmetrical frequency responses. Your specification can only be met by a complex-valued filter because the frequency domain specification is not symmetrical.

In principle, you could use firls to design the real part and the imaginary part of the impulse response separately (by using the even and odd parts, respectively, of the frequency domain specification as the desired responses), but in that case you would get discontinuous desired responses, which would result in large approximation errors.

A better and simpler approach is to set up an overdetermined system of complex linear equations and use Matlab/Octave to solve them in a least squares sense. This is very straightforward if you use matrix commands:

N = 51;     % desired filter length
% frequency grid, desired frequency response, weighting function
f = [linspace(-1,-.18,164),linspace(-.1,.3,80),linspace(.38,1,124)];
d = [zeros(1,164),ones(1,80),zeros(1,124)].*exp(-1i*pi*f*(N-1)/2);
w = [2*ones(1,164),ones(1,80),2*ones(1,124)];
f = f(:); d = d(:); w = w(:);

% set up and solve overdetermined linear system
A = w(:,ones(1,N)) .* exp(-1i*pi*f*(0:N-1) );
h = A \ (w.*d);

The resulting filter is complex-valued and has a linear phase response, i.e., the real part of the impulse response is even, and the imaginary part is odd (see figure):

enter image description here

You can further decrease the approximation error by chosing a larger filter length.

I also have a corresponding Matlab/Octave function on GitHub: cfirls.m.

$\endgroup$
6
  • $\begingroup$ The linspace : in the third argument is the number of elements to use between the the range specified with the first and second arguments.I wonder that how do you find this arguments (164,80,124). $\endgroup$
    – K.n90
    Commented Jan 7, 2018 at 10:33
  • $\begingroup$ @K.n90: I just used a total number of frequency points in the range 5-10 times N (filter length). The numbers are chosen such that the grid density is the same in each band (in that specific case I took the bandwidth per band times 4 to get the number of points in that band, but that's just arbitrary). $\endgroup$
    – Matt L.
    Commented Jan 7, 2018 at 11:12
  • $\begingroup$ @ Matt L: are your code represent the approximation the integral squared error where the approximation error as a function of frequency is defined by E(w) = D(w) - H(w), with D(w) being the desired response or the ideal response ,and H(w) being the actual response .If yes, where is the actual response if ''d'' is the desired responce. $\endgroup$
    – K.n90
    Commented Jan 7, 2018 at 12:34
  • $\begingroup$ @K.n90: The actual response is represented by the vector of filter coefficients h. Since it's a frequency domain method you get the matrix with complex exponentials A. A*h is the actual frequency response evaluated on the specified frequency grid. $\endgroup$
    – Matt L.
    Commented Jan 7, 2018 at 12:39
  • $\begingroup$ @ Matt L: If mentioned : the FIR filter have a complex coefficient , is it mean the filter is causal and finite length . If yes,what's the problem we are trying to solve in this type of filter? $\endgroup$
    – K.n90
    Commented Jan 7, 2018 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.