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

line intersectionthreshold

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.

Best Answer

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]);