How can I resample the acceleration signal?

9 views (last 30 days)
I have a acceleration signal as shown below.
Now I need to process this signal by resampling it at 50 Hz. How can I do it?
Your suggestions will be very valuable.
Thanks.
  1 Comment
Walter Roberson
Walter Roberson on 10 Aug 2016
This is not at all clear as to how the various components relate to each other. What is the duration of each of the entries? Does the 6,25Hz mean that that signal should be assumed to be an impulse that lasted 1/(6.25) of a second and the next line should be assumed to start immediately after that? Is your data essentially a non-uniform Discrete Fourier Transform problem made up of a sequence of impulses?

Sign in to comment.

Accepted Answer

John BG
John BG on 11 Aug 2016
Edited: John BG on 11 Aug 2016
Hi Bijay
I passed your image through the OCR and obtained the attached text file data2.txt there may be a few differing numbers because a few numbers turned characters after scanning, and brought back directly replacing them with best guess.
So, let's crack on, shall we?
% manually removed '|' before using textscan
format long;
f2=fopen('data2.txt');
% A=textscan(f1,'%f %f %f %f','Delimiter','|');
A = textscan(f2,'%s %s %s %s');
fclose(f2);
L=length(A{:,1});
x=zeros(1,L);for k=1:1:L x(k)=str2num(cell2mat(A{1}(k))); end;
y=zeros(1,L);for k=1:1:L y(k)=str2num(cell2mat(A{2}(k))); end;
z=zeros(1,L);for k=1:1:L z(k)=str2num(cell2mat(A{3}(k))); end;
f=zeros(1,L); % the 'Hz' has to be removed before converting to double and ',' to '.'
for k=1:1:L
f_str=cell2mat(A{4}(k));
f_str(f_str=='H')=[];f_str(f_str=='z')=[];f_str(f_str==',')='.';
f(k)=str2num(f_str);
end;
T=1./f; % the time base needed to resample
% the 1st 30 samples of vectors x y z have time intervals of 160ms between
% adjacent samples, while 31st sample to end of sample have 20ms between
% adjacent samples.
% This means you only have to resample between the 1st initial 30 samples.
% the interpolation factor is
Q=T(1)/T(31);
x2=x(1:30);y2=y(1:30);z2=z(1:30);
% you may want to leave it with added zeros between samples
x2_interp=zeros(1,30*Q);x2_interp([1:Q:end])=x2;
% or linearly interpolate between samples
x2_interp2=x2_interp;
for k=1:1:29
x_lin=linspace(x2(k),x2(k+1),Q+1);
x2_interp2([(k-1)*Q+2:1:Q*k])=x_lin([2:end-1]);
end
y2_interp=zeros(1,30*Q);y2_interp([1:Q:end])=y2;
y2_interp2=y2_interp;
for k=1:1:29
y_lin=linspace(y2(k),y2(k+1),Q+1);
y2_interp2([(k-1)*Q+2:1:Q*k])=y_lin([2:end-1]);
end
z2_interp=zeros(1,30*Q);z2_interp([1:Q:end])=z2;
z2_interp2=z2_interp;
for k=1:1:29
z_lin=linspace(z2(k),z2(k+1),Q+1);
z2_interp2([(k-1)*Q+2:1:Q*k])=z_lin([2:end-1]);
end
f2_interp=zeros(1,30*Q);
f2_interp([1:Q:end])=f2;
f2_interp2=f2_interp;
for k=1:1:29
f_lin=linspace(f2(k),f2(k+1),Q+1);
f2_interp2([(k-1)*Q+2:1:Q*k])=f_lin([2:end-1]);
end
% split x y z and remove the 1st part with slower sampling rates
x([1:30])=[];
y([1:30])=[];
z([1:30])=[];
f([1:30])=[];
% and assemble x2 y2 z2 to the 2nd parts of x y z with faster sampling rate
x=[x2_interp2 x];
y=[y2_interp2 y];
z=[z2_interp2 z];
f=[f2_interp2 f];
Please note that the acceleration would be the 2nd derivative of x, y, and z respect time, you already have the time reference with regular interval in
T=1./f
So if you really want the acceleration you have to apply
diff(diff())
to x y and z
Bijay would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
  1 Comment
Bijay Ratna Shakya
Bijay Ratna Shakya on 19 Aug 2016
Dear John, Thank you very much foe the support. It was of great help.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!