How to solve error using matlab function CFIRPM with function handle?

I want to find FIR filter with the best approximation to the desired frequency response, for that i choose to use the function handle
%the function
function [dh,dw]=fresp(n,f,gf,w)
c = exp(-1i*pi*gf*n/2 );
[dh,dw]=freqz(c);
end
%example to apply function handle (fun_han_cfirpm.m)
n = 22; % Filter order
f = [-1 1]; % Frequency band edges
w = [1 1]; % Weights for optimization
gf = linspace(-1,1,256);
b = cfirpm(n,f,@fresp);
fvtool(b);
The error found
> In crmz (line 112)
In cfirpm (line 336)
In fun_han_cfirpm (line 7)
Warning: Matrix is singular to working precision.
> In crmz (line 112)
In cfirpm (line 336)
In fun_han_cfirpm (line 7)
Warning: Matrix is singular to working precision.
Error using fun_han_cfirpm (line 8)
Coefficients must be finite.
What is the cause of the error?

 Respuesta aceptada

Look at the documentation for cfirpm(). The help documentation says,
B = cfirpm(N,F,@fresp,W) returns a length N+1 FIR filter which has the
best approximation to the desired frequency response as returned by
function @fresp. The function is called from within cfirpm using the
syntax:
[DH,DW] = fresp(N,F,GF,W);
where:
N, F, and W are as defined above.
GF is a vector of grid points which have been linearly interpolated over
each specified frequency band by cfirpm, and determines the frequency
grid at which the response function will be evaluated.
DH and DW are the desired complex frequency response and optimization
weight vectors, respectively, evaluated at each frequency in grid GF.
so your problem is that your fresp is only returning one value, y, instead of returning two values, DH and DW.

6 comentarios

Sandi J
Sandi J el 23 de Sept. de 2018
Editada: Walter Roberson el 24 de Sept. de 2018
I don't know if my handle function is correct,because i have error if i used tow output. what is the problem ?
What value are you returning for the second output m
the value it is the group delay or the phase
I need to see your updated code, and I need to see a complete copy of the error message.
Note that the second output needs to be the optimization weight vectors (whatever that means), not the phase.
I updated the question
The problem with the matrix being singular is due to the first coefficient of the second output of freqz() being returned as 0. You are using that variable as the weight matrix in cfipm, and using zero as a weight is causing a problem.
I really doubt that it is appropriate to use the second output of freqz(), the frequency vector, as the weight matrix for cfipm. It would probably be more appropriate to return
dw = ones(size(gf))

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 23 de Sept. de 2018

Comentada:

el 26 de Sept. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by