-
Notifications
You must be signed in to change notification settings - Fork 54
/
DocumentNTF.m
executable file
·90 lines (87 loc) · 2.72 KB
/
DocumentNTF.m
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
80
81
82
83
84
85
86
87
88
89
90
function axis_handle = DocumentNTF(arg1,osr,f0,quadrature)
%axis_handle = DocumentNTF(ntf|ABCD|mod_struct,osr=64,f0=0,quadrature=0) Plot the NTF's poles and zeros as well as its frequency-response
%
% The first argument is either the NTF, ABCD matrix or a struct containing
% ntf, osr=64, f0=0, quadrature=0 and optionally stf.
% If the first argument is a struct, then no other arguments should be supplied.
% If the first argument is ABCD, the stf is also plotted.
% Handle the input arguments
parameters = {'arg1' 'osr' 'f0' 'quadrature'};
defaults = { [] 64 0 0 };
for arg_ii=1:length(defaults)
parameter = parameters{arg_ii};
if arg_ii>nargin | ( eval(['isnumeric(' parameter ') ']) & ...
eval(['any(isnan(' parameter ')) | isempty(' parameter ') ']) )
eval([parameter '=defaults{arg_ii};'])
end
end
if nargin==1 & isstruct(arg1)
flattenStruct(arg1);
for arg_ii=2:length(defaults)
parameter = parameters{arg_ii};
if ~exist(parameter,'var')
eval([parameter '=defaults{arg_ii};'])
end
end
elseif isnumeric(arg1)
ABCD = arg1;
[ntf stf] = calculateTF(ABCD);
else
ntf = arg1;
end
set(gcf,'name','NTF')
set(gcf,'numbertitle','off');
set(gcf,'MenuBar','none');
% Plot poles and zeros
clf;
ax_handle(1) = subplot('position',[.05 .15 .25 .65]);
plotPZ(ntf,'b',6);
axis([-1.1 1.1 -1.1 1.1]);
set(gca,'XTick', [-1:0.5:1]);
set(gca,'XTickLabel', {'-1','','0','','1'});
set(gca,'YTick', [-1:0.5:1]);
set(gca,'YTickLabel', {'-1','','0','','1'});
title('Poles and Zeros');
% Frequency response
ax_handle(2) = subplot('position', [0.37,0.1,0.6 0.8]);
f = ds_freq(osr,f0,quadrature);
z = exp(2i*pi*f);
H = dbv(evalTF(ntf,z));
plot(f,H,'b');
if exist('stf','var') & ~isempty(stf)
set(gcf,'name','NTF and STF')
G = dbv(evalTF(stf,z));
hold on;
plot(f,G,'m');
hold off;
end
[f1 f2] = ds_f1f2(osr,f0,quadrature);
NG0 = dbv(rmsGain(ntf,f1,f2));
hold on;
plot([f1 f2],NG0*[1 1],'k','Linewidth', 3);
if f0==0
text(0.5/osr,NG0,sprintf(' %.0fdB',NG0),'Vert','Mid','Hor','Left');
else
text(f0,NG0+1,sprintf('%.0fdB',NG0),'Vert','Bot','Hor','Cen');
end
msg = sprintf(' Inf-norm of H=%.2f\n 2-norm of H=%.2f', infnorm(ntf), rmsGain(ntf,0,1));
if f0<0.25
text(0.48,0,msg,'Vert','Top','Hor','Right');
else
text(f_left,0,msg,'Vert','Top');
end
if quadrature
ING0 = dbv(rmsGain(ntf,-f1,-f2));
plot(-[f1 f2],ING0*[1 1],'k','Linewidth', 3);
text(-f0,ING0+1,sprintf('%.0fdB',ING0),'Vert','Bot','Hor','Cen');
f_left = -0.5;
else
f_left = 0;
end
figureMagic([f_left,0.5],1/16,2, [-80 15],10,2);
xlabel('frequency');
% text(0.25,-85,'Normalized frequency (1\rightarrow f_s)','hor','center');
title('Frequency Response');
if nargout>0
axis_handle = ax_handle;
end