Skip to content

Commit a600187

Browse files
author
taylora
committed
Initial import of Taylor Matlab Toolbox. This is v1.10.
1 parent 422111b commit a600187

File tree

374 files changed

+12513
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

374 files changed

+12513
-0
lines changed

689_032_0002.abf

1.91 MB
Binary file not shown.

basics/alias_frequency.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function f_alias=f(f_true,f_sampling)
2+
3+
f_alias=abs(f_true-f_sampling*round(f_true/f_sampling));
4+

basics/antilogistic.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function x = f(y)
2+
3+
% all elements of y must be in the interval (0,1)
4+
5+
dims=size(y);
6+
lower_bound=repmat(1e-15,dims);
7+
upper_bound=repmat(1-1e-15,dims);
8+
y=max(y,lower_bound);
9+
y=min(y,upper_bound);
10+
x = -log(y.^(-1)-1);
11+

basics/bit_reverse.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function rev_n=f(n)
2+
3+
% i should be a uint8
4+
% this is probably hecka slow
5+
% if you're using this, you should think about using bitrevorder
6+
7+
rev_n=uint8(0);
8+
for j=1:8
9+
rev_n=bitset(rev_n,j,bitget(n,9-j));
10+
end

basics/break_at_wrap_points.m

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
function [x_seg,y_normed_seg,y_eb_normed_seg] = ...
2+
break_at_wrap_points(x,y,y_lim,y_eb)
3+
4+
% this function breaks an angular quantity y wherever it passes the "wrap
5+
% points" in y_lim. For instance, y might be an angle in radians, and
6+
% y_lim might equal [-pi +pi]. It returns x_seg and y_normed_seg, both
7+
% cell arrays of "segments". If y crosses the wrap limits n_break times,
8+
% then there will be n_break+1 segments, each containing a stretch of
9+
% values where y did not cross the wrap limits. Any y_normed_seg{i}(j),
10+
% for all i and j, will be s.t. y_lim(1) <= y_normed_seg{i}(j) <= y_lim(2).
11+
% This is useful is you would like to plot an angular quantity, for
12+
% instance. The function is smart about interpolating near the break
13+
% points so that the segments end exactly at the y limits, not just near
14+
% them. If the y_eb argument is provided, this error bar is also wrapped
15+
% appropriately, and y_eb_normed_seg{i}(j,:) is the wrapped error bar for
16+
% y_eb_normed_seg{i}(j). Note however that the error bar limits can lie
17+
% outside of [y_lim(1),y_lim(2)]. (This is usually a good thing for
18+
% plotting purposes.)
19+
%
20+
% we assume x, y, are col vectors of length n
21+
% we assume y_lim is 2x1, with y_lim(1)<y_lim(2)
22+
% if present, we assume y_eb is n x 2, with
23+
% y_eb(i,1) <= y_eb(i,2) for all i
24+
25+
% deal with args
26+
calc_error_bars=(nargin>=4);
27+
if nargin<4
28+
calc_error_bars=false;
29+
y_eb_normed_seg=[];
30+
else
31+
calc_error_bars=true;
32+
end
33+
34+
% figure out where the breaks are
35+
y_lo=y_lim(1);
36+
y_hi=y_lim(2);
37+
y_span=y_hi-y_lo;
38+
y_shift=y-y_lo;
39+
y_phase=y_shift/y_span;
40+
% y_phase takes on integer values at wrap points
41+
y_n_wraps=floor(y_phase);
42+
% y_n_wraps is the (signed) number of times you pass the wrap point in
43+
% going from between y_lo and y_hi to that value of y.
44+
i_break=find(diff(y_n_wraps)~=0);
45+
% there's a break between i_break(j) and i_break(j)+1, for all j
46+
n_break=length(i_break);
47+
n_seg=n_break+1; % a "seg" (==segment) is a run between breaks
48+
% there's also a seg before the first break, and after the last
49+
50+
% calculate the x coordinate of each break
51+
x_break=zeros(n_break,1);
52+
for i=1:n_break
53+
j=i_break(i);
54+
x_break(i)=interp1([y_phase(j);y_phase(j+1)],...
55+
[x(j);x(j+1)],...
56+
max(y_n_wraps(j),y_n_wraps(j+1)));
57+
end
58+
59+
%
60+
% useful quantities for making the segments
61+
%
62+
n_wraps_seg=[y_n_wraps(i_break);y_n_wraps(end)];
63+
% n_wraps_seg gives the value of y_n_wraps for each seg (y_n_wraps is
64+
% constant within a seg)
65+
66+
% calculate the offset of the error bars from y
67+
if calc_error_bars
68+
dy_eb=y_eb-repmat(y,[1 2]);
69+
end
70+
71+
% calc the version of y restricted to the bounds
72+
y_normed =y -y_n_wraps*y_span; % y_lo <= this < y_hi
73+
if calc_error_bars
74+
y_eb_normed=repmat(y_normed,[1 2])+dy_eb;
75+
end
76+
77+
% calculate the value of y on either side of each break
78+
y_normed_break_pre =y_span*(1+diff(n_wraps_seg))/2+y_lo;
79+
y_normed_break_post=y_span*(1-diff(n_wraps_seg))/2+y_lo;
80+
if isempty(y_normed_break_pre)
81+
% this matters downstream
82+
y_normed_break_pre =zeros(0,1);
83+
y_normed_break_post=zeros(0,1);
84+
end
85+
86+
% calculate the offset of the error bars from y at each break
87+
if calc_error_bars
88+
y_break=interp1(x,y,x_break);
89+
y_eb_break=interp1(x,y_eb,x_break);
90+
dy_eb_break=y_eb_break-repmat(y_break,[1 2]);
91+
end
92+
93+
% calculate the error bars on either side of each break
94+
if calc_error_bars
95+
y_eb_normed_break_pre =repmat(y_normed_break_pre ,[1 2])+dy_eb_break;
96+
y_eb_normed_break_post=repmat(y_normed_break_post,[1 2])+dy_eb_break;
97+
end
98+
99+
% make the segments
100+
x_seg=cell(n_seg,1);
101+
y_normed_seg=cell(n_seg,1);
102+
for i=1:n_seg
103+
if i==1 && i==n_seg
104+
% i.e., if there are no breaks
105+
x_seg{i}=x;
106+
y_normed_seg{i}=y_normed;
107+
if calc_error_bars
108+
y_eb_normed_seg{i}=y_eb_normed;
109+
end
110+
elseif i==1
111+
x_seg{i}=[x(1:i_break(1)) ; ...
112+
x_break(1)];
113+
y_normed_seg{i}=[y_normed(1:i_break(1)) ; ...
114+
y_normed_break_pre(1)];
115+
if calc_error_bars
116+
dy_eb_normed_seg_this=...
117+
[dy_eb(1:i_break(1),:) ; ...
118+
dy_eb_break(1,:) ];
119+
y_eb_normed_seg{i}=repmat(y_normed_seg{i},[1 2])+...
120+
dy_eb_normed_seg_this;
121+
end
122+
elseif i==n_seg
123+
x_seg{i}=[x_break(end) ; ...
124+
x(i_break(end)+1:end)];
125+
y_normed_seg{i}=[y_normed_break_post(end) ; ...
126+
y_normed(i_break(end)+1:end)];
127+
if calc_error_bars
128+
dy_eb_normed_seg_this=...
129+
[dy_eb_break(end,:) ; ...
130+
dy_eb(i_break(end)+1:end,:) ]; ...
131+
y_eb_normed_seg{i}=repmat(y_normed_seg{i},[1 2])+...
132+
dy_eb_normed_seg_this;
133+
end
134+
else
135+
x_seg{i}=[x_break(i-1);...
136+
x(i_break(i-1)+1:i_break(i));...
137+
x_break(i)];
138+
y_normed_seg{i}=[y_normed_break_post(i-1); ...
139+
y_normed(i_break(i-1)+1:i_break(i)); ...
140+
y_normed_break_pre(i)];
141+
if calc_error_bars
142+
dy_eb_normed_seg_this=[dy_eb_break(i-1,:); ...
143+
dy_eb(i_break(i-1)+1:i_break(i),:); ...
144+
dy_eb_break(i,:)];
145+
y_eb_normed_seg{i}=repmat(y_normed_seg{i},[1 2])+...
146+
dy_eb_normed_seg_this;
147+
end
148+
end
149+
end

