I am trying to find the full width at half max value and plot the waveform with markers

7 views (last 30 days)
I have a voltage waveforn captured using an osciloscope and saved in a csv file. I am trying to find the full width at half max value and plot the waveform with markers. Column 4 is the time (x axis) and column 5 is the voltage data (y axis) in the csv file. Can someone please help me?
Thanks

Accepted Answer

Star Strider
Star Strider on 27 Aug 2021
Explore the options of the Signal Processing Toolboox pulsewidth function.
.
  6 Comments
BP
BP on 1 Sep 2021
This has been a great help. I am new to MATLAB. Please explane what the following steps / commands in the code does. A line by line explanation would really help me.
[ymx,idx] = findpeaks(y, 'MinPeakProminence',100)
ymx = 923.1334
idx = 1028
hafmax = ymx*0.5;
for k = 1:numel(hafmax)
idxrng1 = find(y(1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
Star Strider
Star Strider on 1 Sep 2021
Sure!
The first is just a findpeaks call. I refer you to that documentationo to understand what it does. It returns the maximum peak and the associated index into that vector for reference later.
The ‘hafmax’ variable is just that — it is the value at half the maximum (although it can be value defined on the dependent variable range, depending on what you want to do).
The loop is a bit mor complicated. To use the interp1 function correctly, the independent variable (first argument to the function) has to be monotonically increasing or decreasing. Since the objective is to find the values for both the ascending and descending limbs of the curve, the code requires a separate interp1 call for each limb as the result. That explains the two ‘idxrng’ calls, one for each section of the curve, and a separate interp1 call for each section of the curve, producing two values of ‘xm’ correspondingly. The easiest way to understand how it works is to add a plot statement to the loop to display the different sections being interpolated.
.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!