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

3 ビュー (過去 30 日間)
Sandi J
Sandi J 2018 年 9 月 23 日
コメント済み: Walter Roberson 2018 年 9 月 26 日
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 件のコメント
Sandi J
Sandi J 2018 年 9 月 25 日
I updated the question
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 Center および File ExchangeDigital Filter Design についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by