简体   繁体   English

将正弦波中的时间和频率转储到 csv 中

[英]Dump time and frequency in a sine wav into csv

Am just plotting a sine wave and doing a plot spectrum analysis(similar to the one which is in audacity).我只是在绘制正弦波并进行频谱分析(类似于大胆的分析)。

To plot i have a function like:要绘制我有一个功能,如:

pxx, f, t, ax = plt.specgram(
    audio_data, NFFT=size, Fs=rate, noverlap=0, cmap=plt.cm.binary,
    sides='onesided', window=signal.hann(size), mode='magnitude')
plt.plot(f, 20 * np.log10(np.mean(pxx, axis=1)), 'b')

This function plots as expected.此函数按预期绘制。 But i need to dump the frequency and time of the sine wave into the file in the below format.但我需要以以下格式将正弦波的频率和时间转储到文件中。

Time(secs)    Freq
0.5           100
1             200

Is there a way to do this using the values returned in specgram.有没有办法使用 specgram 中返回的值来做到这一点。

Please note am pretty new to audio analysis am just learning my trade.请注意,我对音频分析还很陌生,我只是在学习我的交易。 Any help would be appreciated.任何帮助,将不胜感激。

The Matplotlib specgram helper automatically segments your signal and runs FFT on it, so you end up with an image. Matplotlib specgram助手会自动specgram您的信号并对其运行 FFT,因此您最终会得到一张图像。 That won't help you much for outputting text data.这对输出文本数据没有多大帮助。

In addition, at any given point in time multiple frequencies will exist in the signal (yes, even a monophonic sine wave due to FFT imprecision), so you can't describe a signal at any given time with just a single "Freq" value.此外,在任何给定的时间点,信号中都会存在多个频率(是的,由于 FFT 不精确,即使是单声道正弦波),因此您无法仅用单个“频率”值来描述任何给定时间的信号. You could, however, figure out a peak frequency for a time window.但是,您可以计算出时间窗口的峰值频率。

You can find the source for specgram here if you feel like adapting it, but it might be better to look at SciPy's FFT functions (or this tutorial ) so you get numeric data from the get-go.如果您想调整它,可以在此处找到specgram的来源,但最好查看 SciPy 的 FFT 函数(或本教程),以便您从一开始就获得数字数据。

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

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