简体   繁体   中英

SciPy: convert feature to frequency domain

Problem statement

Given : A timeseries which consists of time/amplitude values

Desired output : A conversion of the given signal into the frequency domain which consists of time/frequency values

More info

I would like to have an identical mapping of the timestamps in the input, to a frequency level in the output.

To do this I used the signal.spectrogram function from SciPy . It is clear that there is a correspondence between input and output.

Question : What is the preferred way to convert this output into time/frequency values? Is it good practice to take the maximum value?

Code

fs = 1.0
f, t, Sxx = signal.spectrogram(x, fs)
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.axis([t.min(), t.max(), f.min(), .02])
plt.show()

输入 谱图

Question: What is the preferred way to convert this output into time/frequency values? Is it good practice to take the maximum value?

Usually if you calculate the spectrogram you want to see what are the frequencies composing your signal in a window around each time point. And this is why you get the heatmap that you are showing. Now, this is already a representation of your signal in the frequency domain as a function of time. If you take only the maximum values, you will cut relevant information, and what you will obtained will be a representation of a different signal. This is not what you want, because it doesn't make sense from a signal processing perspective. You would represent an artifact signal based on only the strongest frequencies in each time window.

There are other ways of representing frequency features as a function of time that you might want to explore if the spectrogram doesn't display the information you are looking for. For example try exploring Wavelet transforms, (see here an example of a continuous wavelet transform (cwt) applied to a time series ) You can easily get it using the PyWavelets package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM