0

I have a Python snippet of code I found. I used it to create useful Python code to extract the dominate frequency. I know the code works because I have used it with the default N and Nev values on some runs and received the same Strouhal number (St) as the sinusoidal method.

I am evaluating the frequency of a vortex street, so I don't have DC frequency, but I am getting "0.0". I tested the values of N and Nev when the code was working. I noticed the final result of the dominate frequency is very dependent on N.

I have looked at suggested posts, but they fall short. Here is the code. How do I adjust sample for linspace as my lift data increases?

#1/usr/bin/env python

import sys
import numpy as np
import scipy.fftpack as fftpack
import matplotlib.pyplot as plt


print("Hello World!")

N = 2500
Nev = 1000

data = np.loadtxt('CoefficientLiftData.dat', usecols= (0,3)) 

times = data[:,0]
length = int(len(times)/2)

forcez= data[:,1]
t = np.linspace(times[length], times[-1], N) 
forcezint = np.interp(t, times, forcez) 

fourier = fftpack.fft(forcezint[Nev-1:N-1])
frequencies = fftpack.fftfreq(forcezint[Nev-1:N-1].size, d=t[1]-t[0]) 
#print(frequencies)
freq = frequencies[np.argmax(np.abs(fourier))]


print(freq)
Chris Harding
  • 27
  • 1
  • 8

1 Answers1

0

Did you have a look at this answer on how to choose the correct frequency scale? Additionally you should have a look on window functions, like the Tukey window to get the correct frequencies of your signal, if the signal is not equal at the interval boundaries.

Edit: And you could also have a look at this answer that gives detailed explanation on how to get proper results for an FFT analysis.

Axel
  • 1,415
  • 1
  • 16
  • 40