How to get a smooth plot by filtering the sudden variation of the data?

I calculated the numerical derivative of my data as a function of time to get the speed. I got a noisy curve. Then I took the Fourier transform of the velocity data and filtered it to remove the sudden variations and smoothen it. The filtered data is not matching with the unfiltered data. Can anybody help me to solve this issue?
clear;
A = readmatrix('t-v.xlsx');
t = A(:,1);
v = A(:,2);
vfreq=fft(v);
vfreq1=fftshift(vfreq);
vfreq2=vfreq1;
for k=1:485
vfreq2(k)=0;
end
for k=515:size(vfreq1,1)
vfreq2(k)=0;
end
vfreq2=ifftshift(vfreq2);
dvxfilt=ifft(vfreq2);
plot(t/1e-9,dvxfilt);
xlabel('t (ns)')
ylabel('v')
xlim([0 100]);

Answers (1)

It recovers a big tail part of the signal. Hard to guess what should be the signal at the begining.
A=readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321095/t-v.xlsx');
x=A(:,1);
A=A(:,2);
B=flip(unwrap(flip(A)*10)/10);
plot(x,A,"g")
hold on
plot(x,B,'r','LineWidth',2)

3 Comments

@Bruno Luong Dear Bruno Luong, thank you so much for your suggestion. The idea is really good. Can you have close look at the data between 0.08 to 0.22 ( x e-7). The smooth data plot is not fitting with the unfiltered data. Actually I am trying to calculate the speed difference of my systems objects. For that, I calculated the numerical derivative of my data as a function of time. Is there any better way to do it?
clear;
A = readmatrix('t-x.xlsx');
t=A(:,1);
x1=A(:,2);
x2=A(:,3);
for i=1:size(A)
dvx(i)=0;
end
for i=2:size(A)-1
vx1(i)=(x1(i+1)-x1(i-1))/(t(i+1)-t(i-1));
vx2(i)=(x2(i+1)-x2(i-1))/(t(i+1)-t(i-1));
dvx(i)=vx1(i)-vx2(i);
end
plot(t,dvx)
IMO your data are too corrupted to hope to recover reliable. You have to take the idea and push to the limit. I don't have time (and desire) to analyse your data.
There are several post about taking derivative, I recommend you to search and take a look in the archive, for example here
@Bruno Luong These fluctuations are mainly due to my system behaviour. We verified the data. The position functions are varying smoothly.

Sign in to comment.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Products

Release

R2020b

Asked:

on 11 Mar 2023

Commented:

on 11 Mar 2023

Community Treasure Hunt

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

Start Hunting!