0
$\begingroup$

I'm trying to improve my score in the LANL Earthquake Prediction challenge on Kaggle extracting more features from the acoustic data through STFT transforming. Eventually I've found this well written example that produces spectrograms like these.

log spectrogram

When I try to use the same code with my data, I obtain similar results. Below there's the relevant snippet of my code, the obtained spectrograms and the standard output.

    freqs, times, spec = stft(data, 4000000, nperseg=4096)
    # Log spectrogram
    print(80*'*')
    print(np.abs(spec))
    print(80*'*')
    amp = np.log(np.abs(spec)+1e-10)
    print(np.abs(amp))
    print(80*'*')

    print(data.shape)
    print(spec.shape)
    print(amp.shape)

    ax = plt.gca()
    ax.imshow(np.abs(spec), aspect='auto', origin='lower', 
               extent=[times.min(), times.max(), freqs.min(), freqs.max()])
    ax.set_title('Spectrogram of spec')
    ax.set_ylabel('Freqs in Hz')
    ax.set_xlabel('Seconds')
    plt.show()
    plt.close()
    ax = plt.gca()
    ax.imshow(amp, aspect='auto', origin='lower', 
               extent=[times.min(), times.max(), freqs.min(), freqs.max()])
    ax.set_title('Spectrogram of amp')
    ax.set_ylabel('Freqs in Hz')
    ax.set_xlabel('Seconds')
    plt.show()
    plt.close()

    stft_data = pd.DataFrame(amp)
    print(stft_data)
    sys.exit()

spectogram of spec enter image description here

********************************************************************************
[[0.14987504 0.34059396 0.19059515 ... 0.000605   0.04479677 0.00041644]
 [0.11181035 0.16640377 0.08124886 ... 0.04708374 0.06263545 0.00050966]
 [0.03161105 0.07702927 0.10776774 ... 0.14206427 0.07884956 0.00071852]
 ... 
 [0.00582739 0.02830912 0.01044084 ... 0.01680098 0.0332666  0.00150545]
 [0.01319591 0.05239453 0.03082144 ... 0.03149477 0.00660011 0.00149197]
 [0.01834724 0.06475744 0.0356362  ... 0.04321439 0.01655968 0.00148736]]
********************************************************************************
[[1.8979534 1.0770643 1.6576037 ... 7.4102793 3.1056192 7.783778 ]
 [2.190951  1.7933381 2.5102384 ... 3.0558276 2.770424  7.5817738]
 [3.4542487 2.5635698 2.227777  ... 1.9514757 2.5402136 7.2383184]
 ... 
 [5.1451855 3.5645714 4.5620303 ... 4.086318  3.4032013 6.498665 ]
 [4.327848  2.9489532 3.4795446 ... 3.4579337 5.0206685 6.5076556]
 [3.9982762 2.7371066 3.3343933 ... 3.1415818 4.1007843 6.510753 ]]
********************************************************************************
(150000,)
(2049, 75) 
(2049, 75) 
            0         1         2         3         4         5         6   ...        68        69        70        71        72        73        74          

0    -1.897953 -1.077064 -1.657604 -1.066190 -1.116828 -2.121890 -2.555377  ... -0.205251 -0.939756 -0.828219 -1.817054 -7.410279 -3.105619 -7.783778
1    -2.190951 -1.793338 -2.510238 -1.670207 -1.663118 -2.242866 -2.619253  ... -0.747613 -2.647341 -1.579513 -2.104003 -3.055828 -2.770424 -7.581774
...        ...       ...       ...       ...       ...       ...       ...  ...       ...       ...       ...       ...       ...       ...       ...
2047 -4.327848 -2.948953 -3.479545 -3.762161 -3.118481 -3.399782 -4.007057  ... -3.065971 -2.978651 -3.376523 -4.091198 -3.457934 -5.020669 -6.507656
2048 -3.998276 -2.737107 -3.334393 -3.545117 -3.132174 -3.925000 -4.418162  ... -3.432035 -3.509602 -5.066754 -4.357491 -3.141582 -4.100784 -6.510753

[2049 rows x 75 columns]

These spectrograms look good, but I'm short of ideas about how to use this [2049 x 75] DataFrame to extract features. I mean, you can do mean(), std(), min(), max(), np.quantile() on the time-domain monodimensional signal (or on the real and imaginary parts of a fft-transformed signal), but how should I extract the same features with this kind of data?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.