Find value of signal A at a given value of signal B (twice for every cycle)?

1 visualización (últimos 30 días)
In this particular task, value of signal A at a given value of signal B is required. Here, time axis is not available and interpolation is required as csv file does not include all the data points. Minima and Maxima were relatively easy to find than this.
For example, whenever B = 70, it should give 50 values of signal A for these 25 cycles in a table/matrix. I tried using interpolation function but it gives only one value and not 50 values. yes, something is missing in the code!!
I tried this code which gives only one value:
X=dlmread('file1.txt');
A=X(:,1);
B=X(:,2);
xx = interp1(B,A, 70);
Later, seperation of those value is required based on if they were found on positive going edge or negative.
  2 comentarios
Matt J
Matt J el 23 de Jul. de 2022
Your code doesn't contain a variable called "B" nor does it show how the plot was generated.
Himanshu Bhadja
Himanshu Bhadja el 25 de Jul. de 2022
I have updated the variable names in the description. And also added a text file which is used to generate the plot

Iniciar sesión para comentar.

Respuestas (2)

Matt J
Matt J el 23 de Jul. de 2022
Editada: Matt J el 25 de Jul. de 2022
Download this,
and then,
[starts,stops]=groupLims( groupTrue(B>=70) , 1);
Avalues=A([starts,stops]);
  2 comentarios
Himanshu Bhadja
Himanshu Bhadja el 25 de Jul. de 2022
This worked but it find points from the input file only. As i mentioned in the question, not all the data points are available in file. So if the signal does not have exact value 70 then it will take any nearest number and respective value of another signal. But i would like to have interpolated values so that it could give value of signal B when signal A is exactly at 70
Matt J
Matt J el 25 de Jul. de 2022
Editada: Matt J el 25 de Jul. de 2022
Yes, but once you know the nearest values, you can interpolate.
for i=1:numel(starts)
I=starts(i)-1:starts(i);
Avalues(1,i)=interp1(B(I), A(I),70);
I=stops(i):stops(i)+1;
Avalues(2,i)=interp1(B(I), A(I),70);
end

Iniciar sesión para comentar.


Bruno Luong
Bruno Luong el 25 de Jul. de 2022
Editada: Bruno Luong el 25 de Jul. de 2022
You can fit a model to the interpolated data to remove the jump due to interval leap
ab=load('file1.txt');
a=ab(:,1);
b=ab(:,2);
[bb,i]=unique(b);
b2afun=@(b) interp1(bb,a(i),b);
bquery=20:120;
aquery=b2afun(bquery);
plot(bquery,aquery);
xlabel('b')
ylabel('a')
  1 comentario
Bruno Luong
Bruno Luong el 25 de Jul. de 2022
Editada: Bruno Luong el 25 de Jul. de 2022
Actually your data seems to behave differently when a/b increases or decreases (first plot), similar to hysteresis. So here I separate interpolation in two branches
ab=load('file1.txt');
a=ab(:,1);
b=ab(:,2);
plot(a,b)
[~,locv] = findpeaks(-b);
[~,locp] = findpeaks(+b);
if locp(1) < locv(1)
locv = [1; locv];
else
locp = [1; locp];
end
if locp(end) > locv(end)
locv = [locv; length(b)];
else
locp = [locp; length(b)];
end
loc = [locp; locv];
[loc, is] = sort(loc);
ip = is <= length(locp);
[~,i] = histc((1:length(b))',loc);
n = length(loc);
icrop = max(min(i,n-1),1);
ivalid = i>=1 & i<=n-1;
asc = ivalid & ~ip(icrop) & ip(icrop+1);
dsc = ivalid & ip(icrop) & ~ip(icrop+1);
[asc_b,j]=unique(b(asc));
ia = find(asc);
ia = ia(j);
asc_b2afun=@(b) interp1(asc_b,a(ia),b);
[dsc_b,j]=unique(b(dsc));
id = find(dsc);
id = id(j);
dsc_b2afun=@(b) interp1(dsc_b,a(id),b);
bquery=20:120;
asc_aquery=asc_b2afun(bquery);
dsc_aquery=dsc_b2afun(bquery);
plot(bquery,asc_aquery,bquery,dsc_aquery);
xlabel('b')
ylabel('a')
legend('ascending interpolation', 'descending interpolation', 'location', 'best')

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by