|
@@ -5,9 +5,14 @@
|
|
|
%% sphear_signal_arrival_times: measure rotation axis wobble in the measurements
|
|
%% sphear_signal_arrival_times: measure rotation axis wobble in the measurements
|
|
|
%%
|
|
%%
|
|
|
%% usage:
|
|
%% usage:
|
|
|
-%% [] = sphear_signal_arrival_times(SIG);
|
|
|
|
|
|
|
+%% [DELAYS] = sphear_signal_arrival_times(SIG);
|
|
|
%%
|
|
%%
|
|
|
%% SIG: array of signals (measurements, capsules, samples)
|
|
%% SIG: array of signals (measurements, capsules, samples)
|
|
|
|
|
+%% DELAYS: array of delays
|
|
|
|
|
+%%
|
|
|
|
|
+%% use this function for finding peaks:
|
|
|
|
|
+%% https://ccrma.stanford.edu/~jos/sasp/Matlab_listing_findpeaks_m.html
|
|
|
|
|
+%%
|
|
|
%%
|
|
%%
|
|
|
%% Copyright 2016-2018, Fernando Lopez-Lezcano, All Rights Reserved
|
|
%% Copyright 2016-2018, Fernando Lopez-Lezcano, All Rights Reserved
|
|
|
%% nando@ccrma.stanford.edu
|
|
%% nando@ccrma.stanford.edu
|
|
@@ -25,31 +30,32 @@
|
|
|
%% You should have received a copy of the GNU General Public License
|
|
%% You should have received a copy of the GNU General Public License
|
|
|
%% along with this program. If not, see <htp://www.gnu.org/licenses/>.
|
|
%% along with this program. If not, see <htp://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-function [MEAN DELAY DELTA] = sphear_signal_arrival_times(SIG)
|
|
|
|
|
- MEAN = 0;
|
|
|
|
|
|
|
+function [AVG_DELAY DELTA ALL] = sphear_signal_arrival_times(SIG)
|
|
|
|
|
+ %% make all delays relative to first capsule of first measurement
|
|
|
|
|
+ [peakamps, peaklocs] = sphear_findpeaks(abs(reshape(SIG(1, 1, :), 1, [])), 10);
|
|
|
|
|
+ ref = peaklocs(1);
|
|
|
|
|
+ %% now find all average delays
|
|
|
for m = 1:size(SIG, 1);
|
|
for m = 1:size(SIG, 1);
|
|
|
avg_delay = 0;
|
|
avg_delay = 0;
|
|
|
for c = 1:size(SIG, 2);
|
|
for c = 1:size(SIG, 2);
|
|
|
- [peaks, locs] = findpeaks(abs(reshape(SIG(m, c, :), 1, [])), "MinPeakHeight", 0.0001, "MinPeakDistance", 16);
|
|
|
|
|
- [value, index] = max(peaks);
|
|
|
|
|
- loc = locs(index);
|
|
|
|
|
- %% printf("m=%d, c=%d: %d <%d - %f>\n", m, c, index, loc, value);
|
|
|
|
|
- avg_delay = avg_delay + loc;
|
|
|
|
|
|
|
+ %% find at most 10 peaks so that we avoid warnings
|
|
|
|
|
+ [peakamps, peaklocs] = sphear_findpeaks(abs(reshape(SIG(m, c, :), 1, [])), 10);
|
|
|
|
|
+ delay = peaklocs(1) - ref;
|
|
|
|
|
+ %% printf("m=%d, c=%d: idx=%d <delay=%d value=%f>\n", m, c, 1, delay, peakamps(1));
|
|
|
|
|
+ ALL(m,c,:) = delay;
|
|
|
|
|
+ avg_delay = avg_delay + delay;
|
|
|
end
|
|
end
|
|
|
if (m == 1)
|
|
if (m == 1)
|
|
|
first = avg_delay/size(SIG, 2);
|
|
first = avg_delay/size(SIG, 2);
|
|
|
end
|
|
end
|
|
|
- DELAY(m) = avg_delay/size(SIG, 2);
|
|
|
|
|
- DELTA(m) = DELAY(m) - first;
|
|
|
|
|
- printf("m=%d: time=%f, delta=%f\n", m, DELAY(m), DELTA(m));
|
|
|
|
|
- MEAN = MEAN + DELAY(m);
|
|
|
|
|
|
|
+ AVG_DELAY(m) = avg_delay/size(SIG, 2);
|
|
|
|
|
+ DELTA(m) = AVG_DELAY(m) - first;
|
|
|
|
|
+ printf("m=%d: time=%f, delta=%f\n", m, AVG_DELAY(m), DELTA(m));
|
|
|
end
|
|
end
|
|
|
- MEAN = MEAN / size(SIG, 1);
|
|
|
|
|
%% find proper deltas with respect to minimum delay
|
|
%% find proper deltas with respect to minimum delay
|
|
|
- min_delay = min(DELAY);
|
|
|
|
|
- max_delay = max(DELAY);
|
|
|
|
|
- printf("average delay = %f, max delay = %f\n", MEAN, max_delay);
|
|
|
|
|
- DELTA = (DELAY - min_delay)';
|
|
|
|
|
- DELAY = DELAY';
|
|
|
|
|
|
|
+ min_delay = min(AVG_DELAY);
|
|
|
|
|
+ max_delay = max(AVG_DELAY);
|
|
|
|
|
+ DELTA = (AVG_DELAY - min_delay)';
|
|
|
|
|
+ AVG_DELAY = (max_delay - AVG_DELAY)';
|
|
|
end
|
|
end
|
|
|
|
|
|