简体   繁体   English

SciPy:将特征转换为频域

[英]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 . 为此,我使用了SciPysignal.spectrogram函数。 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. 例如,尝试探索Wavelet变换,(请参见此处应用到时间序列的连续Wavelet变换(cwt)的示例),您可以使用PyWavelets包轻松获得它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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