FFT for the given data to find the dominant frequency

129 vues (au cours des 30 derniers jours)
Naveen K S
Naveen K S le 3 Mai 2019
Commenté : Star Strider le 3 Juin 2022
hello everyone,
I have a data file containing a variable called "Lift coefficient" collected over a period of 1.25 seconds with time steps of 1e-5. I am performing the FFT but i'm not getting the desirable result. I am using the following code. Please find the data file also. Thankyou in advance
x=Cl;
plot(t,x)
t=VarName1;
y=fft(x);
f = (0:length(y)-1)*(10000)/length(y);
plot(f,abs(y))

Réponse acceptée

Star Strider
Star Strider le 3 Mai 2019
Modifié(e) : Star Strider le 3 Mai 2019
Try this:
[D,S] = xlsread('forcecoefficients1.xlsx');
t = D(:,1);
Cl = D(:,2);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
L = numel(t);
Clm = Cl-mean(Cl); % Subtract Mean (Mean = 0 Hz)
FCl = fft(Clm)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
[pks,locs] = findpeaks(abs(FCl(Iv))*2, 'MinPeakHeight',0.01);
figure
plot(Fv, abs(FCl(Iv))*2)
grid
xlim([0 1E3])
text(Fv(locs), pks, sprintf('\\leftarrow Dominant Frequency = %.2f', Fv(locs)), 'HorizontalAlignment','left')
The dominant frequency appears to be 226.4.
EDIT —
Added plot image:
FFT for the given data to find the dominant frequency- 2019 05 03.png
  2 commentaires
Guanting SU
Guanting SU le 29 Oct 2019
This is absoluately helpful!
Star Strider
Star Strider le 29 Oct 2019
@Guanting SU — Thank you!

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 3 Mai 2019
Modifié(e) : Image Analyst le 3 Mai 2019
Is this homework?
Here's a start.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
data = readtable('forcecoefficients1.xlsx');
t = data.x_Time;
x = data.Cl;
% Get rid of garbage first point.
x(1) = x(2);
subplot(2, 1, 1);
plot(t, x, 'b-')
title('x vs. t', 'FontSize', fontSize);
xlabel('t', 'FontSize', fontSize);
ylabel('x', 'FontSize', fontSize);
grid on;
y=fftshift(fft(x - mean(x)));
f = (0:length(y)-1)*(10000)/length(y);
subplot(2, 1, 2);
plot(abs(y), 'b-', 'LineWidth', 2)
grid on;
title('Spectral Power', 'FontSize', fontSize);
xlabel('frequency', 'FontSize', fontSize);
ylabel('Power', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
It looks like there are two main spectral ranges with power in them:
See the two spikes close to the origin? You might want to set xlim() to zoom in and see them. Be sure to properly set up the units for the frequency axis. Now, what frequencies do you see the two spikes at? I don't want to do everything for you since I strongly suspect this is your homework and I don't want to get you in trouble for copying.

Kaosar Soomro
Kaosar Soomro le 3 Juin 2022
In you code above, what does [D,S] represent and what do the letters refer to? Also, What is Cl and Clm?
Thank you!
  1 commentaire
Star Strider
Star Strider le 3 Juin 2022
They are the outputs from the xlsread function. See the documentation on xlsread for details.
The ‘Cl’ variable is the signal and ‘Clm’ is the signal with the mean of the signal subtracted from it so the spectrum peaks are easier to see.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by