# How do I plot the FFT of signal from accelerometer

조회 수: 17(최근 30일)
Harrison Osasogie Edokpolor 2022년 8월 6일
댓글: William Rose 2022년 8월 7일
The Sample rate of the accelerometer from the arduino IDE was 833Hz and I placed the accelerometer on a shaker, The shaker has an input frequency of 200Hz and amplitude of 3Vpp in 13s. The data generated was recorded in .CSV as attached.
Can anyone help with the FFT code using either the X-axis(First column) or Y-axis data(Second column) ?

댓글을 달려면 로그인하십시오.

### 답변(2개)

William Rose 2022년 8월 6일
Sampling rate is fs=833 Hz and there are N=1110 samples. (I deleted line 1 since it has only one number.)
When you do the FFT, you get a vector of N complex numbers. The first N/2+1 of those numbers correspond to frequencies 0:df:Fs/2, where df=fs/N.
Plot the amplitudes of the first N/2+1 elements of the FFT, versus the frequecies as described above.
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
William Rose 2022년 8월 7일
The script I posted in the comment below computes the FFT of all three components. It also plots all three components.

댓글을 달려면 로그인하십시오.

William Rose 2022년 8월 6일
Try the code below. It makes the figure below. The figure shows that the oscullaiton frequency was not exactly 200 Hz. Or the sampling rate was not really 833 Hz.
Good luck.
##### 댓글 수: 1표시숨기기 없음
William Rose 2022년 8월 7일
I forgot to include a legend. I recommend adding the line
legend('ax','ay','az');
to the script, after each of the two plot commands.
If the sampling rate is 1000 Hz, rather than 833 as you said in the original post, then the two large peaks in the spectrum occur at 200 and 400 Hz, consistent with your statement that the shaker was shaking at 200 Hz. See figure below, in which I changed fs to 1000 in the script. I also added the legend() statements. 댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!