How to make threshold lines and mark the 1st intersection line?

4 views (last 30 days)
Hi, I would like to ask a few questions:
  1. How to set 20% upper and lower threshold from the signal maximum amplitude and make a line of the thresholds.
  2. From the upper threshold line, how to find and mark the 1st line intersection between upper threshold and signal.
  3. How to expand the signal that only focus on the line intersection automatically.
I really appreciate if anyone can help me with matlab coding.
load energy_bigcircle_placement1 %load file
[p,s,mu]=polyfit((1:numel(bigcircle_ant2))',bigcircle_ant2,20);
f_y=polyval(p,(1:numel(bigcircle_ant2))',[],mu);
bigcircle_ant2_data=bigcircle_ant2 - f_y;
tms=(0:numel(bigcircle_ant2_data)-1)/Fs;
figure (1)
plot(tms,bigcircle_ant2_data)
axis tight
title('Signal and Scalogram')
xlabel('Time(s)')
ylabel('Amplitude')
grid on
Regards.

Accepted Answer

Image Analyst
Image Analyst on 31 Dec 2019
What do you mean by upper and lower 20%? Do you mean like percent of the range from the min to the max value?
theRange = max(bigcircle_ant2_data) - min(bigcircle_ant2_data)
v1 = min(bigcircle_ant2_data) + 0.2 * theRange
v2 = min(bigcircle_ant2_data) + 0.8 * theRange
% Draw horizontal lines across the plot at these values.
line(xlim, [v1, v1], 'Color', 'r')
line(xlim, [v2, v2], 'Color', 'r')
v1 =
-0.185422184752362
v2 =
0.176083685039577
Or do you mean by looking at how often the values occur, like taking the histogram?
sortedValues = sort(bigcircle_ant2_data, 'ascend')
n = numel(sortedValues)
index1 = round(0.2 * n)
index2 = round(0.8 * n)
v1 = sortedValues(index1)
v2 = sortedValues(index2)
line(xlim, [v1, v1], 'Color', 'r')
line(xlim, [v2, v2], 'Color', 'r')
v1 =
-0.00543053385884211
v2 =
0.0115623903477877
load energy_bigcircle_placement1 %load file
[p,s,mu]=polyfit((1:numel(bigcircle_ant2))',bigcircle_ant2,20);
f_y=polyval(p,(1:numel(bigcircle_ant2))',[],mu);
bigcircle_ant2_data=bigcircle_ant2 - f_y;
tms=(0:numel(bigcircle_ant2_data)-1)/Fs;
figure (1)
plot(tms,bigcircle_ant2_data)
axis tight
title('Signal and Scalogram')
xlabel('Time(s)')
ylabel('Amplitude')
grid on
0000 Screenshot.png
To find where the signal first crosses some value, use find(). Use plot() to place a marker there.
index = find(bigcircle_ant2_data > v1, 1, 'first')
x1 = tms(index)
% Plot a circle there
hold on;
plot(x1, bigcircle_ant2_data(index), 'ro', 'MarkerSize', 10, 'LineWidth', 2)
To zoom in to +/1 0.05 around x1, change xlim()
xlim([x1 - 0.05, x1 + 0.05]);
  5 Comments
Image Analyst
Image Analyst on 1 Jan 2020
It doesn't lie EXACTLY on the line because there is no point in your data that is exactly on the line.
So the circle is the first point past where the line intersects the red line, and that circle will be around an actual data point.
If you need it exactly on the red line, then you can use bilinear interpolation to find a time where the Amplitude will be exactly the value of the red line.
melaty amirruddin
melaty amirruddin on 30 Sep 2020
Hi Image Analyst,
Sorry for contacting you from this previous post. I try to find out how to communicate with you, but I can't find any message button in your profile. I really appreciate if you can help me answering my question here:
Thank you in advance.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!