0
$\begingroup$

Question 1

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

$$H(\mathbf{h})=\sum_{k=1}^Kh[k]e^{j\omega_k}\tag{3}$$

The design of filter in matlab ,if using:

$-$$(1)$ and $(3)$ the length of filter is $K$.

$-$$(2)$ the length of filter is $N$.

  • What is the difference between these two design?
  • Can i use the operation 'transpose' in $D(w)$ and weighting function,length of filter?

Question 2

application in matlab

I used the same functions in 'cfirls' like desired and actual function.

   %% Desired coefficient

   N = 61;              %desired filter length
   tau = 26;            % desired passband group delay
   % frequency grid
   f = [linspace(-1,-.18,164),linspace(-.1,.3,80),linspace(.38,1,124)];  
   % desired frequency response
   d = [zeros(1,164),ones(1,80),zeros(1,124)].*exp(-1i*pi*f*tau);        
   w = [10*ones(1,164),ones(1,80),10*ones(1,124)]; 
   A = w(:,ones(1,N)) .* exp(-1i*pi*f*(0:N-1));
   h = A \ (w.*d);
   %%actual function
   c=[zeros(1,164),ones(1,80),zeros(1,124)]*exp(-1i*pi*f*(0:N-1));
   H=h'.*c;

   %% error function
   E=abs(H-d)^2;
   S=sum(E');

   plot(f,S)

I need in my work to reduce the error as little as possible.How can i changing in this code?

$\endgroup$
4
  • $\begingroup$ Does your code actually run or does it produce an error? $\endgroup$
    – Matt L.
    Aug 16, 2018 at 17:02
  • $\begingroup$ E=abs(H-D)^2; ... where this variable D comes from? $\endgroup$
    – Juha P
    Aug 16, 2018 at 17:22
  • $\begingroup$ @ Matt L , @Juha P : I edited the question, the code actually run . $\endgroup$
    – K.n90
    Aug 16, 2018 at 17:36
  • $\begingroup$ When I try it the code doesn't run, because the matrix dimensions are wrong. Apart from that, what is the problem? How do you know it's not the "best design"? Why is D different from d? You use d to design the filter and then you use D to compute the error, this doesn't make much sense. $\endgroup$
    – Matt L.
    Aug 16, 2018 at 17:49

1 Answer 1

2
$\begingroup$

There are many problems in your question and in your code. First, Eqs $(2)$ and $(3)$ are wrong. Eq. $(2)$ cannot equal Eq. $(1)$ because it is its complex conjugate (and $\mathbf{c}$ is a complex vector). Eq. $(3)$ is meaningless.

I will not rewrite your Matlab code, but you should have added that it doesn't run. There are many errors, among which several incompatible matrix dimensions. You should use the function cfirls instead of just copying some of its code. Then vector dimensions would be checked and care would be taken that all vectors have the same format (I chose columns).

Assuming that all these problems are resolved (simply by calling cfirls with the vectors f, d, and w), you can compute the error, but this is where the next problem occurs. Why don't you just use Eq. $(1)$ in your question to compute the frequency response? (You might as well use the Matlab command freqz). The way you define the matrix c in order to compute the frequency response H doesn't make sense.

Assuming that you manage to compute the designed frequency response on a grid, you could choose to compute the unweighted error, as suggested by your code (even though you minimized a weighted error). However, your variable S will be a scalar (as soon as the code to compute it is fixed). So how do you want to plot it as a function of frequency (as suggested by the last line of your code)?

In sum, apart from using cfirls, which will give you the correct filter coefficients, think about how you should compute the frequency response, and why you defined the matrix c the way you did. Then think about which quantity you would like to plot. As mentioned before, the squared error is just a number, not a function of frequency. It could be useful to plot the magnitude of the difference between desired and designed frequency response:

$$\big|E(\omega)\big|=\big|H(\omega)-D(\omega)\big|\tag{1}$$

With N, f, d, and w defined as in your code, the most straightforward way to do what you're trying to do would be:

h = cfirls(N,f,d,w);
H = freqz(h,1,pi*f);
E = H - d;
plot(f,20*log10(abs(E)))
$\endgroup$
7
  • $\begingroup$ L.thank you for your clear answer,but about the equation (1) i found in certain article is the same (2) ,but with using the transpose operation,is the 'transpose' and 'Hermitien' are similar? $\endgroup$
    – K.n90
    Aug 19, 2018 at 8:38
  • $\begingroup$ The symbol $^H$ means that you transpose and conjugate the vector. This is why Eqs (1) and (2) are not the same. Of course, for any column vectors $a$ and $b$ you have $a^Tb=b^Ta$, but $a^Hb=(b^Ha)^*$, where $*$ means conjugation. $\endgroup$
    – Matt L.
    Aug 19, 2018 at 9:38
  • $\begingroup$ L:in my case can i use just the transpose operation ? $\endgroup$
    – K.n90
    Aug 19, 2018 at 10:24
  • $\begingroup$ @K.n90: Yes, if you transpose you get $\mathbf{h}^T\mathbf{c}^*$. $\endgroup$
    – Matt L.
    Aug 19, 2018 at 10:29
  • $\begingroup$ @K.n90: I don't have access to this article. You could formulate a new question and copy the relevant bit of text/formulas from the article into the question. $\endgroup$
    – Matt L.
    Aug 19, 2018 at 11:03

Your Answer

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

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