basics/cclf.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
clear;
2+
close all;

basics/coeff_of_var_est.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function result = f(data)
2+
3+
% data must be a vector
4+
% result is square root of the "S squared" stat over the "x bar" stat
5+
% I don't really know much about what you can say about how this relates to
6+
% sqrt(Var[X]])/E[X]. Is it biased? Are there other estimators of this
7+
% quantity that strictly dominate it in terms of squared-error risk? I have
8+
% no idea...
9+
10+
n=length(data);
11+
x_bar=mean(data);
12+
std_dev_est=sqrt(sum((data-x_bar).^2)/(n-1));
13+
result=std_dev_est/x_bar;

basics/colormaps/bipolar.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function cmap=bipolar(varargin)
2+
3+
if nargin<1
4+
n=256;
5+
else
6+
n=varargin{1};
7+
end
8+
9+
% n is the number of colors
10+
clr_pos=[0 1 0];
11+
clr_neg=[1 0 0];
12+
13+
clr_pos_lab=srgb2lab(clr_pos);
14+
clr_neg_lab=srgb2lab(clr_neg);
15+
16+
n_half=ceil(n/2);
17+
scale=linspace(0,1,n_half)';
18+
cmap_pos_lab=repmat(scale,[1 3]).*repmat(clr_pos_lab,[n_half 1]);
19+
cmap_neg_lab=repmat(scale,[1 3]).*repmat(clr_neg_lab,[n_half 1]);
20+
if mod(n,2)==0
21+
cmap_lab=[flipud(cmap_neg_lab);cmap_pos_lab];
22+
else
23+
cmap_lab=[flipud(cmap_neg_lab); 0 0 0; cmap_pos_lab];
24+
end
25+
cmap=lab2srgb(cmap_lab);
26+
cmap=max(min(cmap,1),0);

