Find value of signal A at a given value of signal B (twice for every cycle)?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
el 23 de Jul. de 2022
Your code doesn't contain a variable called "B" nor does it show how the plot was generated.
Respuestas (2)
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]);
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
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')
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!