0

I'm going to compare stft frequency data with another stft frequency data. I just can use stft method, but I don't know how to extract stft frequency data. Here is my data.

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np

# Data load
data = open('data.txt', 'r').read().split('\n')
time = []
temperature = []
for i in range(0, len(data)):
    time.append(float(data[i][0:8]))
    temperature.append(float(data[i][9:len(data[i])]))

fs = len(time)/(max(time)-min(time))    # Sampling frequency

# FFT
f, t, Zxx = signal.stft(temperature, fs)

plt.pcolormesh(t, 2*np.pi*1.8*f/1e3, np.abs(Zxx), vmin=0, vmax=100)

enter image description here

How can I extract yellow line data? (x axis is time / y axis is frequency)

JK Lee
  • 11
  • 3

1 Answers1

1

This is not perfect, but should work. It will give you the maxima of your fft. The trick is to use np.where

my_rand_fft = np.random.rand(20,80)

The next is to model the fact that your STFT contains a lot of constant value at the low frequencies. If I am wrong, change the later code accordingly

my_rand_fft[-1,:]=1

The brute force approach:

pos_of_max=[]
for n in range(np.shape(my_rand_fft)[1]):
    pos_of_max.append((0,np.where(my_rand_fft[0:-1,n]==np.max(my_rand_fft[0:-1,n])[0])))

The more elegant solution

pos_of_max=np.where(my_rand_fft==np.max(my_rand_fft[0:-1,:], axis=0))

Make sure that the part with the maxima is excluded. If they are in the zero position, keep in mind that you need to add whatever was skipped to exclude them.

Eulenfuchswiesel
  • 879
  • 9
  • 20