From b156b47e6bfdc72e49ed418741aaab2abc258015 Mon Sep 17 00:00:00 2001
From: "AD\\WoudaFJ" <f.j.wouda@utwente.nl>
Date: Tue, 29 Aug 2023 16:11:10 +0200
Subject: [PATCH] Made the filter cut off frequency a setting, double checked
 if results align between this version and the original.

---
 +math/calculateSteps.m | 8 ++++----
 +math/initOrien.m      | 5 +----
 Main.m                 | 6 +++---
 getCalibration.m       | 5 ++++-
 settingsFile.m         | 5 ++++-
 5 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/+math/calculateSteps.m b/+math/calculateSteps.m
index 12c5873..e1aced1 100644
--- a/+math/calculateSteps.m
+++ b/+math/calculateSteps.m
@@ -6,7 +6,7 @@
 % output:
 % dataStruct - containing calculated FPA.
 
-function dataStruct = calculateSteps(dataStruct, trialName)
+function dataStruct = calculateSteps(dataStruct, trialName, fCutOff)
 
 % Get the trial data.
 data = dataStruct.(trialName);
@@ -17,12 +17,12 @@ calibrationFields = fieldnames(dataStruct.calibration);
 % By default take the first calibration trial.
 calibration = dataStruct.calibration.(calibrationFields{1});
 
-% cut-off frequency of the filter.
-fCutoff = 2;
+% Store the cut-off frequency.
+data.fCutOff = fCutOff;
 
 % 2nd order low-pass butterworth filter to get the relevant motion data.
 % Implement as filtfilt due to no realtime constraints.
-[Bf, Af] = butter(2, (2 * fCutoff / data.fs));
+[Bf, Af] = butter(2, (2 * data.fCutOff / data.fs));
 data.filtAcc = filtfilt(Bf, Af, data.acc); 
 data.filtGyr = filtfilt(Bf, Af, data.gyr);
 
diff --git a/+math/initOrien.m b/+math/initOrien.m
index f01dc45..0fd1cff 100644
--- a/+math/initOrien.m
+++ b/+math/initOrien.m
@@ -15,12 +15,9 @@
 
 function data = initOrien(data)
 
-% cut-off frequency of the filter.
-data.fCutoff = 2;
-
 % 2nd order low-pass butterworth filter to get the relevant motion data.
 % Implement as filtfilt due to no realtime constraints.
-[Bf, Af] = butter(2, (2 * data.fCutoff / data.fs));
+[Bf, Af] = butter(2, (2 * data.fCutOff / data.fs));
 data.filtAcc = filtfilt(Bf, Af, data.acc); 
 data.filtGyr = filtfilt(Bf, Af, data.gyr);
 
diff --git a/Main.m b/Main.m
index 3e201a0..9bd8ac8 100644
--- a/Main.m
+++ b/Main.m
@@ -4,7 +4,7 @@
 clear all; close all; clc
 
 % Run the settings file.
-settingsFile
+settingsFile;
 
 % Allocate space for storing the data.
 dataStruct = struct();
@@ -19,7 +19,7 @@ for i = 3:length(subjectFolders)
     dataStruct.(subjectFolders(i).name) = struct();
     
     dataStruct.(subjectFolders(i).name).calibration = getCalibration( ...
-        join([subjectFolders(i).folder '\' subjectFolders(i).name '\' calibrationFolder],''));
+        join([subjectFolders(i).folder '\' subjectFolders(i).name '\' calibrationFolder],''), fCutOff);
 
     for j = 1:length(trialFiles)
         currentPath = [trialFiles(j).folder '\' trialFiles(j).name];
@@ -31,7 +31,7 @@ for i = 3:length(subjectFolders)
 
         % calculate all values for each step.
         dataStruct.(subjectFolders(i).name) = ...
-            math.calculateSteps(dataStruct.(subjectFolders(i).name), trialName);
+            math.calculateSteps(dataStruct.(subjectFolders(i).name), trialName, fCutOff);
 
     end
 end
diff --git a/getCalibration.m b/getCalibration.m
index 48f63f1..cca60c2 100644
--- a/getCalibration.m
+++ b/getCalibration.m
@@ -1,6 +1,6 @@
 %% This function reads in data from Movella DOT csv files of the calibration folder.
 % filePath - full path to where calibration files are stored.
-function dataStruct = getCalibration(filePath)
+function dataStruct = getCalibration(filePath, fCutOff)
     
     % Only select the files that are relevant.
     calibDir = dir(filePath);
@@ -26,6 +26,9 @@ function dataStruct = getCalibration(filePath)
             dataStruct.(trialName).calibration = struct();    
         end
 
+        % cut-off frequency of the filter.
+        dataStruct.(trialName).fCutOff = fCutOff;
+
         % Determine the calibration orientation.
         dataStruct.(trialName) = math.initOrien(dataStruct.(trialName));       
 
diff --git a/settingsFile.m b/settingsFile.m
index 40b32a1..029e39e 100644
--- a/settingsFile.m
+++ b/settingsFile.m
@@ -15,4 +15,7 @@ dirFlags = [allFiles.isdir];
 subjectFolders = allFiles(dirFlags);
 
 % gravity constant is defined.
-gravity = 9.81;
\ No newline at end of file
+gravity = 9.81;
+
+% filter cut off frequency.
+fCutOff = 10;
\ No newline at end of file
-- 
GitLab