Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 23 Set 2018
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 Commenti
Walter Roberson
Walter Roberson il 26 Set 2018
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))

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by