필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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?

채택된 답변

Walter Roberson
Walter Roberson 2018년 9월 23일
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
Walter Roberson
Walter Roberson 2018년 9월 26일
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))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by