-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotdatagram.m
More file actions
164 lines (134 loc) · 4.43 KB
/
Copy pathplotdatagram.m
File metadata and controls
164 lines (134 loc) · 4.43 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function [s, c, datagramplt] = plotdatagram(datagram, metadata, varargin)
%PLOTDATAGRAM Plots a datagram
% [S, C, DATAGRAMPLT] = PLOTDATAGRAM(DATAGRAM, SR) plots a DATAGRAM on
% frequency time surface. METADATA contains info on the datagram. S is
% the handle for the surface and C is the handle for the colourbar.
% DATAGRAMPLT is the plotted surface data,
%
% [S, C, DATAGRAMPLT] = PLOTDATAGRAM(DATAGRAM, SR, VARARGIN) adds
% additional arguments via VARARGIN. These are string, value pairs;
% * 'UseKhz' - true to plot frequency as kHz;
% * 'MaxSurfaceSize' - the maximum allowed surface length before
% interpolation occurs. Interpolation will reduce the surface to this
% size.
% * '0isNaN' - true to plot frequency as kHz;
% * 'plot' - true to plot the calculated surface on a figure. False means
% the function only returns
usekHz= true; % use kHz
maxsurfacesize = 10000;
zeroisNan = true; % zero values should be coloured as NaN values
plotsurf = true; % true to actually do the plotting.
iArg = 0;
while iArg < numel(varargin)
iArg = iArg + 1;
switch(varargin{iArg})
case 'UsekHz'
iArg = iArg + 1;
usekHz = varargin{iArg};
case 'MaxSurfaceSize'
iArg = iArg + 1;
maxsurfacesize = varargin{iArg};
case '0isNaN'
iArg = iArg + 1;
zeroisNan = varargin{iArg};
case 'plot'
iArg = iArg + 1;
plotsurf = varargin{iArg};
end
end
sR= metadata.sR;
minmaxtime = metadata.minmaxtime;
timebins = linspace(minmaxtime(1), minmaxtime(2), length(datagram(1,:)));
if (isempty(metadata.freqbins))
freqbins = linspace(0, sR/2, length(datagram(:,1)));
else
freqbins=metadata.freqbins;
end
[X, Y] = meshgrid(...
timebins,...
freqbins);
if usekHz
Y=Y./1000;
end
% first method works but all nan is zero and thus blue whihc indicates that
% there was some data there - nicer if white...
% % re interpolate a surface...
% if (length(timebins)>maxsurfacesize)
% %// identify indices valid for the 3 matrix
% idxgood=~(isnan(X) | isnan(Y) | isnan(datagram));
%
% [Xq, Yq] = meshgrid(...
% linspace(minmaxtime(1), minmaxtime(2), maxsurfacesize),...
% linspace(0, sR/2, length(datagram(:,1))));
%
% %// re-interpolate scattered data (only valid indices) over the "uniform" grid
% datagramCI = griddata( X(idxgood),Y(idxgood),datagram(idxgood), Xq, Yq );
%
% % datagram = interp2(X,Y,datagram,Xq,Yq);
% datagram=datagramCI;
% X=Xq;
% Y=Yq;
% end
% re interpolate a surface...
if (length(timebins)>maxsurfacesize)
% % first remove NAN values if duty cycled
% indexrmv =[];
% for i=1:length(datagram(1,:))
% if sum(~isnan(datagram(:,i)))==0
% indexrmv = [indexrmv i];
% end
% end
%
% X(:,indexrmv) = [];
% Y(:,indexrmv) = [];
% datagram(:,indexrmv) = [];
%if still too big interpolate.
% do not interpoate if noise as this is a log scale and causes all sorts of
% issues.
if (length(X(1,:))>maxsurfacesize && metadata.datatype~=3)
[Xq, Yq] = meshgrid(...
linspace(minmaxtime(1), minmaxtime(2), maxsurfacesize),...
linspace(0, sR/2, length(datagram(:,1))));
if usekHz
Yq=Yq./1000;
end
%// re-interpolate scattered data (only valid indices) over the "uniform" grid
% datagramCI = griddata(X,Y,datagram, Xq, Yq );
datagram = interp2(X,Y,datagram,Xq,Yq);
% datagram=datagramCI;
X=Xq;
Y=Yq;
end
end
if (plotsurf)
s = surf(X, Y, datagram, 'EdgeColor', 'interp');
if (usekHz)
ylabel('Frequency (kHz)')
else
ylabel('Frequency (Hz)')
end
xlabel('Time')
% datetick x
xlim([minmaxtime(1), minmaxtime(2)])
freqlimits=[0, max(freqbins)];
if usekHz
freqlimits=freqlimits/1000.;
end
ylim(freqlimits);
% colormap Jet
c = colorbar;
c.Label.String = metadata.datagramname;
view([0,90])
cmap = colormap('Jet');
if (zeroisNan)
cmap(1,:) = [1, 1, 1]; % white
end
colormap(cmap);
else
s=[];
c=[];
end
datagramplt.datagram=datagram;
datagramplt.X = X;
datagramplt.Y = Y;
end