Extracting Zoomed in part of curve and finding rising Edges of data

조회 수: 10 (최근 30일)
Jason
Jason 2025년 2월 4일
댓글: Star Strider 2025년 2월 17일
Hello, I have a plot consisting of "square-ish" TTL pulses and I want to be able to
1: Extract the data thats in the "Zoomed" XLim, and then
2: Find the x-location of each rising edge at a certain y-value (say 3, although I may not have data thats exactly on 3, so the nearest to it)
3: Bin the seperations of each rising edge. As you can see below from the 2nd (zoomed in) plot I am having some drop outs so I want to analyse e.g. if there is any variabity in the drop out seperation as well as the actual rising edge seperation. My actual data consists of thousands of these peaks
(I dont have the signal processing toolbox!)
Heres a sample of my real data
and here's a zoomed in version (this would be what I would want to work with and I obtain it by setting the XLims
So for 1: above, I have this.
ax=app.UIAxes;
newlimits =ax.XLim;
[x,y] = getDataFromGraph(app,ax,1); %See function below
xminidx = find(x >= newlimits(1),1,"first");
xmaxidx = find(x <= newlimits(2),1,"last");
X=x(xminidx:xmaxidx,1); Y=y(xminidx:xmaxidx,1);
D=[X,Y];
head(D,8) %View data
where
function [datax,datay] = getDataFromGraph(app,ax,n)
% ax = axes plot is on
% n is the plot index, 1 is the last plot
b=ax.Children; % b(1) is last object added to ax
datax=(b(n).XData)';
datay=(b(n).YData)';
end
Then for 2, this is where I am struggling, I have tried this:
rising_edges = find(diff(X > 3) > 0)
hold(ax,"on");
xline(ax,X(rising_edges))
But rising_edges is empty.
And for 3 I have no idea how to plot some kind of histogram of the seperations between adjacent pulse
  댓글 수: 8
Jason
Jason 2025년 2월 12일
thanks steven, ultimately I need to use appd esigner, but I would be keen to explore your suggestion. where do I find this "Find Local Extrema task "
thank
Steven Lord
Steven Lord 2025년 2월 12일
The "Open the Task" section on the documentation page to which I linked describes two ways to add the task to a live script.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2025년 2월 4일
Depending on the result you want, it might be easier to use islocalmax for this —
T1 = readtable('DS0007_REDUCED.CSV')
T1 = 2522x2 table
Col1 Col2 _______ ____ 0.00033 4.72 0.00034 4.8 0.00035 4.72 0.00036 4.68 0.00037 4.72 0.00038 4.72 0.00039 4.72 0.0004 4.72 0.00041 4.8 0.00042 4.8 0.00043 4.72 0.00044 4.72 0.00045 4.8 0.00046 4.72 0.00047 4.72 0.00048 4.72
t = T1.Col1;
s = T1.Col2;
% figure
% plot(t, s)
% grid
Lvs = islocalmax(s, 'flatselection', 'first', MinProminence=0.5);
Lve = islocalmin(s, 'flatselection', 'last', MinProminence=0.5);
figure
plot(t, s)
hold on
plot(t(Lvs), s(Lvs), '|r')
plot(t(Lve), s(Lve), '|m')
hold off
grid
figure
plot(t, s)
hold on
plot(t(Lvs), s(Lvs), '|r')
plot(t(Lve), s(Lve), '|m')
hold off
grid
xlim([0.011 0.025])
ylim('padded')
Lvt = t >= 0.01;
Ivs = find(Lvs & Lvt);
Ive = find(Lve & Lvt);
for k = 1:numel(Ivs)
idxrng = Ivs(k) - 10 : Ive(k) + 10;
segments{k} = [t(idxrng) s(idxrng)];
end
figure
tiledlayout(4,2)
for k = 1:numel(segments)
nexttile
plot(segments{k}(:,1), segments{k}(:,2))
hold on
plot(t(Ivs(k)), s(Ivs(k)), 'vr')
plot(t(Ive(k)), s(Ive(k)), '^r')
hold off
grid
title(string(k))
ylim('padded')
end
.
  댓글 수: 29
Jason
Jason 2025년 2월 17일
Thankyou so much, I wasn't expecting you to spend all your personal time on this - I really am very grateful to you. What is the key features that different here?
Star Strider
Star Strider 2025년 2월 17일
As always, my pleasure!
I wasn’t going to give up on this until I got a reasonable approach, since it seems to be important to what you’re doing. The key difference is that it is now adaptible. For whatever reason, with the MinProminence value set a a higher value, the last ‘valley’ isn’t detected in some files. With a lower value it is, however with some of the other files, that also identifies a lot of noise. So this approach first uses the higher value, and if then are fewer ‘valleys’ that ‘peaks’ (and all the valleys occurring after the first ‘peak’), it uses the lower value and checks those results. (Thus far it hasn’t needed to add any other adaptations.) With this approach, it results in identifying all the peaks and valleys for each file. It then checks to be sure there are an equal number of beginning and end indices, and calculates and creates the ‘PulseParameters’ table.
It would be difficult to have the results table have the same name as the original file (without the extension), however if you want to store the results files in an identifiable way, create a .mat file with that name:
fn = extractBefore(filename,'.');
save([fn ' PulseParameters.mat'], 'PulseParameters')
In the ‘analysePulseTrain’ function, add these lines after creating the table. That should result in a file with a matching name, for example:
DS0007_REDUCED PulseParameters.mat
I thought of that later.
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by