Clear Filters
Clear Filters

FFT for Lift coefficient to find the frequency

3 views (last 30 days)
Hello, everyone!
I have different data files(.txt) includes simulation time, lift coefficient and drag coefficient.
I want to find the some frequencies which make periodic motion of lift.
The code is follwed :
load CdCl5.txt; a=CdCl5; Time5=a(1:end,2); Lift5=a(1:end,4);
load CdCl7.txt; a=CdCl7; Time7=a(1:end,2); Lift7=a(1:end,4);
figure(1) % Graph of the life coeffi.
subplot(211)
plot(Time5, Lift5)
title('Scheme 1')
xlabel('Time')
ylabel('C_L')
subplot(212)
plot(Time7, Lift7)
title('Scheme 2')
xlabel('Time')
ylabel('C_L')
% Parameter
N = length(Time5);
T = Time5(end); % Time length
dt = T/N;
df = 1/T; % frequency interval
f = df*(0:N-1); % frequency sequence
X5 = fft(Lift5)/N;
X7 = fft(Lift7)/N;
figure(2)
subplot(211)
plot(f,abs(X5))
title('Scheme 1')
ylabel('|X5(f)|')
xlabel('Frequncy[hz]')
subplot(212)
plot(f,abs(X7))
title('Scheme 2')
ylabel('|X7(f)|')
xlabel('Frequncy[hz]')
Do I analyze the figure(2) graphs to find the frequencies?
Could someone help me?
Thank you so much!
Sopo.

Accepted Answer

Mathieu NOE
Mathieu NOE on 17 Oct 2022
hello
I prefer to put the repetitive fft lines in a subfunction , so the code can be cleaner and more compact
for the fft result , we are interested only in the positive half frequency points
you can use max or findpeaks to get the peaks value
a = readmatrix('CdCl5.txt');
Time5=a(1:end,2); Lift5=a(1:end,4);
a = readmatrix('CdCl7.txt');
Time7=a(1:end,2); Lift7=a(1:end,4);
figure(1) % Graph of the life coeffi.
subplot(211)
plot(Time5, Lift5)
title('Scheme 1')
xlabel('Time')
ylabel('C_L')
subplot(212)
plot(Time7, Lift7)
title('Scheme 2')
xlabel('Time')
ylabel('C_L')
% FFT plot
[f1,fft_spectrum1] = do_fft(Time5,Lift5);
[f2,fft_spectrum2] = do_fft(Time7,Lift7);
figure(2)
[PKS1,LOCS1] = max(fft_spectrum1);
f1_peak = f1(LOCS1)
subplot(211)
semilogx(f1,fft_spectrum1,f1_peak,PKS1,'dr')
text(f1_peak*1.25,PKS1 , (['f1 = ' num2str(f1_peak) ' Hz']));
title('Scheme 1')
ylabel('|X5(f)|')
xlabel('Frequency[hz]')
subplot(212)
[PKS2,LOCS2] = max(fft_spectrum2);
f2_peak = f2(LOCS2)
semilogx(f2,fft_spectrum2,f2_peak,PKS2,'dr')
text(f2_peak*1.25,PKS2 , (['f2 = ' num2str(f2_peak) ' Hz']));
title('Scheme 2')
ylabel('|X7(f)|')
xlabel('Frequency[hz]')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [freq_vector,fft_spectrum] = do_fft(time,data)
dt = mean(diff(time));
Fs = 1/dt;
nfft = length(data); % maximise freq resolution => nfft equals signal length
fft_spectrum = abs(fft(data))/nfft;
% one sidded fft spectrum % Select first half
if rem(nfft,2) % nfft odd
select = (1:(nfft+1)/2)';
else
select = (1:nfft/2+1)';
end
fft_spectrum = fft_spectrum(select,:);
freq_vector = (select - 1)*Fs/nfft;
end

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering 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!