How to interpolate my data to produce a variable tolerance band

7 ビュー (過去 30 日間)
Chris Swain-Phipps
Chris Swain-Phipps 2022 年 3 月 14 日
コメント済み: Mathieu NOE 2022 年 3 月 18 日
I have 2 seperate in input arrays, containing x and y values which when plotted give me a black line in the graph similar to the following:
I am looking to apply upper and lower tolerance limits to my data to produce a graph with tighter tolerancing for small Y values (e.g 2x) than large values with a cap of 5x max(Y) and -1/5 max(Y) for the upper and lower tolerances as shown.
My initial thoughts were that interpolation of each Y value based on proximity of the X value to max(Y) would be the best approach however I can't seem to get my data into the correct format for the "interp1" command to produce the graph similar to the one i've drawn above as the Y values are not based on a mathematical function!
Any thoughts?

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 3 月 15 日
hello
maybe this ? your 2 and 5 factors are my a and b in the code below :
clc
clearvars
% dummy signal
n=300;
x=linspace(0,2*pi,n);
y = 0.25*ones(size(x));
y = max(y,-cos(x));
% min / max coefficients
a = 2;
b = 5;
bell_factor = length(y)/7; % tune the bell shape (narrow or wider)
%% main code
a_min1 = a*min(y);
a_max1 = b*max(y);
a_min2 = (1-1/a)*min(y);
a_max2 = (1-1/b)*max(y);
% find peak point
[val,ind] = max(y);
for ci = 1:n
dist = abs(ci-ind);
limit_upper(ci) = a_min1 + (a_max1 - a_min1)*exp(-(dist/bell_factor)^2);
limit_lower(ci) = a_min2 + (a_max2 - a_min2)*exp(-(dist/bell_factor)^2);
end
figure(1)
plot(x,y,'k',x,limit_upper,'g--',x,limit_lower,'b--','linewidth',2,'markersize',12);
  4 件のコメント
Chris Swain-Phipps
Chris Swain-Phipps 2022 年 3 月 18 日
編集済み: Chris Swain-Phipps 2022 年 3 月 18 日
Hi Mathieu,
Basically, I'm looking for a way for the limits to be set based on the values of some reference data.
So in your graph that you produced above, I want the limits curves to have a similar shape but scaled differently in the Y-axis based on the distance away from the maximum value, something like this:
I've added a feature to the reference signal you created to empahsise that this should also be visible on the tolerance curve.
Hope that clarifies things.
Mathieu NOE
Mathieu NOE 2022 年 3 月 18 日
hello Cristopher
a new attempt here below :
clc
clearvars
% dummy signal
n=300;
x=linspace(0,2*pi,n);
y = 0.25*ones(size(x));
y = max(y,-cos(x));
y(200:220) = 0.5;
% min / max coefficients
a = 2;
b = 5;
%% main code
% find peak point
[val,ind] = max(y);
for ci = 1:n
dist = abs(ci-ind)./ind;
limit_upper(ci) = (a + (b - a)*(1-dist)).*y(ci);
limit_lower(ci) = (1/a + (1/b - 1/a)*(1-dist)).*y(ci);
end
figure(1)
plot(x,y,'k',x,limit_upper,'g--',x,limit_lower,'b--','linewidth',2,'markersize',12);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by