basics/colormaps/blue_off_edge.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function color_map=f(L,x)
2+
3+
% L is a scalar, x is a col vector
4+
5+
% this is the RGB-to-XYZ matrix
6+
M=[0.412453 0.357580 0.180423;
7+
0.212671 0.715160 0.072169;
8+
0.019334 0.119193 0.950227];
9+
10+
% this is the code
11+
n_samples=length(x);
12+
Y=l2y(L);
13+
r=1-x;
14+
g=ungamma_srgb( (Y-M(2,1)*gamma_srgb(1-x)) / M(2,2) );
15+
b=repmat(0,[n_samples 1]);
16+
color_map=[r g b];
17+

basics/colormaps/blue_on_edge.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function sRGB=f(L,x)
2+
3+
% L is a scalar, x is a col vector
4+
5+
% this is the RGB-to-XYZ matrix
6+
M=[0.412453 0.357580 0.180423;
7+
0.212671 0.715160 0.072169;
8+
0.019334 0.119193 0.950227];
9+
10+
% this is the code
11+
n_samples=length(x);
12+
Y=l2y(L);
13+
r=x;
14+
g=ungamma_srgb( (Y-M(2,1)*gamma_srgb(x)-M(2,3)) / M(2,2) );
15+
b=repmat(1,[n_samples 1]);
16+
sRGB=[r g b];
17+

basics/colormaps/blue_to_yellow.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function cmap=blue_to_yellow(n)
2+
3+
% deal with args
4+
if nargin<1 || isempty(n)
5+
n=256;
6+
end
7+
8+
% n is the number of colors
9+
clr_pos=[1 1 0]; % yellow
10+
clr_neg=[0 0 1]; % blue
11+
12+
clr_one_lab=srgb2lab(clr_pos);
13+
clr_zero_lab=srgb2lab(clr_neg);
14+
15+
scale=linspace(0,1,n)';
16+
cmap_lab=interp1([0;1],[clr_zero_lab;clr_one_lab],scale);
17+
cmap=lab2srgb(cmap_lab);
18+
cmap=max(min(cmap,1),0);

