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

refact(findstall): replace findpeaks by islocalmax

Rather than looking for the stall point using findpeaks, simply look for
the highest local maximum. Not only is this faster and cleaner, but it
removes the unneeded dependency to the _Signal Processing Toolbox_.
parent 42efd292
No related branches found
No related tags found
No related merge requests found
function [alpha_s, c_l_s, c_d_s] = findstall(varargin)
% FINDSTALL Finds the stall point and returns the corresponding AOA, CL and CD.
% This function uses Matlab's findpeak in order to determine the position of the stall point.
% This function looks for the highest local maximm in the CL curve to determine the position
% of the stall point.
%
% FINDSTALL accepts inputs in the form of a Polar structure (generated with XF2MAT) or values
% for angles of attack and their associated cl and cd. While alpha and cl are required for
......@@ -99,22 +100,11 @@ function [alpha_s, c_l_s, c_d_s] = stallfinder(alpha, c_l, c_d)
% Loop for every polar data (every column of cl)
for i = 1:size(c_l, 2)
% Find stall for each polar using findpeaks
maxFound = false;
minWidth = 0;
% Iterate in order to find only one peak (largest one should indicate the stall)
while ~maxFound && minWidth <= length(alpha(:, i))
[~, locs] = findpeaks(c_l(:, i), 'MinPeakWidth', minWidth);
if numel(locs) == 1
maxFound = true;
else
minWidth = minWidth + 1;
end
end
% Find all local maxima in c_l, then assume the highest one is the stall point
locMax = islocalmax(c_l(:, i));
[~, absMaxIdx] = max(locMax);
if ~maxFound
% If findpeaks does not work
if ~any(locMax)
if PLOT_POLAR_IF_ERROR
figure('Name', 'Debug: Polar with no stall');
plot(rad2deg(alpha(:, i)), c_l(:, i));
......@@ -124,15 +114,15 @@ function [alpha_s, c_l_s, c_d_s] = stallfinder(alpha, c_l, c_d)
grid on;
end
error('MATLAB:findstall:noStallFound', ...
['findpeaks did not found any stall point the polar. '...
['The stall point could not be determined as no local maximum was detected. '...
'Please provide a polar that goes a bit after the stall.\n' ...
'See the attached plot for more details']);
end
alpha_s(i) = alpha(locs, i);
c_l_s(i) = c_l(locs, i);
alpha_s(i) = alpha(absMaxIdx, i);
c_l_s(i) = c_l(absMaxIdx, i);
if ~isempty(c_d)
c_d_s(i) = c_d(locs, i);
c_d_s(i) = c_d(absMaxIdx, i);
end
end
......
......@@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
## [4.2.0] - 2023-12-14
### Changed
- **findstall**: use `islocalmax` rather than `findpeaks` to find stall point.
## [4.1.0] - 2022-11-25
### Added
......@@ -127,7 +133,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial release
[Unreleased]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v4.1.0...master
[Unreleased]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v4.2.0...master
[4.2.0]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/4.1.0...v4.2.0
[4.1.0]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/4.0.0...v4.1.0
[4.0.0]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/3.0.0...4.0.0
[3.0.0]: https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox/-/compare/v2.0.1...v3.0.0
......
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