Convert striaght lines to smooth curves

Hi, I have acceleration and time data and want to create a phase diagram (displacement vs velocity).
My current plot looks like below fig 1, with straight lines connecting each point. Is it possible to change these to smooth curves as fig 2?
fig 1
fig 2
My current code is as below.
v = diff(Acc1).*diff(X_Value); %Acc1 = acceleration data and X_Value = Time
s = diff(v).*diff(X_Value(1:end-1));
figure
plot(s,v(1:end-1))

 Accepted Answer

It looks like your sample rate was too low. I'd recollect the data at a higher sample rate.
You could try doing a cubic spline interpolation on your acceleration data to estimate intermediate time points and then rerun your code.
dt = mean(diff(X_value));
t_hiRes = 0:dt/100:max(X_value);
hiresAccel1 = interp1(X_value, Acc1, t_hirRes,'cubic');
%Same for the rest
v = diff(Acc1).*diff(X_Value); %Acc1 = acceleration data and X_Value = Time
s = diff(v).*diff(X_Value(1:end-1));
figure
plot(s,v(1:end-1))

4 Comments

Thank you Michael, my sampling rate was 20k collected over 6 seconds, I hope it was sufficient sampling rate. I have attached the collected data for reference. I would appreciate if you could take a look at it.
If you'd like to upload a .mat file I can take a look, but I really don't need to. After looking more closely at your code, I am confused about what you are doing. You are taking derivatives of acceleration, which will give you the jerk. You have acceleration and you are trying to plot velocity vs position.You need to integrae acceleration. If you are still seeing sharp edges in the phase plot, it likely means the sample rate was too low. For a plot like this, your sample rate thought be at least 10x the maximum frequency content you expect in the signal. Ideally it would be closer to 50-100x.
v = cumtrapz(X_val, Acc1);
s = cumtrapz(X_val, v);
figure;
plot(s,v)
@Pranav Shende Did this fix your problem?
Thanks for your help Micheal, I understand using 'diff' comes out confusing to find velocity from acceleration. I have tried using trapz and cumtrapz for my data. The problem I faced is all the values (velocty and displacement) increases/decreases with time. I believe it should follow the same trend as accleration if plotted against time as my sensors are attached to the rig fixed on a table. Ideally as below figure. I think as you mentioned the sampling frequency is too low for my data. I will be using a higher sampling frequency and try again. Or else I am missing something fundamental and need to go back to basics.

Sign in to comment.

More Answers (1)

Why in the name of god and little green apples are you differentiating acceleration? You need to INTEGRATE acceleration, once to get velocity, then again to get displacement.
Differentiating acceleration results in noisy garbage, as it probably should. You differentiated the accelerations TWICE.
data = xlsread('starved_1000_001.lvm.xlsx');
T = data(:,1);
Acc = data(:,2);
vel = cumtrapz(T,Acc);
displacement = cumtrapz(T,vel);
plot(vel,displacement,'-')

3 Comments

Thanks for your advice John. I understand what I have done is fundamentally wrong. I have some concerns with the output after using cumtrapz for my data as I have mentioned in the above comment. Since my sensors are attached to the rig, I was expecting the displacement values to oscillate along neutral x-axis (time) and not increase or decrease.
@Pranav Shende This might be due a DC bias in your accel measurement. This can happen if you have a bit of gravity measured in the axis of the accel. Try doing
a = a_raw - mean(a_raw)
to eliminate the bias. Also, be sure to accept the answer.
@Michael Sure, will try that too. Thanks.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!