Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
stochastic
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
Insights
Issues
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
stochasticpublic
stochastic
Commits
062eb3b7
Commit
062eb3b7
authored
Aug 14, 2019
by
Philip Roy Charlton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing because this has now been checked in to the Utilities directory
parent
9f123e1e
Changes
1
Hide whitespace changes
Inline
Sidebyside
Showing
1 changed file
with
0 additions
and
130 deletions
+0
130
CrossCorr/test/coarseGrain_new.m
CrossCorr/test/coarseGrain_new.m
+0
130
No files found.
CrossCorr/test/coarseGrain_new.m
deleted
100644 → 0
View file @
9f123e1e
%
% coarseGrain  coarse grain a frequencyseries
%
% coarseGrain(x, flowy, deltaFy, Ny) returns a frequencyseries structure
% coarsegrained to the frequency values f = flowy + deltaFy*[0:Ny1].
%
% coarseGrain also returns the frequency indices of the lowest and highest
% frequency bins of x that overlap with y (0 <= index1 <= length(x);
% 1 <= index2 <= length(x)+1) and the fractional contributions from these
% frequency bins (note that these indices start from 0 and and are 1 less
% than the corresponding Matlab indices). The fractional contribution is
% the fraction of the fine bin that overlaps with any part of the coarse
% series.
%
% The method used is to treat the xvalues
%
% x(k) = x.flow + (k  1)*x.deltaF
%
% as bin centres and the value x.data(k) as the average value over the
% the bin ie.
%
% (1/x.deltaF)*(integral from the lower edge of the bin to upper edge)
%
% The coarse graining can then be performed by finding the integral
% from the start of the fine series just below the coarse series (via
% the cumulative sum), interpolating to the coarse series, and taking
% differences to recover the average value for each coarse bin.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function
[
y
,
index1
,
index2
,
frac1
,
frac2
]
=
coarseGrain_new
(
x
,
flowy
,
deltaFy
,
Ny
)
% Set the metadata for the coarsegrained sequence
y
.
flow
=
flowy
;
y
.
deltaF
=
deltaFy
;
if
(
isfield
(
x
,
'symmetry'
))
y
.
symmmetry
=
x
.
symmetry
;
else
y
.
symmetry
=
0
;
end
;
% Length of coarse series
Nx
=
length
(
x
.
data
);
% Lower edge of the first bin of the fine series
xLowerEdge
=
x
.
flow

0.5
*
x
.
deltaF
;
% Upper edge of the last bin of the fine series
xUpperEdge
=
x
.
flow
+
(
Nx

0.5
)
*
x
.
deltaF
;
% yi(k) is the lower edge of bin k for the coarsegrained series
yi
=
y
.
flow
+
y
.
deltaF
*
[

0.5
:
1
:
Ny

0.5
]
.'
;
% Lower edge of the first bin of the coarse series
yLowerEdge
=
yi
(
1
);
% Upper edge of the last bin of the coarse series
yUpperEdge
=
yi
(
end
);
% Error checking
if
(
Nx
<=
0
)
error
(
'Length of fine series is invalid'
);
end
;
if
(
Ny
<=
0
)
error
(
'Length of coarse series is invalid'
);
end
;
if
(
x
.
deltaF
<=
0
)
error
(
'Spacing of fine series is invalid'
);
end
;
if
(
y
.
deltaF
<=
0
)
error
(
'Spacing of coarse series is invalid'
);
end
;
if
(
y
.
deltaF
<
x
.
deltaF
)
error
(
'Frequency spacing of coarse series is smaller than fine series'
);
end
;
if
(
yLowerEdge
<
xLowerEdge
)
error
(
'Start of coarse series is less than start of fine series'
);
end
;
if
(
yUpperEdge
>
xUpperEdge
)
error
(
'End of coarse series is more than end of fine series'
);
end
;
% xlow is the index of the last bin whose lower edge is <= the
% lower edge of the coarsegrained sequence, that is
% x(xlow) <= y(1) < x(xlow+1)
xlow
=
1
+
floor
((
yLowerEdge

xLowerEdge
)/
x
.
deltaF
);
% xhi is the index of the last bin whose upper edge is >= the
% lower edge of the coarsegrained sequence, that is
% x(xhi1) < y(end) <= x(xhi)
xhi
=
ceil
((
yUpperEdge

xLowerEdge
)/
x
.
deltaF
);
% xi is the array of frequencies of the lower edge of each bin, that is,
% xi(k) is the lower edge of bin k, which is
% x.flow + (k1)*x.deltaF  0.5*x.deltaF = x.flow + (k1.5)*x.deltaF
% This is only calculated for the bins that the coarse series overlaps with,
% that is, bins [xlow:xhi]
xi
=
x
.
flow
+
[(
xlow

1.5
):
1
:(
xhi

0.5
)]
.'*
x
.
deltaF
;
% Integrate the original function so that the value fi(k) is
% the integral from the lower edge of the fine series xi(1)
% to xi(k). The 0 is inserted so that the fi(1) is 0, as it should be,
% so that we can interpolate the integral to the coarse series
fi
=
[
0
;
x
.
deltaF
*
cumsum
(
x
.
data
(
xlow
:
xhi
))
];
% Interpolate the integrated function using the lower edges of each bin in
% the coarse series as the ordinates
y
.
data
=
interp1
(
xi
,
fi
,
yi
,
'linear'
);
% Take the difference to get the integral over each bin of the coarse series,
% that is, y.data(k) becomes the integral from y(k) to y(k+1)
y
.
data
=
(
1
/
y
.
deltaF
)
*
diff
(
y
.
data
);
% For compatability with the original coarseGrain, we also return the
% frequency index of the first and last bins of the fine series that
% overlap with the coarse series (these are the array index  1)
index1
=
xlow

1
;
index2
=
xhi

1
;
% Fraction of the end bins of the fine series that overlap with the
% coarse series
frac1
=
(
xi
(
2
)

yLowerEdge
)/
x
.
deltaF
;
frac2
=
(
yUpperEdge

xi
(
end

1
))/
x
.
deltaF
;
return
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment