-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_transferFunction.m
More file actions
72 lines (63 loc) · 1.77 KB
/
Copy pathplot_transferFunction.m
File metadata and controls
72 lines (63 loc) · 1.77 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
67
68
69
70
71
72
function [h] = plot_transferFunction(freq,gain,plotParams)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if nargin < 1 || isempty(freq), freq = [.25 .5 1 2 4 8]*1000; end
if nargin < 2 || isempty(gain), gain = [1 4 7 NaN 5 2]; end
if nargin < 3 || isempty(plotParams), plotParams = struct; end
% set default plotting params
defaultParams.freqUnits = 'kHz';
defaultParams.logBase = 10;
defaultParams.ylim = [-20 50];
defaultParams.bConnectLines = 1;
defaultParams.bLogFreq = 1;
defaultParams.bGrid = 1;
defaultParams.bGridMinor = 1;
defaultParams.numMinorGridlines = [];
defaultParams.bBlank = 0;
defaultParams.bKey = 0;
plotParams = set_missingFields(plotParams,defaultParams,0);
% plot transfer function
h = figure;
if ~plotParams.bBlank
plot(freq,gain,'o')
hold on;
plot(freq,gain,'--');
end
if plotParams.bLogFreq
set(gca,'Xscale','log');
end
ylim(plotParams.ylim);
if plotParams.bGrid
grid on;
end
if plotParams.bGridMinor
grid minor;
if plotParams.numMinorGridlines
ax = gca;
ytix = yticks;
majorTickIntervals = diff(ytix);
minorTickInterval = majorTickIntervals(1)/plotParams.numMinorGridlines;
minorTickValues = ytix(1):minorTickInterval:ytix(end);
ax.YAxis.MinorTickValues = minorTickValues;
end
end
if plotParams.bLogFreq
switch plotParams.logBase
case 2
xtix = [.25 .5 1 2 4 8]*1000;
xlim([200 10000]);
case 10
xtix = [.1 1 10]*1000;
xlim([100 10000]);
end
xticks(xtix);
else
xtix = xticks;
end
if strcmp(plotParams.freqUnits,'kHz')
xticklabels(compose('%g',xtix/1000));
end
xlabel(['frequency (' plotParams.freqUnits ')']);
ylabel('gain (dB)');
makeFig4Screen;
set(h,'Position',[100 100 450 433]);