1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA - 1988 - C. Bunks
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
function [xm,fr]=frmag(num,den,npts)
//[xm,fr]=frmag(num[,den],npts)
//Calculates the magnitude of the frequency respones of
//FIR and IIR filters. The filter description can be
//one or two vectors of coefficients, one or two polynomials,
//or a rational polynomial.
//Case 1 (When den is not given):
// num :Vector coefficients/Polynomial/Rational
// :polynomial of filter
//Case 2 (When den is given):
// num :Vector coefficients/Polynomial of filter numerator
// den :Vector coefficients/Polynomial of filter denominator
//Case 1 and 2:
// npts :Number of points desired in frequency response
// xm :Magnitude of frequency response at the points fr
// fr :Points in the frequency domain where
// :magnitude is evaluated
//!
select argn(2)
case 2 then //frmag(sys,npts)
npts=den;
if typeof(num)=="rational" then
h=num;
if size(h,"*")<>1 then
error(msprintf(_("%s: Wrong size for input argument #%d: A single input, single output system expected.\n"),"frmag",1))
end
num=h.num;den=h.den;
elseif typeof(num)=="state-space" then
h=ss2tf(num);
if size(h,"*")<>1 then
error(msprintf(_("%s: Wrong size for input argument #%d: A single input, single output system expected.\n"),"frmag",1))
end
num=h.num;den=h.den;
elseif type(num)==2 then,
if size(num,"*")<>1 then
error(msprintf(_("%s: Wrong size for input argument #%d: A polynomial expected.\n"),"frmag",1));
end
den=poly(1,"z","c");
elseif type(num)==1 then,
num=poly(num,"z","c");
den=1
else
error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),"frmag",1))
end,
case 3 then,//frmag(num,den,npts)
if type(num)==2 then,
if size(num,"*")<>1 then
error(msprintf(_("%s: Wrong size for input argument #%d: A polynomial expected.\n"),"frmag",1));
end
elseif type(num)==1 then,
num=poly(num,"z","c");
else,
error(msprintf(_("%s: Wrong size for input argument #%d: A polynomial expected.\n"),"frmag",1));
end,
if type(den)==2 then,
if size(den,"*")<>1 then
error(msprintf(_("%s: Wrong size for input argument #%d: A polynomial expected.\n"),"frmag",2));
end
elseif type(den)==1 then,
den=poly(den,"z","c");
else,
error(msprintf(_("%s: Wrong size for input argument #%d: A polynomial expected.\n"),"frmag",2));
end,
end
fr=linspace(0,1/2,npts+1);
fr($)=[];
dfr=exp(2*%i*%pi*fr);
xm=abs(freq(num,den,dfr));
endfunction
|