added distance based correlation function in matlab and java
This commit is contained in:
@@ -1,58 +1,47 @@
|
||||
%We are using a threshold-based version for bpm estimation
|
||||
%Only the z axis of the acc is used
|
||||
%using autocorrelation to estimate the current bmp within some fixed window
|
||||
|
||||
%NOTE: depending on the measurement device we have a highly different sample rate. the smartwatches are not capable of providing a constant sample rate. the xsens on the other hand is able to do this.
|
||||
|
||||
%load file provided by the sensor readout app
|
||||
|
||||
% SMARTWATCH LG WEAR ------> 100 hz - 1000hz
|
||||
%measurements = dlmread('../../measurements/lgWear/PR_recording_80bpm_4-4_177596720.csv', ';'); %
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_48bpm_4-4_176527527.csv', ';');
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_48bpm_4-4_176606785.csv', ';');
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_48bpm_4-4_176696356.csv', ';');
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_48bpm_4-4_176820066.csv', ';'); %
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_48bpm_4-4_176931941.csv', ';'); %double
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_72bpm_4-4_176381633.csv', ';');
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_72bpm_4-4_176453327.csv', ';'); %
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_100bpm_4-4_176073767.csv', ';'); %*
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_100bpm_4-4_176165357.csv', ';');
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_100bpm_4-4_176230146.csv', ';');
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_100bpm_4-4_176284687.csv', ';'); %
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_100bpm_4-4_177368860.csv', ';'); %(besonders)
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_180bpm_4-4_177011641.csv', ';'); %
|
||||
%measurements = dlmread('../../measurements/lgWear/recording_180bpm_4-4_177064915.csv', ';'); %
|
||||
|
||||
|
||||
% SMARTWATCH G WATCH WEAR R ----> 100hz - 250hz
|
||||
%measurements = dlmread('../measurements/wearR/PR_recording_80bpm_4-4_177596720.csv', ';'); %*
|
||||
%measurements = dlmread('../measurements/wearR/recording_48bpm_4-4_176527527.csv', ';');
|
||||
%measurements = dlmread('../measurements/wearR/recording_48bpm_4-4_176606785.csv', ';');
|
||||
%measurements = dlmread('../../measurements/wearR/recording_48bpm_4-4_176696356.csv', ';'); %*
|
||||
%measurements = dlmread('../measurements/wearR/recording_48bpm_4-4_176820066.csv', ';');
|
||||
%measurements = dlmread('../measurements/wearR/recording_48bpm_4-4_176931941.csv', ';'); %double
|
||||
%measurements = dlmread('../measurements/wearR/recording_72bpm_4-4_176381633.csv', ';');
|
||||
%measurements = dlmread('../measurements/wearR/recording_72bpm_4-4_176453327.csv', ';');
|
||||
%measurements = dlmread('../measurements/wearR/recording_100bpm_4-4_176073767.csv', ';'); *
|
||||
%measurements = dlmread('../measurements/wearR/recording_100bpm_4-4_176165357.csv', ';');
|
||||
%measurements = dlmread('../measurements/wearR/recording_100bpm_4-4_176230146.csv', ';'); %* 72?
|
||||
%measurements = dlmread('../measurements/wearR/recording_100bpm_4-4_176284687.csv', ';'); %*48?
|
||||
%measurements = dlmread('../measurements/wearR/recording_100bpm_4-4_177368860.csv', ';'); %(besonders)
|
||||
%measurements = dlmread('../measurements/wearR/recording_180bpm_4-4_177011641.csv', ';'); *
|
||||
%measurements = dlmread('../measurements/wearR/recording_180bpm_4-4_177064915.csv', ';'); *
|
||||
|
||||
files = dir(fullfile('../../measurements/mSensor/', '*.csv'));
|
||||
%files = dir(fullfile('../../measurements/lgWear/', '*.csv'));
|
||||
%load sensor files
|
||||
%files = dir(fullfile('../../measurements/2017.06/mSensor/', '*.csv'));
|
||||
%files = natsortfiles(dir(fullfile('../../measurements/2017.06/lgWear/', '*.csv')));
|
||||
%files = dir(fullfile('../../measurements/wearR/', '*.csv'));
|
||||
%files = dir(fullfile('../../measurements/peter_failed/', '*.csv'));
|
||||
%files = dir(fullfile('../../measurements/2018.06/manfred/LGWatchR/', '*.csv'));
|
||||
%files = dir(fullfile('../../measurements/2018.06/peter/Huawai/', '*.csv'));
|
||||
%files = dir(fullfile('../../measurements/2018.06/peter/mSensor/', '*.csv'));
|
||||
%files = dir(fullfile('../../measurements/2018.06/frank/mSensor/', '*.csv'));
|
||||
files = dir(fullfile('../../measurements/2018.06/leon/mSensor/', '*.csv'));
|
||||
|
||||
%files_sorted = natsortfiles({files.name});
|
||||
for file = files'
|
||||
|
||||
filename = [file.folder '/' file.name];
|
||||
measurements = dlmread(filename, ';');
|
||||
measurements = dlmread(filename, ';', 3, 0);
|
||||
|
||||
%load ground truth file
|
||||
fid = fopen(filename);
|
||||
fgetl(fid);
|
||||
Str = fgetl(fid);
|
||||
Key = 'Metronom: ';
|
||||
Index = strfind(Str, Key);
|
||||
gtDataRaw = sscanf(Str(Index(1) + length(Key):end), '%g', 1);
|
||||
gtData = [];
|
||||
gtFile = [];
|
||||
if(isempty(gtDataRaw))
|
||||
gtFile = extractAfter(Str, Key);
|
||||
gtFile = strcat('../../measurements/2018.06/gt_toni/', gtFile);
|
||||
f = fopen(gtFile);
|
||||
gtDataRaw = textscan(f, '%f %s', 'Delimiter', ' ');
|
||||
fclose(f);
|
||||
[~,~,~,hours,minutes,seconds] = datevec(gtDataRaw{2}, 'HH:MM:SS.FFF');
|
||||
gtData(:,1) = 1000*(60*minutes + seconds); %we do not use hours!
|
||||
gtData(:,2) = gtDataRaw{1};
|
||||
else
|
||||
gtData = gtDataRaw;
|
||||
end
|
||||
|
||||
%draw the raw acc data
|
||||
m_idx = [];
|
||||
m_idx = (measurements(:,2)==3); %Android App: 10, Normal Data: 2
|
||||
m_idx = (measurements(:,2)==3); %Android App: 10, Sensor: 3, Normal Data: 2
|
||||
m = measurements(m_idx, :);
|
||||
|
||||
%Interpolate to generate a constant sample rate to 250hz (4ms per sample)
|
||||
@@ -66,53 +55,74 @@ for file = files'
|
||||
%put all together again
|
||||
m = [t_interp', t_interp', m_interp];
|
||||
|
||||
figure(1);
|
||||
plot(m(:,1),m(:,3)) %x
|
||||
legend("x", "location", "eastoutside");
|
||||
|
||||
figure(2);
|
||||
plot(m(:,1),m(:,4)) %yt
|
||||
legend("y", "location", "eastoutside");
|
||||
|
||||
figure(3);
|
||||
plot(m(:,1),m(:,5)) %z
|
||||
legend("z", "location", "eastoutside");
|
||||
% figure(1);
|
||||
% plot(m(:,1),m(:,3)) %x
|
||||
% legend("x", "location", "eastoutside");
|
||||
%
|
||||
% figure(2);
|
||||
% plot(m(:,1),m(:,4)) %yt
|
||||
% legend("y", "location", "eastoutside");
|
||||
%
|
||||
% figure(3);
|
||||
% plot(m(:,1),m(:,5)) %z
|
||||
% legend("z", "location", "eastoutside");
|
||||
%
|
||||
% %magnitude
|
||||
magnitude = sqrt(sum(m(:,3:5).^2,2));
|
||||
% figure(5);
|
||||
% plot(m(:,1), magnitude);
|
||||
% legend("magnitude", "location", "eastoutside");
|
||||
|
||||
%magnitude
|
||||
magnitude = sqrt(sum(m(:,3:5).^2,2));
|
||||
figure(5);
|
||||
plot(m(:,1), magnitude);
|
||||
legend("magnitude", "location", "eastoutside");
|
||||
|
||||
waitforbuttonpress();
|
||||
%waitforbuttonpress();
|
||||
|
||||
%save timestamps
|
||||
timestamps = m(:,1);
|
||||
data = m(:,3); %only z
|
||||
|
||||
%TODO: Different window sizes for periods under 16.3 s
|
||||
window_size = 2048; %about 2 seconds using 2000hz, 16.3 s using 250hz
|
||||
window_size = 1024; %about 2 seconds using 2000hz, 16.3 s using 250hz
|
||||
overlap = 256;
|
||||
bpm_per_window_ms = [];
|
||||
bpm_per_window = [];
|
||||
for i = window_size+1:length(data)
|
||||
bpm_3D = [];
|
||||
ms_3D = [];
|
||||
|
||||
gtIdx = 1;
|
||||
gtError_3D = [];
|
||||
gtError_1D = [];
|
||||
|
||||
for i = window_size+1:1:length(data)
|
||||
|
||||
%wait until window is filled with new data
|
||||
if(mod(i,overlap) == 0)
|
||||
|
||||
|
||||
%set cur ground truth
|
||||
if(length(gtData) > 1)
|
||||
curTimestamp = timestamps(i);
|
||||
while(curTimestamp > gtData(gtIdx,1) && gtIdx < length(gtData))
|
||||
curGtBpm = gtData(gtIdx,2);
|
||||
gtIdx = gtIdx + 1;
|
||||
end
|
||||
else
|
||||
curGtBpm = gtData;
|
||||
end
|
||||
%measure periodicity of window and use axis with best periodicity
|
||||
[corr_x, lag_x] = xcov(m(i-window_size:i,3), (window_size/4), "coeff");
|
||||
[corr_y, lag_y] = xcov(m(i-window_size:i,4), (window_size/4), "coeff");
|
||||
[corr_z, lag_z] = xcov(m(i-window_size:i,5), (window_size/4), "coeff");
|
||||
[corr_mag, lag_mag] = xcov(magnitude(i-window_size:i), (window_size/4), "coeff");
|
||||
|
||||
|
||||
%autocorrelation of the autocorrelation?!
|
||||
%[corr_corr_x, lag_lag_x] = xcov(corr_x, length(corr_x), "coeff");
|
||||
%[corr_corr_y, lag_lag_y] = xcov(corr_y, length(corr_x), "coeff");
|
||||
%[corr_corr_z, lag_lag_z] = xcov(corr_z, length(corr_x), "coeff");
|
||||
[corr_x, lag_x] = xcov(m(i-window_size:i,3), (window_size/2), "coeff");
|
||||
[corr_y, lag_y] = xcov(m(i-window_size:i,4), (window_size/2), "coeff");
|
||||
[corr_z, lag_z] = xcov(m(i-window_size:i,5), (window_size/2), "coeff");
|
||||
|
||||
%magnitude
|
||||
[corr_mag, lag_mag] = xcov(magnitude(i-window_size:i), (window_size/2), "coeff");
|
||||
|
||||
%TODO: stichwort spatial autocorrelation
|
||||
%figure(77);
|
||||
%scatter3(timestamps(i-window_size:i), m(i-window_size:i,4), m(i-window_size:i,5));
|
||||
|
||||
%distanz zwischen den vektoren nehmen und in eine normale autocorrelation zu packen
|
||||
%aufpassen wegen der norm, dass die richtung quasi nicht verloren geht.
|
||||
%https://en.wikipedia.org/wiki/Lp_space
|
||||
[corr_3D, lag_3D] = distCorr(m(i-window_size:i, 3:5), (round(window_size * 0.8)));
|
||||
|
||||
corr_x_pos = corr_x;
|
||||
corr_y_pos = corr_y;
|
||||
corr_z_pos = corr_z;
|
||||
@@ -127,67 +137,81 @@ for file = files'
|
||||
[peak_y, idx_y_raw] = findpeaks(corr_y_pos, 'MinPeakHeight', 0.1,'MinPeakDistance', 50, 'MinPeakProminence', 0.1);
|
||||
[peak_z, idx_z_raw] = findpeaks(corr_z_pos, 'MinPeakHeight', 0.1,'MinPeakDistance', 50, 'MinPeakProminence', 0.1);
|
||||
[peak_mag, idx_mag_raw] = findpeaks(corr_mag_pos, 'MinPeakHeight', 0.1,'MinPeakDistance', 50, 'MinPeakProminence', 0.1);
|
||||
[peak_3D, idx_3D_raw] = findpeaks(corr_3D, 'MinPeakHeight', 0.1,'MinPeakDistance', 50, 'MinPeakProminence', 0.1);
|
||||
|
||||
|
||||
idx_x_raw = sort(idx_x_raw);
|
||||
idx_y_raw = sort(idx_y_raw);
|
||||
idx_z_raw = sort(idx_z_raw);
|
||||
idx_mag_raw = sort(idx_mag_raw);
|
||||
idx_3D_raw = sort(idx_3D_raw);
|
||||
|
||||
idx_x = findFalseDetectedPeaks(idx_x_raw, lag_x, corr_x);
|
||||
idx_y = findFalseDetectedPeaks(idx_y_raw, lag_y, corr_y);
|
||||
idx_z = findFalseDetectedPeaks(idx_z_raw, lag_z, corr_z);
|
||||
idx_mag = findFalseDetectedPeaks(idx_mag_raw, lag_mag, corr_mag);
|
||||
idx_3D = findFalseDetectedPeaks(idx_3D_raw, lag_3D', corr_3D);
|
||||
|
||||
Dwindow = m(i-window_size:i,3);
|
||||
Dwindow_mean_ts_diff = mean(diff(lag_3D(idx_3D) * sample_rate_ms)); %2.5 ms is the time between two samples at 400hz
|
||||
Dwindow_mean_bpm = (60000 / (Dwindow_mean_ts_diff));
|
||||
|
||||
figure(10);
|
||||
plot(lag_3D, corr_3D, lag_3D(idx_3D), corr_3D(idx_3D), 'r*', lag_3D(idx_3D_raw), corr_3D(idx_3D_raw), 'g*')
|
||||
hold ("on")
|
||||
m_label_ms = strcat(" mean ms: ", num2str(Dwindow_mean_ts_diff));
|
||||
m_label_bpm = strcat(" mean bpm: ", num2str(Dwindow_mean_bpm));
|
||||
title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
hold ("off");
|
||||
|
||||
Xwindow = m(i-window_size:i,3);
|
||||
Xwindow_mean_ts_diff = mean(diff(lag_x(idx_x) * sample_rate_ms)); %2.5 ms is the time between two samples at 400hz
|
||||
Xwindow_mean_bpm = (60000 / (Xwindow_mean_ts_diff));
|
||||
|
||||
figure(11);
|
||||
plot(lag_x, corr_x, lag_x(idx_x), corr_x(idx_x), 'r*', lag_x(idx_x_raw), corr_x(idx_x_raw), 'g*') %z
|
||||
hold ("on")
|
||||
m_label_ms = strcat(" mean ms: ", num2str(Xwindow_mean_ts_diff));
|
||||
m_label_bpm = strcat(" mean bpm: ", num2str(Xwindow_mean_bpm));
|
||||
title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
hold ("off");
|
||||
|
||||
% figure(11);
|
||||
% plot(lag_x, corr_x, lag_x(idx_x), corr_x(idx_x), 'r*', lag_x(idx_x_raw), corr_x(idx_x_raw), 'g*') %z
|
||||
% hold ("on")
|
||||
% m_label_ms = strcat(" mean ms: ", num2str(Xwindow_mean_ts_diff));
|
||||
% m_label_bpm = strcat(" mean bpm: ", num2str(Xwindow_mean_bpm));
|
||||
% title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
% hold ("off");
|
||||
|
||||
Ywindow = m(i-window_size:i,4);
|
||||
Ywindow_mean_ts_diff = mean(diff(lag_y(idx_y) * sample_rate_ms));
|
||||
Ywindow_mean_bpm = (60000 / (Ywindow_mean_ts_diff));
|
||||
|
||||
figure(12);
|
||||
plot(lag_y, corr_y, lag_y(idx_y), corr_y(idx_y), 'r*', lag_y(idx_y_raw), corr_y(idx_y_raw), 'g*') %z
|
||||
hold ("on")
|
||||
m_label_ms = strcat(" mean ms: ", num2str(Ywindow_mean_ts_diff));
|
||||
m_label_bpm = strcat(" mean bpm: ", num2str(Ywindow_mean_bpm));
|
||||
title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
hold ("off");
|
||||
% figure(12);
|
||||
% plot(lag_y, corr_y, lag_y(idx_y), corr_y(idx_y), 'r*', lag_y(idx_y_raw), corr_y(idx_y_raw), 'g*') %z
|
||||
% hold ("on")
|
||||
% m_label_ms = strcat(" mean ms: ", num2str(Ywindow_mean_ts_diff));
|
||||
% m_label_bpm = strcat(" mean bpm: ", num2str(Ywindow_mean_bpm));
|
||||
% title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
% hold ("off");
|
||||
|
||||
Zwindow = m(i-window_size:i,5);
|
||||
Zwindow_mean_ts_diff = mean(diff(lag_z(idx_z)* sample_rate_ms));
|
||||
Zwindow_mean_bpm = (60000 / (Zwindow_mean_ts_diff));
|
||||
|
||||
figure(13);
|
||||
plot(lag_z, corr_z, lag_z(idx_z), corr_z(idx_z), 'r*', lag_z(idx_z_raw), corr_z(idx_z_raw), 'g*') %z
|
||||
hold ("on")
|
||||
m_label_ms = strcat(" mean ms: ", num2str(Zwindow_mean_ts_diff));
|
||||
m_label_bpm = strcat(" mean bpm: ", num2str(Zwindow_mean_bpm));
|
||||
title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
hold ("off");
|
||||
% figure(13);
|
||||
% plot(lag_z, corr_z, lag_z(idx_z), corr_z(idx_z), 'r*', lag_z(idx_z_raw), corr_z(idx_z_raw), 'g*') %z
|
||||
% hold ("on")
|
||||
% m_label_ms = strcat(" mean ms: ", num2str(Zwindow_mean_ts_diff));
|
||||
% m_label_bpm = strcat(" mean bpm: ", num2str(Zwindow_mean_bpm));
|
||||
% title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
% hold ("off");
|
||||
|
||||
%magnitude
|
||||
Mwindow = magnitude(i-window_size:i);
|
||||
Mwindow_mean_ts_diff = mean(diff(lag_mag(idx_mag)* sample_rate_ms));
|
||||
Mwindow_mean_bpm = (60000 / (Mwindow_mean_ts_diff));
|
||||
|
||||
figure(14);
|
||||
plot(lag_mag, corr_mag, lag_mag(idx_mag), corr_mag(idx_mag), 'r*', lag_mag(idx_mag_raw), corr_mag(idx_mag_raw), 'g*') %z
|
||||
hold ("on")
|
||||
m_label_ms = strcat(" mean ms: ", num2str(Mwindow_mean_ts_diff));
|
||||
m_label_bpm = strcat(" mean bpm: ", num2str(Mwindow_mean_bpm));
|
||||
title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
hold ("off");
|
||||
|
||||
|
||||
% figure(14);
|
||||
% plot(lag_mag, corr_mag, lag_mag(idx_mag), corr_mag(idx_mag), 'r*', lag_mag(idx_mag_raw), corr_mag(idx_mag_raw), 'g*') %z
|
||||
% hold ("on")
|
||||
% m_label_ms = strcat(" mean ms: ", num2str(Mwindow_mean_ts_diff));
|
||||
% m_label_bpm = strcat(" mean bpm: ", num2str(Mwindow_mean_bpm));
|
||||
% title(strcat(" ", m_label_ms, " ", m_label_bpm));
|
||||
% hold ("off");
|
||||
|
||||
%breakpoints dummy for testing
|
||||
if(length(idx_x) > length(idx_x_raw))
|
||||
@@ -277,11 +301,22 @@ for file = files'
|
||||
|
||||
if(isnan(window_mean_ts_diff) || isnan(window_mean_bpm))
|
||||
%do nothing
|
||||
else
|
||||
else
|
||||
gtError_1D = [gtError_1D, abs(window_mean_bpm - curGtBpm)];
|
||||
bpm_per_window_ms = [bpm_per_window_ms, window_mean_ts_diff];
|
||||
bpm_per_window = [bpm_per_window, window_mean_bpm];
|
||||
end
|
||||
|
||||
|
||||
%3D mean
|
||||
if(isnan(Dwindow_mean_bpm))
|
||||
%nothing
|
||||
else
|
||||
gtError_3D = [gtError_3D, abs(Dwindow_mean_bpm - curGtBpm)];
|
||||
bpm_3D = [bpm_3D, Dwindow_mean_bpm];
|
||||
ms_3D = [ms_3D, Dwindow_mean_ts_diff];
|
||||
end
|
||||
|
||||
%TODO: if correlation value is lower then a treshhold, we are not conducting TODO: change to a real classification instead of a treshhold.
|
||||
|
||||
end
|
||||
@@ -290,22 +325,70 @@ for file = files'
|
||||
%TODO: smooth the results using a moving avg or 1d kalman filter.(transition for kalman could be adding the last measured value)
|
||||
|
||||
%remove the first 40% of the results, due to starting delays while recording.
|
||||
number_to_remove = round(abs(0.1 * length(bpm_per_window_ms)));
|
||||
num_all = length(bpm_per_window_ms);
|
||||
bpm_per_window_ms = bpm_per_window_ms(number_to_remove:num_all);
|
||||
bpm_per_window = bpm_per_window(number_to_remove:num_all);
|
||||
%number_to_remove = round(abs(0.1 * length(bpm_per_window_ms)));
|
||||
%num_all = length(bpm_per_window_ms);
|
||||
%bpm_per_window_ms = bpm_per_window_ms(number_to_remove:num_all);
|
||||
%bpm_per_window = bpm_per_window(number_to_remove:num_all);
|
||||
|
||||
mean_final_ms = mean(bpm_per_window_ms);
|
||||
std_final_ms = std(bpm_per_window_ms);
|
||||
|
||||
mean_final_bpm = mean(bpm_per_window);
|
||||
std_final_bpm = std(bpm_per_window);
|
||||
|
||||
mean_final_error_1D = mean(gtError_1D);
|
||||
std_final_error_1D = std(gtError_1D);
|
||||
|
||||
mean_final_ms_3D = mean(ms_3D);
|
||||
std_final_ms_3D = std(ms_3D);
|
||||
|
||||
mean_final_bpm_3D = mean(bpm_3D);
|
||||
std_final_bpm_3D = std(bpm_3D);
|
||||
|
||||
mean_final_error_3D = mean(gtError_3D);
|
||||
std_final_error_3D = std(gtError_3D);
|
||||
|
||||
fprintf('%s: mean = %f bpm (%f ms) stddev = %f bpm (%f ms)\n', strrep(regexprep(filename,'^.*recording_',''),'.txt',''), mean_final_bpm, mean_final_ms, std_final_bpm, std_final_ms);
|
||||
|
||||
fprintf('%s: mean = %f bpm (%f bpm) stddev = %f bpm (%f bpm) --- 1D\n', strrep(regexprep(filename,'^.*recording_',''),'.txt',''), mean_final_error_1D, mean_final_bpm, std_final_error_1D, std_final_bpm);
|
||||
fprintf('%s: mean = %f bpm (%f bpm) stddev = %f bpm (%f bpm) --- 3D\n', strrep(regexprep(filename,'^.*recording_',''),'.txt',''), mean_final_error_3D, mean_final_bpm_3D, std_final_error_3D, std_final_bpm_3D);
|
||||
|
||||
end
|
||||
|
||||
|
||||
% %1D fft - nicht so der brüller
|
||||
% z_fft = fft(m(i-window_size:i,5));
|
||||
% L = length(z_fft);
|
||||
% Fs = 250;
|
||||
% P2 = abs(z_fft/L);
|
||||
% P1 = P2(1:L/2+1);
|
||||
% P1(2:end-1) = 2*P1(2:end-1);
|
||||
% f = Fs*(0:(L/2))/L; %nyquist frequence
|
||||
%
|
||||
% figure(66);
|
||||
% plot(f, P1);
|
||||
%
|
||||
% %3D fft
|
||||
% m_3D = m(i-window_size:i, 3);
|
||||
% m_3D(:,:,2) = m(i-window_size:i, 4);
|
||||
% m_3D(:,:,3) = m(i-window_size:i, 5);
|
||||
%
|
||||
% fft_3D = fftn(m_3D);
|
||||
%
|
||||
% %2D fft
|
||||
% fft_xy = fft2(m(i-window_size:i, 3:4));
|
||||
% fft_yz = fft2(m(i-window_size:i, 3:4));
|
||||
%
|
||||
% fft_test = fft(m(i-window_size:i, 3:5),[],2);
|
||||
%
|
||||
% figure(60);
|
||||
% imagesc(abs(fftshift(fft_test)));
|
||||
%
|
||||
% figure(61);
|
||||
% imagesc(abs(fftshift(fft_xy)));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
41
matlab/distCorr.m
Normal file
41
matlab/distCorr.m
Normal file
@@ -0,0 +1,41 @@
|
||||
% Autocorrelation for Points based on the distance between those points
|
||||
% data is the sensor data. one point per row.
|
||||
% lag_size is the number of required lags
|
||||
function [corr, lag] = distCorr(data, lag_size)
|
||||
|
||||
n = length(data);
|
||||
|
||||
%if lag size is bigger as data, then use data length - 1
|
||||
% -1 because the max. lag is -1 of the data length..
|
||||
if(lag_size >= n)
|
||||
lag_size = n - 1; %
|
||||
end
|
||||
|
||||
%init
|
||||
corr = zeros(lag_size + 1, 1); % +1, because the first index is lag 0.
|
||||
lag = (-lag_size:1:lag_size)';
|
||||
|
||||
%mean shift and l2 normalization
|
||||
%data = data - mean(data);
|
||||
%data = data / norm(data);
|
||||
|
||||
for j = 1:lag_size + 1 % +1, because the first index is lag 0.
|
||||
dist = zeros(n - abs(j), 1);
|
||||
idx = 1;
|
||||
|
||||
for i = j:n
|
||||
%x_i * x_i-(j-1)
|
||||
dist(idx) = norm(data(i, :) - data(i-(j-1), :));
|
||||
idx = idx + 1;
|
||||
end
|
||||
|
||||
corr(j) = geomean(dist);
|
||||
end
|
||||
|
||||
%mirror corr(2:512) and put it infront
|
||||
corr = [flipud(corr(2:end)); corr];
|
||||
|
||||
%to [0, 1]
|
||||
corr = ((corr .* -1) / max(corr)) + 1;
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user