PT:plot to compare. FX, FY, Mx, MZ

This commit is contained in:
Pengtao Xie 2024-01-05 19:46:37 +01:00
parent 96459e2b8f
commit 824f9b1e74
6 changed files with 470 additions and 32 deletions

BIN
scripts/FX.fig Normal file

Binary file not shown.

BIN
scripts/FY.fig Normal file

Binary file not shown.

BIN
scripts/MX.fig Normal file

Binary file not shown.

BIN
scripts/MZ.fig Normal file

Binary file not shown.

View File

@ -1,7 +1,8 @@
%% please open Magic Formular APP first %% please open Magic Formular APP first
clear clear
clc
n = 20; n = 20;
mkdir('similarityData');
%% %%
directoryPath = "..\sorted_data"; directoryPath = "..\sorted_data";
subdirectories = getSubdirectories(directoryPath); subdirectories = getSubdirectories(directoryPath);
@ -15,32 +16,207 @@ subdirectories_list = contents([contents.isdir] & ~ismember({contents.name}, {'.
% Extract and display the names of the subdirectories % Extract and display the names of the subdirectories
subdirectoryNames = {subdirectories_list.name}; 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); % SA-MX
FY = smoothdata(FY, "gaussian",100); % figure()
if i < length(subdirectories)/3 % for i=1:length(subdirectories)
plot(SA, FY, 'LineWidth', 1) % fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat");
elseif i <= length(subdirectories)/3*2 % parser = tydex.parsers.FSAETTC_SI_ISO_Mat();
plot(SA, FY, '--','LineWidth', 1) % measurements = parser.run(fileMeasurement);
else % measurement = measurements(n);
plot(SA, FY, '-.','LineWidth', 1) %
% [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 end
SAA{i} = SA; title("Similarities, n=",n)
FYY{i} = FY; xlabel("SA")
hold on ylabel("FY")
end end
legend(subdirectoryNames{:}) %% without plot
title("Similarities, n=",n) % mkdir('similarityDataFY');
xlabel("Slip Angle") % for n=1:60
ylabel("FY") % for i=1:length(subdirectories)
%% without plot % 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 n=1:60
for i=1:length(subdirectories) for i=1:length(subdirectories)
fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat"); fileMeasurement = fullfile("..\sorted_data", subdirectories{i}, "\cornering.mat");
@ -49,10 +225,10 @@ for n=1:60
measurement = measurements(n); measurement = measurements(n);
[SX,SA,FZ,IP,IA,VX,FX,FY,MZ,MY,MX,W,T] = unpack(measurement); [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; SAA{i} = SA;
FYY{i} = FY; MXX{i} = MX;
end end
file_name = ['similarityData\nEqu' num2str(n) '.mat']; file_name = ['similarityDataMX\nEqu' num2str(n) '.mat'];
save(file_name, 'SAA', 'FYY'); save(file_name, 'SAA', 'MXX');
end end

View File

@ -1,6 +1,7 @@
clear; clear;
clc; clc;
% Use the dir function to get information about files and directories
% % FY
directoryPath = ".\similarityData"; directoryPath = ".\similarityData";
% Get a list of all files in the directory % Get a list of all files in the directory
@ -29,7 +30,7 @@ for tire=1:length(SAA)
end end
residuals_tire{tire} = residuals_one_tire; residuals_tire{tire} = residuals_one_tire;
end end
%% mean % mean
for tire=1:length(SAA) for tire=1:length(SAA)
num = 0; num = 0;
% each tire under 60 measurement conditions % each tire under 60 measurement conditions
@ -42,11 +43,11 @@ for tire=1:length(SAA)
end end
residuals_mean{tire} = sum(residuals_tire{tire})/num; residuals_mean{tire} = sum(residuals_tire{tire})/num;
end end
%% median % median
for tire=1:length(SAA) for tire=1:length(SAA)
residuals_median{tire} = median(residuals_tire{tire}); residuals_median{tire} = median(residuals_tire{tire});
end end
%% mode % mode
for tire=1:length(SAA) for tire=1:length(SAA)
residuals_mode{tire} = mode(residuals_tire{tire}); residuals_mode{tire} = mode(residuals_tire{tire});
end end
@ -64,6 +65,7 @@ ylabel("in 1")
xticks(idx) xticks(idx)
grid on grid on
subplot(312) subplot(312)
y = cell2mat(residuals_median); y = cell2mat(residuals_median);
plot(idx, y, "-o") plot(idx, y, "-o")
@ -81,4 +83,264 @@ title("Mode of the Absolute Residuials")
xlabel("Order of the tires(8 is our traget tire)") xlabel("Order of the tires(8 is our traget tire)")
ylabel("in 1") ylabel("in 1")
xticks(idx) xticks(idx)
grid on 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")