FFT frequency does not correspond to my sensor frequency
1 view (last 30 days)
Show older comments
Hello,
I'm trying to use matlab in order to retrieve the tremor fundamental frequency of a IMU sensor.
I use FFT and PSD to get my funcdamental frequency.
To perform measurements, i calibrated a 3D printer stepper motor. It manage to create rotational vibration around the Z axis of the IMU at a 2.01Hz. However, when i process the data into matlab, i retrieve a 1.3Hz fundamental frequency...
I don't know if my sensor values are incorrect or if my processing is incorrect.
Something to know : my signal is triangle waves due to the stepper motor.
Please find here the matlab code and a sample of data as attachment.
MATLAB :
if true
%import csv file
M = csvread('3.csv');
%select the gx column
gx = M(:,1);
%select the gy column
gy = M(:,2);
%select the gz column
gz = M(:,3);
%size of M (same size for each column)
s = size(gx, 1);
%because of loop, need s/2
s2 = fix(s/2);
% computes the fast fourier transform of M for gx
Ygx = fft(gx, s);
% computes the fast fourier transform of M for gy
Ygy = fft(gy, s);
% computes the fast fourier transform of M for gz
Ygz = fft(gz, s);
%Compute the power spectral density for gx
PSDYgx = Ygx.*conj(Ygx)/s;
%Compute the power spectral density for gy
PSDYgy = Ygy.*conj(Ygy)/s;
%Compute the power spectral density for gz
PSDYgz = Ygz.*conj(Ygz)/s;
%acquisition frequency
Hz = 30;
%calculate X axis (frequency)
f = Hz/s*(0:s2);
%find peaks of the frequency sampl1e for gx
[pksgx,locsgx] = findpeaks(PSDYgx(1:s2+1), 'SortStr', 'descend', 'NPeaks', 1);
%find peaks of the frequency sample for gy
[pksgy,locsgy] = findpeaks(PSDYgy(1:s2+1), 'SortStr', 'descend', 'NPeaks', 1);
%find peaks of the frequency sample for gz
[pksgz,locsgz] = findpeaks(PSDYgz(1:s2+1), 'SortStr', 'descend', 'NPeaks', 1);
figure
color = {'b', 'k', 'r'};
PSDYg = {PSDYgx(1:s2+1), PSDYgy(1:s2+1), PSDYgz(1:s2+1)};
pksg = {pksgx, pksgy, pksgz};
locsg = {locsgx, locsgy, locsgz};
linevgxx = [f(locsgx), f(locsgx)];
linevgxy = [pksgx, 0];
linehgxx = [0, f(locsgx)];
linehgxy = [pksgx, pksgx];
linevgyx = [f(locsgy), f(locsgy)];
linevgyy = [pksgy, 0];
linehgyx = [0, f(locsgy)];
linehgyy = [pksgy, pksgy];
linevgzx = [f(locsgz), f(locsgz)];
linevgzy = [pksgz, 0];
linehgzx = [0, f(locsgz)];
linehgzy = [pksgz, pksgz];
linevgx = {linevgxx, linevgyx, linevgzx};
linevgy = {linevgxy, linevgyy, linevgzy};
linehgx = {linehgxx, linehgyx, linehgzx};
linehgy = {linehgxy, linehgyy, linehgzy};
for i = 1:3
hold on
plot(f, PSDYg{i}, 'Color', color{i})
plot(f(locsg{i}), pksg{i}, 'Color', color{i}, 'MarkerFaceColor', color{i}, 'Marker' , 'v')
plot(linevgx{i}, linevgy{i}, color{i})
plot(linehgx{i}, linehgy{i}, color{i})
str = sprintf('%0.3e', f(locsg{i}));
str2 = strcat(num2str(str), ' Hz');
h = text(f(locsg{i}), -0.1 ,str2);
set(h, 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top', 'Color', color{i});
str = sprintf('%0.3e', pksg{i});
str2 = strcat(num2str(str), ' g²/Hz');
h = text(-0.5, pksg{i}, str2);
set(h, 'HorizontalAlignment', 'right', 'color', color{i});
end
title('Power Spcetral Density for gyroscope')
xlabel('Frequency (Hz)')
ylabel('Power (g²/Hz)')
hold off
end
Thanks for your help !
0 Comments
Answers (0)
See Also
Categories
Find more on AI for Signals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!