Skip to content
Snippets Groups Projects
Verified Commit 9720e014 authored by Thomas Lambert's avatar Thomas Lambert :helicopter:
Browse files

fix(plot): bad sync in inertia plot

parent 0e07429d
No related branches found
No related tags found
No related merge requests found
...@@ -9,17 +9,15 @@ function plotwindonoff(ResData) ...@@ -9,17 +9,15 @@ function plotwindonoff(ResData)
% MIT License % MIT License
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(0, 'defaulttextinterpreter', 'latex');
POSITION = 'Front'; POSITION = 'Front';
INTERESTING_POINTS = [ INTERESTING_POINTS = [
0.10, 2.5, 4.6 0.10, 2, 7.7
0.10, 2.5, 7.7
0.10, 3.5, 2.5
0.10, 3.5, 4.6
0.10, 3.5, 7.7
]; ];
PLOT_TIME = true;
PLOT_TIME = false; SAVE_TIKZ_PARAM = []; % INTERESTING_POINTS(1:2, :);
SAVE_TIKZ_PARAM = INTERESTING_POINTS(1:2, :); MYGREY = [186, 216, 221] / 255;
for i = 1:size(ResData, 1) for i = 1:size(ResData, 1)
for j = 1:size(ResData, 2) for j = 1:size(ResData, 2)
...@@ -40,44 +38,134 @@ function plotwindonoff(ResData) ...@@ -40,44 +38,134 @@ function plotwindonoff(ResData)
windOn = ResData(i, j).(POSITION); windOn = ResData(i, j).(POSITION);
timeOn = ResData(i, j).time; timeOn = ResData(i, j).time;
meanPeakAngle = averagepeaks(windOff.angles, sampling, windOff.trueFreq); %% PROBABLY BETTER
meanPeakFoff = averagepeaks(windOff.forces(:, 3), sampling, windOff.trueFreq); windOffPeriodIdx = getmeanperiodidx(windOff.angles, sampling, windOff.trueFreq);
meanPeakFon = averagepeaks(windOn.forces(:, 3), sampling, windOn.trueFreq); windOnPeriodIdx = getmeanperiodidx(windOn.angles, sampling, windOn.trueFreq);
windOffIdx = windOffPeriodIdx(1):windOffPeriodIdx(2);
windOnIdx = windOnPeriodIdx(1):windOnPeriodIdx(2);
% Trim to same length if needed % Trim to same length if needed
minLen = min(length(meanPeakFoff), length(meanPeakFon)); minLen = min(length(windOffIdx), length(windOnIdx));
meanPeakAngle = meanPeakAngle(1:minLen); windOffIdx = windOffIdx(1:minLen);
meanPeakFoff = meanPeakFoff(1:minLen); windOnIdx = windOnIdx(1:minLen);
meanPeakFon = meanPeakFon(1:minLen);
meanDiff = meanPeakFon - meanPeakFoff;
% True period % True period
period = 1 / windOff.trueFreq; period = 1 / windOff.trueFreq;
nPeriodIdx = period * sampling; nPeriodIdx = period * sampling;
if PLOT_TIME fzOff = windOff.forces(windOffIdx, 3);
time = (0:length(meanDiff) - 1) / nPeriodIdx; anglesOff = windOff.angles(windOffIdx);
anglesOn = windOn.angles(windOnIdx);
figure; fzOn = windOn.forces(windOnIdx, 3);
hold on; meanDiff = fzOn - fzOff;
plot(time, meanPeakFoff);
plot(time, meanPeakFon); time = (0:length(meanDiff) - 1) / nPeriodIdx;
plot(time, meanDiff); [~, donwStrokeEndIdx] = min(anglesOff);
yyaxis right;
plot(time, meanPeakAngle); figure;
title(expParam); setcolormap();
legend('Wind off', 'Wind on', 'Diff'); hold on;
grid on; patchX = [0, donwStrokeEndIdx / nPeriodIdx, donwStrokeEndIdx / nPeriodIdx, 0];
xlim([0, 1]); patchY = [-5, -5, 10, 10];
patch(patchX, patchY, [186, 216, 221] / 255, 'EdgeColor', 'none', 'FaceAlpha', 0.5);
h1 = plot(time, fzOff, 'LineWidth', 1.2);
h2 = plot(time, fzOn, 'LineWidth', 1.2);
h3 = plot(time, meanDiff, 'LineWidth', 1.2);
text((donwStrokeEndIdx / nPeriodIdx) / 2, -1.25, ...
'Downstroke', ...
'HorizontalAlignment', 'center');
text(donwStrokeEndIdx / nPeriodIdx + ...
(1 - (donwStrokeEndIdx / nPeriodIdx)) / 2, -1.25, ...
'Upstroke', ...
'HorizontalAlignment', 'center');
setgca();
legend([h1, h2, h3], {'\airspeed = 0 m/s', '\airspeed = 7.7 m/s', 'Difference'});
legend('boxoff');
xlim([0, 1]);
ylim([-1.5 1.5]);
if isinteresting(ResData(i, j), SAVE_TIKZ_PARAM)
figdir = 'figures/results/';
filename = sprintf('inertia-period-Dx%0.2f_F%0.2f_V%0.1f.tex', ...
ResData(i, j).Testcase.dx, ...
ResData(i, j).Testcase.freq, ...
ResData(i, j).Testcase.airspeed);
save2tikz([figdir, filename], '\small');
end end
title(expParam);
figure;
hold on;
plot(time, fzOff);
plot(time, fzOn);
plot(time, meanDiff);
plot(time(round(end / 5)), fzOn(round(end / 5)), 'or');
yyaxis right;
plot(time, windOff.angles(windOffIdx));
title(expParam);
legend('Wind off', 'Wind on', 'Diff');
grid on;
xlim([0, 1]);
figure;
ax1 = subplot(3, 1, 1);
setcolormap();
hold on;
plot(anglesOn, fzOn);
plot(anglesOn(round(end / 5)), fzOn(round(end / 5)), 'or');
setgca('XTickLabel', [], ...
'YLabel', [], ...
'XLabel', []);
ax2 = subplot(3, 1, 2);
setcolormap();
hold on;
plot(anglesOff, fzOff);
% plot(meanPeakAngle(round(end / 5)), meanPeakFoff(round(end / 5)), 'or');
setgca('XTickLabel', [], ...
'XLabel', []);
ax3 = subplot(3, 1, 3);
setcolormap();
hold on;
plot(anglesOff, meanDiff);
% plot(meanPeakAngle(round(end / 5)), meanDiff(round(end / 5)), 'or');
linkaxes([ax1 ax2 ax3], 'xy');
ax1.YLim = 1.25 * ax1.YLim;
setgca('YLabel', []);
if isinteresting(ResData(i, j), SAVE_TIKZ_PARAM)
figdir = 'figures/results/';
filename = sprintf('inertia-Dx%0.2f_F%0.2f_V%0.1f.tex', ...
ResData(i, j).Testcase.dx, ...
ResData(i, j).Testcase.freq, ...
ResData(i, j).Testcase.airspeed);
save2tikz([figdir, filename], '\small');
end %
figure;
hold on;
plot(time, fzOff);
plot(time, fzOn);
plot(time, meanDiff);
plot(time(round(end / 5)), fzOn(round(end / 5)), 'or');
yyaxis right;
plot(time, windOff.angles(windOffIdx));
title(expParam);
legend('Wind off', 'Wind on', 'Diff');
grid on;
xlim([0, 1]);
figure; figure;
ax1 = subplot(3, 1, 1); ax1 = subplot(3, 1, 1);
setcolormap(); setcolormap();
hold on; hold on;
plot(meanPeakAngle, meanPeakFon); plot(anglesOn, fzOn);
% plot(meanPeakAngle(round(end / 5)), meanPeakFon(round(end / 5)), 'or'); plot(anglesOn(round(end / 5)), fzOn(round(end / 5)), 'or');
setgca('XTickLabel', [], ... setgca('XTickLabel', [], ...
'YLabel', [], ... 'YLabel', [], ...
'XLabel', []); 'XLabel', []);
...@@ -85,7 +173,7 @@ function plotwindonoff(ResData) ...@@ -85,7 +173,7 @@ function plotwindonoff(ResData)
ax2 = subplot(3, 1, 2); ax2 = subplot(3, 1, 2);
setcolormap(); setcolormap();
hold on; hold on;
plot(meanPeakAngle, meanPeakFoff); plot(anglesOff, fzOff);
% plot(meanPeakAngle(round(end / 5)), meanPeakFoff(round(end / 5)), 'or'); % plot(meanPeakAngle(round(end / 5)), meanPeakFoff(round(end / 5)), 'or');
setgca('XTickLabel', [], ... setgca('XTickLabel', [], ...
'XLabel', []); 'XLabel', []);
...@@ -93,7 +181,7 @@ function plotwindonoff(ResData) ...@@ -93,7 +181,7 @@ function plotwindonoff(ResData)
ax3 = subplot(3, 1, 3); ax3 = subplot(3, 1, 3);
setcolormap(); setcolormap();
hold on; hold on;
plot(meanPeakAngle, meanDiff); plot(anglesOff, meanDiff);
% plot(meanPeakAngle(round(end / 5)), meanDiff(round(end / 5)), 'or'); % plot(meanPeakAngle(round(end / 5)), meanDiff(round(end / 5)), 'or');
linkaxes([ax1 ax2 ax3], 'xy'); linkaxes([ax1 ax2 ax3], 'xy');
ax1.YLim = 1.25 * ax1.YLim; ax1.YLim = 1.25 * ax1.YLim;
...@@ -111,6 +199,12 @@ function plotwindonoff(ResData) ...@@ -111,6 +199,12 @@ function plotwindonoff(ResData)
title(ax1, ['Wind on - ', expParam]); title(ax1, ['Wind on - ', expParam]);
title(ax2, ['Wind off - ', expParam]); title(ax2, ['Wind off - ', expParam]);
title(ax3, ['Diff - ', expParam]); title(ax3, ['Diff - ', expParam]);
% Add titles after having saved
title(ax1, ['Wind on - ', expParam]);
title(ax2, ['Wind off - ', expParam]);
title(ax3, ['Diff - ', expParam]);
end end
end end
...@@ -118,8 +212,8 @@ function plotwindonoff(ResData) ...@@ -118,8 +212,8 @@ function plotwindonoff(ResData)
end end
function meanPeak = averagepeaks(signal, sampling, freq) function meanPeriod = getmeanperiodidx(signal, sampling, freq)
% AVERAGEPEAKS Make the average of all peaks in the signal % GETMEANPEAK Return bounds of a period somewhere in the signal
period = 1 / freq; period = 1 / freq;
nPeriodIdx = period * sampling; nPeriodIdx = period * sampling;
...@@ -128,19 +222,14 @@ function meanPeak = averagepeaks(signal, sampling, freq) ...@@ -128,19 +222,14 @@ function meanPeak = averagepeaks(signal, sampling, freq)
% Remove first and last peaks % Remove first and last peaks
peakLocs = peakLocs(2:end - 1); peakLocs = peakLocs(2:end - 1);
% Create mean peak meanPeriod = [peakLocs(round(end / 3)), peakLocs(round(end / 3)) + nPeriodIdx];
for i = 1:min(length(peakLocs), 100)
peakVals(i, :) = signal(round(peakLocs(i) - nPeriodIdx / 2): ...
round(peakLocs(i) + nPeriodIdx / 2));
end
meanPeak = mean(peakVals);
end end
function setgca(varargin) function setgca(varargin)
xlabel('Flapping angle [deg]'); xlabel('t/T [-]');
ylabel('\cfz [N]'); ylabel('\fz [N]');
set(gca, ... set(gca, ...
'Box', 'off', ... 'Box', 'off', ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment