You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Voltage find equation diagramm
4 views (last 30 days)
Show older comments
Accepted Answer
Star Strider
on 7 Nov 2023
Perhaps this —
imshow(imread('LI.jpg'))
T1 = readtable('Versuch.txt');
T1.Properties.VariableNames = {'Time','Voltage'}
[V1,V2] = bounds(T1.Voltage);
Vnorm = (T1.Voltage-V1) / (V2-V1);
figure
tiledlayout(2,1)
nexttile
plot(T1.Time, T1.Voltage, '.-b')
grid
xlabel('Time')
ylabel('Voltage')
title('Original')
nexttile
plot(T1.Time, Vnorm, '.-r')
xlabel('Time')
ylabel('Voltage')
title('Normalised')
grid
.
25 Comments
Star Strider
on 7 Nov 2023
As always, my pleasure!
Tt ka
on 7 Nov 2023
maybe you have also an idea, how could I find a "zero Point" on the normalised diagramm? It should also be marked as a black point. The Zero Point must be on the x-axis, but I did not find any information on this special case...
I have tried to use this code, but it didn't work properly.
plot(Time, Voltage, 'k');
idx = (Voltage == 0);
hold on;
myplot = plot(Vnorm(idx), Time(idx), '*r');
for ind=idx;
datatip(myplot,Voltage(ind),Time(ind))
end
Thank you in advance.
Star Strider
on 7 Nov 2023
As always, my pleasure!
I assume the zero point is only defined on the original data.
Try this —
T1 = readtable('Versuch.txt');
T1.Properties.VariableNames = {'Time','Voltage'}
T1 = 10000×2 table
Time Voltage
_________ _______
-1e-05 -50003
-9.99e-06 -50003
-9.98e-06 -50003
-9.97e-06 -50003
-9.96e-06 -50003
-9.95e-06 -50003
-9.94e-06 -50003
-9.93e-06 -50003
-9.92e-06 -50003
-9.91e-06 -50003
-9.9e-06 -50003
-9.89e-06 -50003
-9.88e-06 -50003
-9.87e-06 -50003
-9.86e-06 -50003
-9.85e-06 -50003
zxi = find(diff(sign(T1.Voltage))); % Index Of Approximate Zero Crossing
idxrng = max(1,zxi-1) : min(height(T1),zxi+1); % Index Range
ExactTime = interp1(T1.Voltage(idxrng), T1.Time(idxrng), 0) % Interpolate To Find Percise Value
ExactTime = 1.3182e-08
figure
plot(T1.Time, T1.Voltage, '-r')
hold on
plot(ExactTime, 0, 'sk', 'MarkerFaceColor','k')
hold off
grid
expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)))) floor(log10(abs(x(:))))];
text(ExactTime, 0, sprintf(' \\leftarrow Zero-Crossing Time = %6.3f \\times 10^{%2d} s',expstr(ExactTime)), 'Horiz','left', 'Vert','middle')

The code first finds the approximate index of the zero-crossing, then uses a range of indices centred on it to do the interpolation. (This first narrows the interpolation region and second — with rare exceptions— avoids the problem of the crossing points not being unique, since it will do this for every crossing index in a loop if there is more than one.)
.
Tt ka
on 7 Nov 2023
Edited: Tt ka
on 19 Nov 2023
Thanks a million for your coding!
just a short question:
If we want to put on a normalised graph 2 points: A und B; A must be on the 30 % of the voltage on the verticale line and B must be on the 90% of the voltage also on the verticale line.
Would the code be much different in comparison to the previos one?
After that we want to draw a line between these two points, this line must touch the x-axis.
Star Strider
on 7 Nov 2023
I do not understand what you want to do. I assume you want vertical lines plotted vrom the x-axis to the 30% and 90% points on the curve. I would code it a bit differently.
Try this —
T1 = readtable('Versuch.txt');
T1.Properties.VariableNames = {'Time','Voltage'}
T1 = 10000×2 table
Time Voltage
_________ _______
-1e-05 -50003
-9.99e-06 -50003
-9.98e-06 -50003
-9.97e-06 -50003
-9.96e-06 -50003
-9.95e-06 -50003
-9.94e-06 -50003
-9.93e-06 -50003
-9.92e-06 -50003
-9.91e-06 -50003
-9.9e-06 -50003
-9.89e-06 -50003
-9.88e-06 -50003
-9.87e-06 -50003
-9.86e-06 -50003
-9.85e-06 -50003
format shortE
[V1,V2] = bounds(T1.Voltage);
Vnorm = (T1.Voltage-V1) / (V2-V1);
L = height(T1);
idx30 = find(diff(sign(Vnorm - 0.3)));
for k = 1:numel(idx30)
idxrng = max(1,idx30(k) : min(L,idx30(k)+1));
time30(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.3);
end
time30
time30 =
9.5839e-08
idx90 = find(diff(sign(Vnorm - 0.9)));
for k = 1:numel(idx90)
idxrng = max(1,idx90(k) : min(L,idx90(k)+1));
time90(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.9);
end
time90
time90 = 1×2
1.0e+00 *
5.9968e-07 1.0689e-05
figure
plot(T1.Time, Vnorm)
hold on
plot([0; 0]+time30, [0; 0.3], '.-c')
plot([0; 0]+time90, [0; 0.9], '.-m')
hold off
grid

There is only one intersection at the 30% level, that being at 9.5839E-008 seconds (cyan line), and two intersections at the 90% level, at 5.9968E-007 and 1.0689E-005 seconds (magenta lines).
If you wnat to plot something else, please be a bit more specific.
.
Star Strider
on 8 Nov 2023
Windows 11 managed to crash to do something with ‘autopilot’ bloatware (that I neither asked for nor ever intend to use) twice in 15 minutes. I’ll see if it can avoid crashing for the time ti takse to respond to your latest request. (I’m searching out Linux distributions to see what is the best and most reliable and appropriate for my needs, then ditching Micro$oft forever. I’ve grown to absolutely hate Windows in the last 1½ years.)
Well, at least it didn’t crash again in the last few minutes.
Your waveform is not the same as the waveform in the image, so the plot is not going to look the same.
Try this —
T1 = readtable('Versuch.txt');
T1.Properties.VariableNames = {'Time','Voltage'}
T1 = 10000×2 table
Time Voltage
_________ _______
-1e-05 -50003
-9.99e-06 -50003
-9.98e-06 -50003
-9.97e-06 -50003
-9.96e-06 -50003
-9.95e-06 -50003
-9.94e-06 -50003
-9.93e-06 -50003
-9.92e-06 -50003
-9.91e-06 -50003
-9.9e-06 -50003
-9.89e-06 -50003
-9.88e-06 -50003
-9.87e-06 -50003
-9.86e-06 -50003
-9.85e-06 -50003
format shortE
[V1,V2] = bounds(T1.Voltage);
Vnorm = (T1.Voltage-V1) / (V2-V1);
L = height(T1);
idx30 = find(diff(sign(Vnorm - 0.3)));
for k = 1:numel(idx30)
idxrng = max(1,idx30(k) : min(L,idx30(k)+1));
time30(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.3);
end
time30
time30 =
9.5839e-08
idx50 = find(diff(sign(Vnorm - 0.5)));
for k = 1:numel(idx50)
idxrng = max(1,idx50(k) : min(L,idx50(k)+1));
time50(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.5);
end
% time50
fprintf('\n\tT_2 = %10.4E s\n',time50(2))
T_2 = 5.9999E-05 s
idx90 = find(diff(sign(Vnorm - 0.9)));
for k = 1:numel(idx90)
idxrng = max(1,idx90(k) : min(L,idx90(k)+1));
time90(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.9);
end
time90
time90 = 1×2
1.0e+00 *
5.9968e-07 1.0689e-05
B = [time30 1; time90(1) 1] \ [0.3; 0.9];
fprintf('\n\tSlope = %10.4E\n\tIntercept = %10.4E\n',B)
Slope = 1.1908E+06
Intercept = 1.8587E-01
LineFit = [-B(2)/B(1) 1; (1-B(2))/B(1) 1] * B; % Line Limits
figure
plot(T1.Time, Vnorm)
hold on
plot(time30, 0.3, 'or', 'MarkerFaceColor','r')
plot(time90(1), 0.9, 'or', 'MarkerFaceColor','r')
plot([time30 time90(1)], LineFit, '-r')
plot([min(xlim) time50(2)], [1 1]*0.5, '-g')
plot([1 1]*time50(2), [0 0.5], '-g')
hold off
grid
xlabel('Time')
ylabel('Voltage')

.
Star Strider
on 10 Nov 2023
As always, my pleasure!
Tt ka
on 15 Nov 2023
Hello,
I would like to create a universal code for pulse signals with noise, so that a signal with noise would be filtered to work only with “clean data”. It should be also normalised like in the first case. For the filtering, I would like to use this function “wdenoise”.
The raw data I have just uploaded are with some noise. As a result, I would like to get a pulse signal without any noises.
The example is very similar to the previous one with the difference that it has a little noise and it should be filtered.
I have tried to write my own code, but it still not working. Maybe you have an idea?
Maybe it would be better to plot two signals: a filterd and an unfiltered just for a comparison.
Thank you beforhand for your help.
my code:
clear;
T1 = readtable('Versuch_n.txt');
T1.Properties.VariableNames = {'Time', 'Voltage'};
%%% Filtering
Mat = wdenoise([T1.Properties.VariableNames]);
[V1, V2] = bounds(Mat); % max.Voltage
Vnorm = (Mat-V1) / (V2-V1); % Normalising
figure
plot(T1.Time, Vnorm, '.-b');
xlabel('Time,s');
ylabel('Voltage, V');
title('Normalised Lightning Impulse');
grid
Star Strider
on 15 Nov 2023
The only change I would make is to change:
Mat = wdenoise([T1.Properties.VariableNames]);
to:
Mat = wdenoise(T1.Voltage);
because the firrst version will attempt to do wavelet denoising on a cell array of character vectors. That may actually work (I did not try it), however I doubt that it is the result that you want.
Try this —
T1 = readtable('Versuch_n.txt');
T1.Properties.VariableNames = {'Time', 'Voltage'};
%%% Filtering
Mat = wdenoise(T1.Voltage);
[V1, V2] = bounds(Mat); % max.Voltage
Vnorm = (Mat-V1) / (V2-V1); % Normalising
figure
plot(T1.Time, Vnorm, '.-b');
xlabel('Time,s');
ylabel('Voltage, V');
title('Normalised Lightning Impulse');
grid

However the signal is not noisy. so there is nothing much to be done here.
.
Tt ka
on 15 Nov 2023
Edited: Tt ka
on 15 Nov 2023
Thank you very much.
Interesting as it may seem, but this is a noisy signal indeed, you can see a small difirence between the previous one. But it's working correcly :) I got a filtered signal in the end.
Star Strider
on 15 Nov 2023
As always, my pleasure!
Tt ka
on 20 Nov 2023
Edited: Tt ka
on 22 Nov 2023
Hello,
my task ist to find the t_0 using a formula (see the picture 1). Also it should work for other different signals. For this coding we will use the same data like before like an example
According to your previous code, I could find the point O.
But to find the point t_0 it is not an easy task. The procedure would be like that I think:
1)Firstly, we need to find two points: A and B, which located by 30% and 90% respectively.
2) After that we need to build a line between these two points; But here we also need to take the times t(30%) and t(90%) into consideration. It is not so easy. I have tried to make a coding, but I do not know if it is correct.
3) The end of the line would be our point t_0 vertically (see the picture 1)
.
Star Strider
on 20 Nov 2023
You removed ‘Versuch.txt’ so I had to get it using websave.
Try this —
file = websave('Versuch','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1532232/Versuch.txt')
file = '/users/mss.system.UGH5zV/Versuch.txt'
T1 = readtable('Versuch.txt');
T1.Properties.VariableNames = {'Time','Voltage'}
T1 = 10000×2 table
Time Voltage
_________ _______
-1e-05 -50003
-9.99e-06 -50003
-9.98e-06 -50003
-9.97e-06 -50003
-9.96e-06 -50003
-9.95e-06 -50003
-9.94e-06 -50003
-9.93e-06 -50003
-9.92e-06 -50003
-9.91e-06 -50003
-9.9e-06 -50003
-9.89e-06 -50003
-9.88e-06 -50003
-9.87e-06 -50003
-9.86e-06 -50003
-9.85e-06 -50003
format shortE
[V1,V2] = bounds(T1.Voltage);
Vnorm = (T1.Voltage-V1) / (V2-V1);
L = height(T1);
nvolts = [0.3 0.9];
for k1 = 1:numel(nvolts)
idxvolts = find(diff(sign(Vnorm - nvolts(k1))));
for k2 = 1:numel(idxvolts)
idxrng = max(1,idxvolts(k2)-1 : min(L,idxvolts(k2)+1));
timev(k1,k2) = interp1(Vnorm(idxrng), T1.Time(idxrng), nvolts(k1));
end
end
timev = timev(:,1)
timev = 2×1
1.0e+00 *
9.5839e-08
5.9968e-07
time30 = timev(1)
time30 =
9.5839e-08
time90 = timev(2)
time90 =
5.9968e-07
% idx30 = find(diff(sign(Vnorm - 0.3)));
% for k = 1:numel(idx30)
% idxrng = max(1,idx30(k) : min(L,idx30(k)+1));
% time30(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.3);
% end
%
% time30
%
% % fprintf('\n\tT_2 = %10.4E s\n',time50(2))
%
% idx90 = find(diff(sign(Vnorm - 0.9)));
% for k = 1:numel(idx90)
% idxrng = max(1,idx90(k) : min(L,idx90(k)+1));
% time90(k) = interp1(Vnorm(idxrng), T1.Time(idxrng), 0.9);
% end
%
% time90
t_0 = time30 - 0.3/(0.9 - 0.3) * (time90 - time30) % Direct Calculation
t_0 =
-1.5608e-07
B = [time30 1; time90 1] \ [0.3; 0.9];
t_0_LR = -B(2)/B(1) % Linear Regression
t_0_LR =
-1.5608e-07
t_0_diff = t_0 - t_0_LR % Difference
t_0_diff =
2.6470e-23
fprintf('\n\tSlope = %10.4E\n\tIntercept = %10.4E\n',B)
Slope = 1.1908E+06
Intercept = 1.8587E-01
LineFit = [-B(2)/B(1) 1; (1-B(2))/B(1) 1] * B; % Line Limits
figure
plot(T1.Time, Vnorm)
hold on
plot(time30, 0.3, 'or', 'MarkerFaceColor','r')
plot(time90(1), 0.9, 'or', 'MarkerFaceColor','r')
plot([-B(2)/B(1) (1-B(2))/B(1)], LineFit, '-r')
plot([min(xlim) time30(1)], [1 1]*0.5, '-g')
plot([1 1]*time30(1), [0 0.5], '-g')
hold off
grid
xlabel('Time')
ylabel('Voltage')
text(t_0, 0, sprintf('t_0 = %11.3E\n\\downarrow',t_0), 'Horiz','left', 'Vert','bottom')

figure
plot(T1.Time, Vnorm)
hold on
plot(time30, 0.3, 'or', 'MarkerFaceColor','r')
plot(time90, 0.9, 'or', 'MarkerFaceColor','r')
plot([-B(2)/B(1) (1-B(2))/B(1)], LineFit, '-r')
plot([min(xlim) time30(1)], [1 1]*0.5, '-g')
plot([1 1]*time30, [0 0.5], '-g')
hold off
grid
xlabel('Time')
ylabel('Voltage')
xlim([-0.5 1.0]*1E-6)
text(t_0, 0, sprintf('t_0 = %11.3E\n\\downarrow',t_0), 'Horiz','left', 'Vert','bottom')
title('Zoomed To Show Detail')

.
Tt ka
on 21 Nov 2023
Edited: Tt ka
on 21 Nov 2023
This coding is working, but If I change my varibale name "timev" to another one, it gets me a false answer. All times get a 0. I can not figure it out, why it is so.
[V1,V2] = bounds(T1.Voltage);
Vnorm = (T1.Voltage-V1) / (V2-V1);
L = height(T1);
nvolts = [0.3 0.9];
for k1 = 1:numel(nvolts)
idxvolts = find(diff(sign(Vnorm - nvolts(k1))));
for k2 = 1:numel(idxvolts)
idxrng = max(1,idxvolts(k2)-1 : min(L,idxvolts(k2)+1));
timev(k1,k2) = interp1(Vnorm(idxrng), T1.Time(idxrng), nvolts(k1));
end
end
timev = timev(:,1)
time30 = timev(1)
time90 = timev(2)
t_0 = time30 - 0.3/(0.9 - 0.3) * (time90 - time30)
Star Strider
on 21 Nov 2023
I do not know what you changed or where you changed it in the code. (The code you quoted is the code I wrote.) You would have to change all references to your new name for ‘timev’ to match that change to my code.
Tt ka
on 21 Nov 2023
Edited: Tt ka
on 21 Nov 2023
"timev" is just a variable, right? I can rewrite it e.g. like time_voltage, and also change all variables to a new name, like:
nvolts = [0.3 0.9]; %
for k1 = numel(nvolts) %
idxvolts = find(diff(sign(Vnorm - nvolts(k1))));
for k2 = numel(idxvolts)
idxrng = max(1,idxvolts(k2)-1 : min(L,idxvolts(k2)+1));
time_voltage(k1,k2) = interp1(Vnorm(idxrng), T1.Time(idxrng), nvolts(k1)); % Interpolation
end
end
time30 = time_voltage(1)
time90 = time_voltage(2)
t_0 = time30 - 0.3/(0.9 - 0.3) * (time90 - time30) %
time30 =
0
time90 =
0
t_0 =
0
If I only change a variable name, I get different results. -_-
Star Strider
on 21 Nov 2023
You copied my code incorrectly.
Specifically, you changed:
for k1 = 1:numel(nvolts)
to:
for k1 = numel(nvolts) %
and that left ‘k1’ equalling 2 rather than iterating through ‘nvolts’ from 1 to 2, so the first column of ‘time_voltage’ is identically zero. (MATLAB backfills arrays with zeros if those positions are undefined. Run: ‘q(5) = 5’ to demonstrate this.)
So changing the variable name was not the problem. Not copying my code correctly was definitely the problem.
.
Star Strider
on 21 Nov 2023
As always, my pleasure!
Tt ka
on 21 Nov 2023
Could you please shortly explain this part:
I have a small problem to understand what a command "sign" exactly mean here.
find(diff(sign(Vnorm - nvolts(k1))));
and:
max(1,idxvolts(k2)-1 : min(L,idxvolts(k2)+1));
- why do we use here "-1" and "+1" ?
- what does the symbol ":" mean between "max" and "min" ?
Thank you beforehand
Star Strider
on 21 Nov 2023
The first assignment returns the approximate indices of where ‘Vnorm’ equals ‘nvolts(k1)’. That will change sign at that point, and the sign call converts it into a vector of either [-1 0 +1]. That makes it easier to find the transition.
The second creates the ‘idxrng’ vector, and spans the region between each ‘idxvolts’ element ±1, creating an index vector range to interpolate over.
Star Strider
on 21 Nov 2023
As always, my pleasure!
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

