-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSRSbode.m
More file actions
66 lines (57 loc) · 1.65 KB
/
SRSbode.m
File metadata and controls
66 lines (57 loc) · 1.65 KB
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
function SRSbode(varargin)
% make bode plot of exported SRS plot in .mat format
% input is nx2 matrix, first column is frequencies, second is complex
% transfer function value.
% check for options
unwrapflag = 0;
flagIndex = find(strncmp(varargin,'-',1),2); % find the option flag
if length(flagIndex)>1
error('Please only use the option flag "-" once in arguments.')
end
if flagIndex
if any(varargin{flagIndex}=='u') || any(varargin{flagIndex}=='U')
unwrapflag = 1; % unwrap flag
end
varargin = {varargin{1:end~=flagIndex}}; % remove options from the arguments
end
colorlist = { [1 1 1], [1 0 0], [0 1 0], [0 0 1], [218/255 165/255 32/255], [.75 .25 .75], [0 1 1] };
for j=1:length(varargin)
M=varargin{j};
subplot(2,1,1)
loglog(M(:,1),abs(M(:,2)),'Color',colorlist{mod(j,length(colorlist))+1})
hold on
subplot(2,1,2)
if(unwrapflag)
semilogx(M(:,1),180/pi*unwrap(angle(M(:,2))),'Color',colorlist{mod(j,length(colorlist))+1})
else
semilogx(M(:,1),180/pi*angle(M(:,2)),'Color',colorlist{mod(j,length(colorlist))+1})
end
hold on
maxnow = max(M(:,1));
minnow = min(M(:,1));
if ~exist('minf','var') || minnow<minf
minf = minnow;
end
if ~exist('maxf','var') || maxnow>maxf
maxf = maxnow;
end
end
subplot(2,1,1)
title('Bode Diagram')
ylabel('Magnitude')
xlim([minf,maxf])
ylim('auto')
grid on
hold off
subplot(2,1,2)
xlabel('Frequency (Hz)')
ylabel('Phase (deg)')
xlim([minf,maxf])
if(unwrapflag)
ylim('auto')
else
ylim([-200,200])
end
grid on
hold off
subplot(2,1,1) % end with mag selscted