0

So I have this car that moves at a velocity that is the sum of three different sine waves (whose individual frequencies I know). I used the following to construct this velocity time graph

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('drivingdata.csv') # velocity values
s = df['leadspeed'].values # transform csv col into array
t = np.linspace(0, 1, 5067)
plt.ylabel("Amplitude")
plt.xlabel("Time[s]")
plt.plot(t, s)
plt.show()

This is fine, and then I perform a FFT on this data with the following numpy function:

T = t[1]-t[0] # sample rate
N = s.size
fft = np.fft.fft(s)
f = np.linspace(0, 1//T, N) # 1/T is the frequency 

plt.ylabel("Amplitude")
plt.xlabel("Frequency [Hz]")

plt.bar(f[:N // 2], np.abs(fft)[:N // 2] * 1 // N) # 1/N is a normalization factor
plt.show()

Then I get this amplitude vs frequency graph. How do I "zoom-in" so that I can confirm my initial frequencies (all under 0.2) ?

I'm completely new to fft, so criticism/help would be appreciated.

EDIT:

I followed your helpful advice, Cris Luengo, and this is my new graph. The frequencies I input into my waves were 0.033, 0.083, and 0.117, so I'm still left seeking answers.

EDIT 2: My apologies, Cris. Here you go. Are the frequencies I'm looking for just right past the 0 there? Is there a way to "zoom in" ? New graph

  • 1
    Note that `1//T` uses integer division, leading to an integer value. This will be 0 for any `T>1`. I don't know what your `T` is, but either way you want to use `1.0/T` here. The same is true for `1//N`. Because of precedence, I guess you first compute `fft*1`, and then apply the integer division by `N`. I guess all your bins except the first one are lower than `N`, and hence will turn out to be 0 in the plot. – Cris Luengo Nov 29 '18 at 23:01
  • See here: https://stackoverflow.com/q/183853/7328782 – Cris Luengo Nov 29 '18 at 23:05
  • Your new plot is not the result of the code posted. Could you please post the code that produces this new plot? – Cris Luengo Nov 29 '18 at 23:25
  • Hi Cris, The edit is up. My apologies. – Hanna Haponenko Nov 30 '18 at 11:58

0 Answers0