Realization of Acceleration Frequency Domain Integration and Its Limitation Analysis

For notes only, reproduced from

(14 messages) The realization of acceleration frequency domain integration and its limitations

 

First of all, I believe that everyone has tried to obtain the displacement directly in the time domain through the integration of the acceleration sensor. When the accuracy of the acceleration is not high or the acceleration data is not processed, the displacement obtained by the integration will always have a cumulative error, and it will become larger and larger. At this time, some people will turn their attention to the frequency domain. What happens when the acceleration is integrated in the frequency domain? Will there be unexpected effects?

What is frequency domain integration

The points obtained by the single-chip microcomputer or sensor sampling are all discrete, and in the time domain, the integration of the discrete points is the summation.

The frequency domain integration needs to transfer the time domain array to the frequency domain through fast Fourier transform (FFT), and then through the integration property of Fourier transform, after realizing integration and filtering in the frequency domain, return to the time domain through IFFT inverse Fourier transform, and the array obtained at this time is the integration result of the time domain array. The principle of Fourier transform will not be repeated here. The general function is to decompose a signal waveform in the time domain into the superposition of several single-frequency signals. In layman’s terms, it is to approximate the waveform of the original signal through the superposition of infinitely many sine waves with different amplitudes and frequencies, and the spectrum obtained by Fourier transform is the amplitude corresponding to these different frequency sine waves. Here are two animations for easy understanding.

The integration in the frequency domain requires the use of the integral properties of the Fourier transform:

one point

quadratic integral

These two formulas put the time-domain integration into the frequency domain, and remove the integral sign, which looks more complicated. In fact, it is relatively simple if you look at it from one variable to the other.

How to implement frequency domain integration

Using a programming language to describe the integral properties of the Fourier transform may seem complicated, but in fact it is only necessary to find out each item of the formula separately.

The following steps refer to the fifth chapter of frequency domain integration in "Application of Matlab in Vibration Signal Processing" (Wang Ji).

1. Get time domain array

 Assuming that the sampling frequency sf of the acceleration is 1kHz, it is necessary to collect data for a period of time to obtain a time-domain array. For the convenience of FFT calculation, nfft takes a power of 2 sampling points such as 1024 points;

2. Calculate the FFT 

Perform FFT fast Fourier transform on these 1024 points to obtain the frequency spectrum, which is F(ω) in the above formula. After taking the modulo length of F(ω), we will find that the graph is symmetrical about 500Hz (the first point is F(0), asymmetrical), as shown in the figure:  

3. Calculate the ω array

 To obtain the ω array, you first need to calculate the frequency interval df, because the sampling frequency sf rate is 1000Hz, and the length of the entire array is 1024, so df=sf/nff, the unit (Hz/s), by calculating df, the time points sampled in the time domain and the frequency points in the frequency domain are one-to-one. To put it bluntly, the time interval of sampling points in the time domain is 1/1000Hz=1ms, and the frequency interval in the frequency domain is 1000/1024= 0.977Hz, the interval between each value of the spectrum obtained by our FFT is 0.977Hz, and 1024 points correspond to 0~1000Hz. The ω array is also symmetric (or centrosymmetric) and divided into positive and negative discrete circular frequency vectors. First convert the frequency interval df just obtained into an angular frequency interval dω, dω=2π*df. The calculation formula of ω array is as follows, where n is the number of integrations:

 

 The ω array of the first integration and the ω array of the second integration are shown in the figure:

 

4. Imaginary number j

After getting the ω array, it is time to process j, j is a unit imaginary number, and the square of j is -1. In the integral formula, F(ω) except a j, and j represents the phase shift in the frequency domain, every time a j is multiplied, it rotates 90 degrees counterclockwise, and every time a j is divided, it rotates 90 degrees clockwise. That is to say, the first integration in the time domain needs to be rotated 90 degrees clockwise after being transferred to the frequency domain, and the second integration needs to be rotated 180 degrees clockwise.

5. Frequency domain transformation for integration 

 The frequency domain transformation is the result of FFT in the second step (that is, 1024 complex numbers) divided by the ω array in turn.

6. Phase transformation for integration 

 Step 4 mentions that the primary integral is rotated 90 degrees clockwise and the secondary integral is rotated 180 degrees clockwise. Phase transformation is to rotate each complex number of the complex number array obtained in step 5. Assume that the real part is real and the imaginary part is imag. In one integration, the imaginary part is equal to the real part imag=real, and the real part is equal to the negative imaginary part real=-imag; in the second integration, the real part is equal to the negative real part real=-real, and the imaginary part is equal to the negative imaginary part imag=-imag.

7. Filtering

 At this point, if you skip to step 8 without filtering, you can get the result of the second integration in the time domain. If you want to filter out the low-frequency and high-frequency parts, you can directly set the first few complex numbers and the last few complex numbers in the complex number array obtained in step 6 to zero. Suppose you need to filter out the part below Fmin=10Hz, first calculate which point ni=Fim/df+1, 10/0.977+1≈11 at 10Hz, that is, set the first 11 complex numbers in the complex number array obtained in step 6 to 0, and the same is true for filtering high frequencies.

Supplement: The above method actually uses a rectangular window function. If you want to achieve different filtering effects, you can consider other window functions such as Hanning window, Hamming window, Gauss window, etc.

8. IFFT back to time domain

 Finally, the processed complex array is converted back to the time domain by IFFT to obtain the integration result.