basics/colormaps/bspectrumw_of_x.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function clr=f(x)
2+
3+
% x is a col vector, on [0,1]
4+
5+
% calculates a color based on x, which goes from blue to cyan to green to
6+
% yellow to red
7+
8+
% the four cases to be handled
9+
x_frac=mod(6*x,1);
10+
x_floor=floor(6*x)+1;
11+
special=(x==1);
12+
x_frac(special)=1;
13+
x_floor(special)=6;
14+
15+
% make weights
16+
n_x=length(x);
17+
w=zeros(n_x,7);
18+
for i=1:n_x
19+
w(i,x_floor(i) )=1-x_frac(i);
20+
w(i,x_floor(i)+1)= x_frac(i);
21+
end
22+
23+
% the colors
24+
C=[0 0 0;...
25+
0 0 1;...
26+
0 1 1;...
27+
0 1 0;...
28+
1 1 0;...
29+
1 0 0;...
30+
1 1 1];
31+
32+
% do the matrix mult
33+
clr=w*C;

basics/colormaps/bspectrumw_smooth.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function cmap=f(n_colors)
2+
3+
% generate a non-smooth colormap on a very fine grid
4+
% calculate the path length, and from that get the phase for each
5+
% point on the fine grid
6+
n_samples=4096;
7+
x=linspace(0,1,n_samples)';
8+
clr=bspectrumw_of_x(x);
9+
clr_lab=srgb2lab(clr);
10+
ds=dist_lab(clr_lab(1:end-1,:),clr_lab(2:end,:));
11+
s=[0 ; cumsum(ds)];
12+
phase=s/s(end); % normalized path length
13+
14+
% make a colormap with inter-color spacings equal
15+
phase_samples=linspace(0,1,n_colors)';
16+
x_samples=interp1(phase,x,phase_samples,'linear');
17+
cmap=bspectrumw_of_x(x_samples);

basics/colormaps/bw_of_x.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function clr=f(x)
2+
3+
% x is a col vector, on [0,1]
4+
5+
clr=x*[1 1 1];

basics/colormaps/bw_smooth.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function cmap=f(n_colors)
2+
3+
% generate a non-smooth colormap on a very fine grid
4+
% calculate the path length, and from that get the phase for each
5+
% point on the fine grid
6+
n_samples=4096;
7+
x=linspace(0,1,n_samples)';
8+
clr=bw_of_x(x);
9+
clr_lab=srgb2lab(clr);
10+
ds=dist_lab(clr_lab(1:end-1,:),clr_lab(2:end,:));
11+
s=[0 ; cumsum(ds)];
12+
phase=s/s(end); % normalized path length
13+
14+
% make a colormap with inter-color spacings equal
15+
phase_samples=linspace(0,1,n_colors)';
16+
x_samples=interp1(phase,x,phase_samples,'linear');
17+
cmap=bw_of_x(x_samples);

basics/colormaps/coh2l75_border.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function im=coh2l75_border(z,z_thresh)
2+
3+
% z is mxn of complex, assumed to have mag(z)<=1
4+
% im is mxnx3, RGB image
5+
6+
if nargin<2 || isempty(z_thresh)
7+
z_thresh=0;
8+
end
9+
10+
n_clr=1000;
11+
cmap_outer_rgb=l75_border(n_clr);
12+
cmap_outer_lab=srgb2lab(cmap_outer_rgb);
13+
z_mag=abs(z);
14+
z_phase=wrap(angle(z));
15+
% deal with NaN's, infs, etc.
16+
messed=~isfinite(z_mag);
17+
z_mag(messed)=0;
18+
z_phase(messed)=0;
19+
% deal with values that might be (hopefully only slightly) out of bounds
20+
z_mag=min(max(z_mag,0),1);
21+
im_l=75*z_mag;
22+
im_l(z_mag<z_thresh)=0;
23+
ind=round((n_clr-1)*(((z_phase/pi)+1)/2))+1;
24+
im_lab_r_max=reshape(cmap_outer_lab(ind,:),[size(z) 3]);
25+
im_ab_r_max=im_lab_r_max(:,:,2:3);
26+
im_ab=repmat(z_mag,[1 1 2]).*im_ab_r_max;
27+
%im_ab=im_ab_r_max;
28+
im_lab=zeros([size(z) 3]);
29+
im_lab(:,:,1)=im_l;
30+
im_lab(:,:,2:3)=im_ab;
31+
32+
% convert Lab to sRGB
33+
im_lab_rows=reshape(im_lab,[size(z,1)*size(z,2) 3]);
34+
im_rows=lab2srgb(im_lab_rows);
35+
im=reshape(im_rows,[size(z) 3]);
36+
im=min(max(im,0),1); % some things might be a little bit out-of-bounds

0 commit comments

Comments
 (0)