Smart questions
Smart people
 Find A ForumFind An Expert
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Remember Me

Are you an
Engineering professional?
Join Eng-Tips now!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Just copy and paste the

#### Feedback

"...I signed up to your site to get help with a problem and I am so glad I did. I found the help I needed immediately. Thanks to all who contribute to your site..."

#### Geography

Where in the world do Eng-Tips members come from?

# Acceleration to Displacement - Filtering Issue

 Forum Search FAQs Links Jobs Whitepapers MVPs
 sanchezb (Civil/Environmental) 8 Jun 12 15:38
I am using fast fourier transforms to convert raw acceleration to displacement. I am able to get extremely close to expected results; however, I am having issues at the beginning of the dataset. I believe there may be an issue with the filter I am using.

Here is the code for the butterworth filter I am using

#### CODE --> Matlab

[B,A] = butter(5,0.5/(Fs/2),'high');

I apply it to the raw data and after conversion.

Here are the results, I move the device +/- 10cm, +/- 7.5cm, and +/- 5cm as seen. The green line represents actual movement and the blue line represents the dataset produced through the conversion algorithm.

Any suggestions for better filtering techniques? I can provide the code and some data upon request.
 sanchezb (Civil/Environmental) 8 Jun 12 15:43
Here is the code

#### CODE --> Matlab

clear clc home load ACCfilter load ElapsedTime %definitions Fs = 32; t = ElapsedTime; % sampling range yno = ACCfilter; [B,A] = butter(5,0.5/(Fs/2),'high'); y = filter(B,A,yno); %plot in time domain subplot(2, 1, 1); % plot(t, y,'r'); grid on % plot with grid title('Acceleration vs Time') xlabel('Time (s)'); % time expressed in seconds hold on plot(t,yno,'g') %FFT section Y = fft(y); % compute Fourier transform enter n = length(y); % Amp = abs(Y )/n; % absolute value and normalize %if n is even the fft will be symmetric %the first n/2 + 1 points will be unique and the rest are symmetrically %redundant. Point 1 is the DC component. Point n/2 +1 is the nyquist %component %1 2 3 4 5 6 7 8 %4 3 2 1 0 -1 -2 -3 % if n is odd the nyquist component is not evaluated. The number of unique % points is (n+1)/2 %1 2 3 4 5 6 7 8 9 %5 4 3 2 1 -1 -2 -3 -4 %create the frequency axis NumUniquePts=ceil((n+1)/2); % the positive frequencies freq=(0:NumUniquePts-1)*Fs/(n-1); %mirror the positive frequencies but make them negative then adjust some things %to look right freq2= -1*freq(end:-1:1); if mod (n,2)==0 freq2(1)=[]; end freq3=[freq, freq2]; freq3'; size(freq3); if mod(n,2)==1 freq3(n+1)=[]; end if mod(n,2)==0 freq3(n)=[]; end %store freq3 in a column freq3c = freq3'; %plot acceleration in frequency domain subplot(2, 1, 2); plot(freq, Amp(1 : NumUniquePts),'b.'); grid on % plot amplitude spectrum enter xlabel('Frequency (Hz)'); % 1 Herz = number of cycles per second enter ylabel('Acceleration Amplitude'); % amplitude as function of frequency enter %Omega Arithmetic to convert acceleration to velocity %uses complete frequency vector from above V=Y./(2*pi*freq3c*1i); %result=[freq3',Y',G'] %use this line to look at freq3, Y, and G next to each other % Get rid of infinities resulting from divisions by zero to prepare for % ifft V(1)=[1]; if mod(n,2)==0 V(n)=[1]; end %go back to time domain with the velocity inversedVno=ifft(V); [B,A] = butter(5,0.5/(Fs/2),'high'); inversedV = filter(B,A,inversedVno); figure plot(t,real(inversedV),'b') hold on title('Velocity vs Time'); % amplitude as function of time xlabel('Time (s)'); % time expressed in seconds ylabel('FFT Velocity'); % FsdirV=100; %sampling rate % dtdirV = 1/Fs; % % etdirV = 3; % end of the interval % tdirV = 0 : dt : et; % sampling range % ydirV = -cos(4*pi*t)/(2*pi);% define the signal % plot(t,ydirV,'g') %Omega Arithmetic to convert velocity to displacement D=V./(2*pi*freq3c*1i); % Get rid of infinities resulting from divisions by zero to prepare for % ifft D(1)=[1]; if mod(n,2)==0 D(n)=[1]; end %go back to time domain with the displacement inversedDno=ifft(D); [B,A] = butter(5,0.5/(Fs/2),'high'); inversedD = filter(B,A,inversedDno);
 IRstuff (Aerospace) 8 Jun 12 15:59
 FeX32 (Mechanical) 8 Jun 12 17:04
 Yes never double post!!!!Whenever you use a high-pass filter there will be some magnitude and phase warp. The warp or "lag" is frequency dependent. Consequently, the estimated displacement is just that, an estimate. You can predict how different the actual from estimated will be by several methods. Firstly, look at a bode plot of the filter input-outputs. It is evident from your pic that this is what is happening. First easy thing to try is increase the cutt-off frequency of your butterworth filter. Fe (IronX32)
 btrueblood (Mechanical) 8 Jun 12 18:54
 Your accel data is not very well windowed, i.e. it starts at a non-zero value and instantaneously reaches a very high level. The FFT as a result is giving you some weird harmonics (aliasing? not the right term, but like that) near the start.
 GregLocock (Automotive) 9 Jun 12 2:37
 You could try integrating in the time domain. I'll have a look at your code if you post a zip with ACCfilter and ElapsedTime in it. CheersGreg LocockNew here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?
 FeX32 (Mechanical) 9 Jun 12 17:14
 Hmm, or filtering in the frequency domain? Fe (IronX32)
 IRstuff (Aerospace) 10 Jun 12 0:52
 I ask again, what did you expect, and why do you think this is wrong? TTFNFAQ731-376: Eng-Tips.com Forum Policieshttp://tinyurl.com/7ofakss" border="0" alt="" />
 MikeyP (Aerospace) 10 Jun 12 7:51
 You could try running the signal through the filter twice - once forward and once backward - to remove filter phase effects. Also you should check that you are doing the transforms correctly: a useful check is to see if you have any imaginary part in your final result (you may see some imag part down at machine precision level - that is OK - but anything significant means you have gone wrong somewhere).M --Dr Michael F Platten
 hacksaw (Mechanical) 11 Jun 12 16:51
 why do you feel it necessary to use a high pass filter on accelerometer data?agree with gL, a low pass filter might be more suited to your problem
 FeX32 (Mechanical) 11 Jun 12 17:07
 I didn't even notice it was high-pass! For sure that is one of the problems... Fe (IronX32)
 MikeyP (Aerospace) 11 Jun 12 17:56
 You high pass filter when doing this sort of thing to avoid drift problems when you integrate. Just removing the DC isn't usually enough.TaM --Dr Michael F Platten
 FeX32 (Mechanical) 11 Jun 12 19:04
 What about a band-pass? Seems appropriate. Fe (IronX32)
 sanchezb (Civil/Environmental) 11 Jun 12 19:47
 I'll try a bandpass

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!