clear;
clc;
close all hidden;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fno = 'output.txt';
fid = fopen('1.txt','r');
x = fscanf(fid,'%f',[1,inf]);
status = fclose(fid);
 
sf = 1000;            %采样频率
fmin = 1;           %最小截止频率
fmax = 200;           %最大截止频率
c = 9810.5;           %单位变换系数
it = 2;               %积分次数
 
sx = '时间';          %横坐标标注
sy1 = 'y1';           %纵坐标标注
sy2 = 'y2';           %纵坐标标注
 
n=length(x);                    %待分析数组长度
t=0:1/sf:(n-1)/sf;              %建立时间向量
nfft=2^nextpow2(n);             %大于并接近n的2的幂次方的FFT长度
y=fft(x,nfft);                  %FFT变换
 
df=sf/nfft;                     %计算频率间隔(Hz/s)
ni=round(fmin/df+0.5);          %高通频率截止点=最小截止频率/时间步长t+1
na=round(fmax/df+0.5);          %低通频率截止点=最大截止频率/时间步长t+1
dw=2*pi*df;                     %圆频率间隔(rad/s)
w1=0:dw:2*pi*(0.5*sf-df);       %正离散圆频率向量
w2=-2*pi*(0.5*sf-df):dw:-dw;    %负离散圆频率向量
w=[w1,w2];                      %连接w1,w2
w=w.^it;                        %以积分次数为指数,建立圆频率变量向量
subplot(2,2,2);
plot(abs(y));
 
a=zeros(1,nfft);                %进行积分的频域变换
a(2:nfft-1)=y(2:nfft-1)./w(2:nfft-1);
subplot(2,2,4);                 %绘制积分前的时程曲线图形
plot(abs(a));
 
if it==2
    y=-a;                       %进行二次积分的相位变换
else
    y = imag(a) - 1i*real(a);   %进行一次积分的相位变换
end
 
a=zeros(1,na);                  
a(ni:na)=y(ni:na);              %消除指定正频带外的频率成分
a(nfft-na+1:nfft-ni+1)=y(nfft-na+1:nfft-ni+1);%消除指定负频带外的频率成分
 
y=ifft(a,nfft);                 %IFFT变换
y=real(y(1:n))*c;               %取逆变换的实部n个元素并乘以单位变换系数为积分结果
subplot(2,2,1);                 %绘制积分前的时程曲线图形
plot(t,x);
xlabel('时间(s)');
ylabel('加速度(g)');
grid on;
subplot(2,2,3);                 %绘制积分前的时程曲线图形
plot(t,y);
xlabel('时间(s)');
if it==2
    ylabel('距离(m)');
else
    ylabel('速度(m/s)');
end
grid on;
fid=fopen(fno,'w');             %输出积分后的数据
for k=1:n
	fprintf(fid,'%f/n',y(k));
end
status=fclose(fid);

Attach the MATLAB code, C language code click the link below

C Language Algorithm of Acceleration Frequency Domain Quadratic Integral Vibration Displacement Based on STM32F4

Implementation of acceleration frequency domain integration based on STM32F407 and JY901 modules (complete project)

limitation

However, the above calculation idea is limited to the displacement calculation of vibration, that is to say, the total displacement is 0. When the total displacement is not 0, our integral result will eventually be equal to 0. Let's take a look at the simulation results

Figure 1 is the original data, Figure 3 is the integration of Figure 1, and the integration result is not 0. Figure 2 is the waveform of IFFT after removing the lowest frequency signal (that is, the DC part) after FFT. It can be seen that the entire graph is shifted downward for a certain distance. Figure 4 is the integration result of Figure 2, which is finally 0, which is seriously inconsistent with the actual integration result. Because according to the Fourier transform formula when ω=0, it can be seen that F(0) itself is equal to the integral of the time domain graph, and it is directly set to 0 when filtering low frequencies, and the final integral result is of course 0, which means that the above frequency domain integration is only applicable to the case where the total integral is 0.

If the DC component is filtered out, the final integral is 0, and if the DC component is not filtered out, the cumulative error after acceleration integration cannot be eliminated, so they are contradictory. So frequency domain integration is not suitable for acceleration integration where the total displacement is not zero.

non-zero displacement

关于非零位移的问题,首先我们要清楚加速度计累积误差的来源,加速度计都带有一定的线性偏移,即需要通过kx+b的方法进行校正,而其中的b正是引起加速度积分累积误差的罪魁祸首,因此需要对加速度进行线性补偿,可通过Matlab中的lsqcurvefit,非线性拟合文中提到的方法确定k和b,如果在要求不是很严格的场合,只需要对b进行补偿即可,方法是在确定系统处于静止状态时(通过其他方式确定的系统状态),首先令速度为零,然后将一段时间内的加速度取平均即可作为补偿值b,每隔适当时间校正一次b这样就能保证速度基本无累积误差,然后用同样的方法计算位移。

However, the above method still has relatively large errors, and the accelerometer alone obviously cannot accurately obtain the displacement, so other sensors need to be added. For a system that moves on a plane, it is recommended to add GPS. If it is a system that moves in a vertical direction, a barometer can be added, and then the two sets of data are fused through Kalman filtering to obtain more accurate displacement, velocity and acceleration. For specific methods, please refer to this blog post: Calculation of acceleration, velocity and height by second-order Kalman filter

Guess you like

Origin blog.csdn.net/m0_38012497/article/details/128529761