diff --git a/scripts/FX.fig b/scripts/FX.fig new file mode 100644 index 0000000..5b29584 Binary files /dev/null and b/scripts/FX.fig differ diff --git a/scripts/FY.fig b/scripts/FY.fig new file mode 100644 index 0000000..ac4ead2 Binary files /dev/null and b/scripts/FY.fig differ diff --git a/scripts/MX.fig b/scripts/MX.fig new file mode 100644 index 0000000..2f12d66 Binary files /dev/null and b/scripts/MX.fig differ diff --git a/scripts/MZ.fig b/scripts/MZ.fig new file mode 100644 index 0000000..197f337 Binary files /dev/null and b/scripts/MZ.fig differ diff --git a/scripts/similarities.m b/scripts/similarities.m index a164687..2862c8a 100644 --- a/scripts/similarities.m +++ b/scripts/similarities.m @@ -1,7 +1,8 @@ %% please open Magic Formular APP first clear +clc n = 20; -mkdir('similarityData'); + %% directoryPath = "..\sorted_data"; subdirectories = getSubdirectories(directoryPath); @@ -15,32 +16,207 @@ subdirectories_list = contents([contents.isdir] & ~ismember({contents.name}, {'. % Extract and display the names of the subdirectories subdirectoryNames = {subdirectories_list.name}; %% -figure() +% figure() +% for i=1:length(subdirectories) +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% FY = smoothdata(FY, "gaussian",100); +% if i < length(subdirectories)/3 +% plot(SA, FY, 'LineWidth', 1) +% elseif i <= length(subdirectories)/3*2 +% plot(SA, FY, '--','LineWidth', 1) +% else +% plot(SA, FY, '-.','LineWidth', 1) +% end +% SAA{i} = SA; +% FYY{i} = FY; +% hold on +% end +% legend(subdirectoryNames{:}) +% title("Similarities, n=",n) +% xlabel("Slip Angle") +% ylabel("FY") -for i=1:length(subdirectories) - fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); - parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); - measurements = parser.run(fileMeasurement); - measurement = measurements(n); - [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); - FY = smoothdata(FY, "gaussian",100); - if i < length(subdirectories)/3 - plot(SA, FY, 'LineWidth', 1) - elseif i <= length(subdirectories)/3*2 - plot(SA, FY, '--','LineWidth', 1) - else - plot(SA, FY, '-.','LineWidth', 1) +% SA-MX +% figure() +% for i=1:length(subdirectories) +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% MX = smoothdata(MX, "gaussian",100); +% if i < length(subdirectories)/3 +% plot(SA, MX, 'LineWidth', 1) +% elseif i <= length(subdirectories)/3*2 +% plot(SA, MX,'--','LineWidth', 1) +% else +% plot(SA, MX, '-.','LineWidth', 1) +% end +% hold on +% end +% legend(subdirectoryNames{:}) +% title("Similarities, n=",n) +% xlabel("Slip Angle") +% ylabel("MX") + + +% SA - MZ +% figure() +% for i=1:length(subdirectories) +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% MZ = smoothdata(MZ, "gaussian",100); +% if i < length(subdirectories)/3 +% plot(SA, MZ, 'LineWidth', 1) +% elseif i <= length(subdirectories)/3*2 +% plot(SA, MZ,'--','LineWidth', 1) +% else +% plot(SA, MZ, '-.','LineWidth', 1) +% end +% SAA{i} = SA; +% MZZ{i} = MZ; +% hold on +% end +% legend(subdirectoryNames{:}) +% title("Similarities, n=",n) +% xlabel("Slip Angle") +% ylabel("MZ") + + +% for n=1:1 +% figure() +% j = 1; +% for i=8:8%length(subdirectories) +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% fileMeasurement1 = fullfile("..\sorted_data", subdirectories{i}, "\drivebrake.mat"); +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% try +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% measurements1 = parser.run(fileMeasurement1); +% measurement1 = measurements1(n); +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% [SX1,SA1,FZ1,IP1,IA1,VX1,FX1,FY1,MZ1,MY1,MX1,W1,T1] = unpack(measurement1); +% +% MX = smoothdata(MX, "gaussian"); +% if i < length(subdirectories)/3 +% plot(SA, FY, 'LineWidth', 1) +% elseif i <= length(subdirectories)/3*2 +% plot(SA, FY, '--','LineWidth', 1) +% else +% plot(SA, FY, '-.','LineWidth', 1) +% end +% lengends{j} = subdirectoryNames{i}; +% j = j+1; +% hold on +% catch +% disp(fileMeasurement) +% end +% end +% legend(lengends{:}) +% title("Similarities, n=",n) +% xlabel("SA") +% ylabel("MZ") +% end + +%% prove FY are the same +for n=1:10:60 + figure() + for i=9:9%length(subdirectories) + fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); + fileMeasurement1 = fullfile("..\sorted_data", subdirectories{i}, "\drivebrake.mat"); + parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); + try + measurements = parser.run(fileMeasurement); + measurement = measurements(n); + + measurements1 = parser.run(fileMeasurement1); + measurement1 = measurements1(n); + + [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); + [SX1,SA1,FZ1,IP1,IA1,VX1,FX1,FY1,MZ1,MY1,MX1,W1,T1] = unpack(measurement1); + + MX = smoothdata(MX, "gaussian"); + plot(SA, FY, 'LineWidth', 1) + hold on + plot(SA1, FY1, 'LineWidth', 1) + legend("Cornering", "drivebrake") + catch + disp(fileMeasurement) + end end - SAA{i} = SA; - FYY{i} = FY; - hold on + title("Similarities, n=",n) + xlabel("SA") + ylabel("FY") end -legend(subdirectoryNames{:}) -title("Similarities, n=",n) -xlabel("Slip Angle") -ylabel("FY") -%% without plot +%% without plot +% mkdir('similarityDataFY'); +% for n=1:60 +% for i=1:length(subdirectories) +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% FY = smoothdata(FY, "gaussian",100); +% SAA{i} = SA; +% FYY{i} = FY; +% end +% file_name = ['similarityDataFY\nEqu' num2str(n) '.mat']; +% save(file_name, 'SAA', 'FYY'); +% end + + +% mkdir('similarityDataFX'); +% for n=1:60 +% for i=1:length(subdirectories) +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% FX = smoothdata(FX, "gaussian",100); +% SAA{i} = SA; +% FXX{i} = FX; +% end +% file_name = ['similarityDataFX\nEqu' num2str(n) '.mat']; +% save(file_name, 'SAA', 'FXX'); +% end +% +% mkdir("similarityDataMZ") +% for n=1:60 +% for i=1:length(subdirectories) +% fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); +% parser = tydex.parsers.FSAETTC_SI_ISO_Mat(); +% measurements = parser.run(fileMeasurement); +% measurement = measurements(n); +% +% [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); +% MZ = smoothdata(MZ, "gaussian",100); +% SAA{i} = SA; +% MZZ{i} = MZ; +% end +% file_name = ['similarityDataMZ\nEqu' num2str(n) '.mat']; +% save(file_name, 'SAA', 'MZZ'); +% end + +mkdir("similarityDataMX") for n=1:60 for i=1:length(subdirectories) fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); @@ -49,10 +225,10 @@ for n=1:60 measurement = measurements(n); [SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); - FY = smoothdata(FY, "gaussian",100); + MX = smoothdata(MX, "gaussian",100); SAA{i} = SA; - FYY{i} = FY; + MXX{i} = MX; end - file_name = ['similarityData\nEqu' num2str(n) '.mat']; - save(file_name, 'SAA', 'FYY'); + file_name = ['similarityDataMX\nEqu' num2str(n) '.mat']; + save(file_name, 'SAA', 'MXX'); end diff --git a/scripts/similarities2.m b/scripts/similarities2.m index baabba9..4df4b9b 100644 --- a/scripts/similarities2.m +++ b/scripts/similarities2.m @@ -1,6 +1,7 @@ clear; clc; -% Use the dir function to get information about files and directories + +% % FY directoryPath = ".\similarityData"; % Get a list of all files in the directory @@ -29,7 +30,7 @@ for tire=1:length(SAA) end residuals_tire{tire} = residuals_one_tire; end -%% mean +% mean for tire=1:length(SAA) num = 0; % each tire under 60 measurement conditions @@ -42,11 +43,11 @@ for tire=1:length(SAA) end residuals_mean{tire} = sum(residuals_tire{tire})/num; end -%% median +% median for tire=1:length(SAA) residuals_median{tire} = median(residuals_tire{tire}); end -%% mode +% mode for tire=1:length(SAA) residuals_mode{tire} = mode(residuals_tire{tire}); end @@ -64,6 +65,7 @@ ylabel("in 1") xticks(idx) grid on + subplot(312) y = cell2mat(residuals_median); plot(idx, y, "-o") @@ -81,4 +83,264 @@ title("Mode of the Absolute Residuials") xlabel("Order of the tires(8 is our traget tire)") ylabel("in 1") xticks(idx) -grid on \ No newline at end of file +grid on +sgtitle("FY") + +%% FX +directoryPath = ".\similarityDataFX"; +% Get a list of all files in the directory +files = dir(fullfile(directoryPath, '*.mat')); % You can adjust the file extension as needed + +% Extract file names +fileNames = {files.name}; + +for n=1:length(fileNames) + % fit the curve of 43075 , 8 inch + filePath = fullfile(directoryPath, fileNames(n)); + load(filePath); + [fitresult, gof] = createFit(SAA{8},FXX{8}); + % Evaluate the fitted curves + for tire=1:length(SAA) + y_fit = fitresult(SAA{tire}); + % Calculate residuals + residuals{tire}{n} = abs(FXX{tire} - fitresult(SAA{tire})); + end +end + +for tire=1:length(SAA) + residuals_one_tire = []; + for n=1:length(fileNames) + residuals_one_tire = [residuals_one_tire; residuals{tire}{n}]; + end + residuals_tire{tire} = residuals_one_tire; +end +% mean +for tire=1:length(SAA) + num = 0; + % each tire under 60 measurement conditions + for i=1:length(residuals_tire{tire}) + if not(isnan(residuals_tire{tire}(i))) + num = num + 1; + else + residuals_tire{tire}(i) = 0; + end + end + residuals_mean{tire} = sum(residuals_tire{tire})/num; +end +% median +for tire=1:length(SAA) + residuals_median{tire} = median(residuals_tire{tire}); +end +% mode +for tire=1:length(SAA) + residuals_mode{tire} = mode(residuals_tire{tire}); +end + +% plots +idx = linspace(1,length(SAA),length(SAA)); + +figure() +subplot(311) +y = cell2mat(residuals_mean); +plot(idx, y, "-*") +title("Average Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + + +subplot(312) +y = cell2mat(residuals_median); +plot(idx, y, "-o") +title("Median of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + + +subplot(313) +y = cell2mat(residuals_mode); +plot(idx, y, "-o") +title("Mode of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on +sgtitle("FX") + + +%% Mx +directoryPath = ".\similarityDataMX"; +% Get a list of all files in the directory +files = dir(fullfile(directoryPath, '*.mat')); % You can adjust the file extension as needed + +% Extract file names +fileNames = {files.name}; + +for n=1:length(fileNames) + % fit the curve of 43075 , 8 inch + filePath = fullfile(directoryPath, fileNames(n)); + load(filePath); + [fitresult, gof] = createFit(SAA{8},MXX{8}); + % Evaluate the fitted curves + for tire=1:length(SAA) + y_fit = fitresult(SAA{tire}); + % Calculate residuals + residuals{tire}{n} = abs(MXX{tire} - fitresult(SAA{tire})); + end +end + +for tire=1:length(SAA) + residuals_one_tire = []; + for n=1:length(fileNames) + residuals_one_tire = [residuals_one_tire; residuals{tire}{n}]; + end + residuals_tire{tire} = residuals_one_tire; +end +% mean +for tire=1:length(SAA) + num = 0; + % each tire under 60 measurement conditions + for i=1:length(residuals_tire{tire}) + if not(isnan(residuals_tire{tire}(i))) + num = num + 1; + else + residuals_tire{tire}(i) = 0; + end + end + residuals_mean{tire} = sum(residuals_tire{tire})/num; +end +% median +for tire=1:length(SAA) + residuals_median{tire} = median(residuals_tire{tire}); +end +% mode +for tire=1:length(SAA) + residuals_mode{tire} = mode(residuals_tire{tire}); +end + +% plots +idx = linspace(1,length(SAA),length(SAA)); + +figure() +subplot(311) +y = cell2mat(residuals_mean); +plot(idx, y, "-*") +title("Average Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + + +subplot(312) +y = cell2mat(residuals_median); +plot(idx, y, "-o") +title("Median of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + + +subplot(313) +y = cell2mat(residuals_mode); +plot(idx, y, "-o") +title("Mode of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on +sgtitle("MX") + +%% Mz +directoryPath = ".\similarityDataMZ"; +% Get a list of all files in the directory +files = dir(fullfile(directoryPath, '*.mat')); % You can adjust the file extension as needed + +% Extract file names +fileNames = {files.name}; + +for n=1:length(fileNames) + % fit the curve of 43075 , 8 inch + filePath = fullfile(directoryPath, fileNames(n)); + load(filePath); + [fitresult, gof] = createFit(SAA{8},MZZ{8}); + % Evaluate the fitted curves + for tire=1:length(SAA) + y_fit = fitresult(SAA{tire}); + % Calculate residuals + residuals{tire}{n} = abs(MZZ{tire} - fitresult(SAA{tire})); + end +end + +for tire=1:length(SAA) + residuals_one_tire = []; + for n=1:length(fileNames) + residuals_one_tire = [residuals_one_tire; residuals{tire}{n}]; + end + residuals_tire{tire} = residuals_one_tire; +end +% mean +for tire=1:length(SAA) + num = 0; + % each tire under 60 measurement conditions + for i=1:length(residuals_tire{tire}) + if not(isnan(residuals_tire{tire}(i))) + num = num + 1; + else + residuals_tire{tire}(i) = 0; + end + end + residuals_mean{tire} = sum(residuals_tire{tire})/num; +end +% median +for tire=1:length(SAA) + residuals_median{tire} = median(residuals_tire{tire}); +end +% mode +for tire=1:length(SAA) + residuals_mode{tire} = mode(residuals_tire{tire}); +end + +% plots +idx = linspace(1,length(SAA),length(SAA)); + +figure() +subplot(311) +y = cell2mat(residuals_mean); +plot(idx, y, "-*") +title("Average Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +grid on +xticks(idx) + + +subplot(312) +y = cell2mat(residuals_median); +plot(idx, y, "-o") +title("Median of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on + + +subplot(313) +y = cell2mat(residuals_mode); +plot(idx, y, "-o") +title("Mode of the Absolute Residuials") +xlabel("Order of the tires(8 is our traget tire)") +ylabel("in 1") +xticks(idx) +grid on +sgtitle("MZ") + + + + + +