什么是频谱图以及如何设置其参数? [英] What is a spectrogram and how do I set its parameters?

查看:45
本文介绍了什么是频谱图以及如何设置其参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制给定的时域信号的频谱图:

N=5000;phi = (rand(1,N)-0.5)*pi;a = tan((0.5.*phi));i = 2.*a./(1-a.^2);情节(一);频谱图(i,100,1,100,1e3);

问题是我不明白参数和应该给出什么值.我使用的这些值,我参考了 MATLAB 的 spectrogram 在线文档.我是 MATLAB 的新手,我只是不明白.任何帮助将不胜感激!

解决方案

在我们真正了解 MATLAB 命令的作用之前,您可能想知道什么是频谱图.这样您就可以更深入地了解每个参数的工作原理.

频谱图是

因此,对于每个时间点,我们都会看到频率分量的分布.将每一列视为以该时间点为中心的块的频率分解.对于每一列,我们看到不同的颜色光谱.颜色越深,该频率的幅度分量越低,反之亦然.

<小时>

那么!...现在您已经掌握了这一点,让我们从函数及其参数的角度来研究 MATLAB 的工作原理.您调用 spectrogram 的方式符合这个版本的功能:

频谱图(x,window,noverlap,nfft,fs)

让我们一一介绍每个参数,以便您更好地了解每个参数的作用:

  • x - 这是您希望找到其频谱图的输入时域信号.没有比这更简单的了.在您的情况下,您要查找其频谱图的信号在以下代码中定义:

    N=5000;phi = (rand(1,N)-0.5)*pi;a = tan((0.5.*phi));i = 2.*a./(1-a.^2);

    这里,i 是您要查找其频谱图的信号.

  • window - 如果你还记得,我们将图像分解成块,每个块都有指定的宽度.window 根据样本定义每个块的宽度.由于这是一个离散时间信号,您知道该信号是用特定的采样频率和采样周期进行采样的.您可以通过以下方式确定窗口的样本大小:

    window_samples = window_time/Ts

    Ts 是信号的采样时间.设置窗口大小实际上是非常经验的,需要大量的实验.基本上,窗口尺寸越大,当您捕获更多频率时,您获得的频率分辨率就越好,但时间定位很差.类似地,窗口大小越小,您的时间定位就越好,但您不会得到那么好的频率分解.我在这里没有任何关于最佳尺寸的建议......这就是为什么小波 在时频分解方面是首选.对于每个块",这些块会被分解为具有动态宽度的较小块,因此您可以获得良好的时间和频率本地化.

  • noverlap - 确保良好频率定位的另一种方法是块重叠.适当的频谱图确保每个块都有一定数量的样本,每个块都有重叠,noverlap 定义了每个窗口中重叠的样本数.默认为每个块宽度的 50%.

  • nfft - 您实际上是在对每个块进行 FFT.nfft 告诉您每个块需​​要计算多少个 FFT 点.默认点数是 256 或 floor(log2(N)) 中的最大值,其中 N 是信号的长度.nfft 还给出了频率分辨率细粒度的度量.FFT 点数越多,频率分辨率越高,从而在可视化的情况下沿频谱图的频率轴显示细粒度的细节.

  • fs - 信号的采样频率.默认值为 1 Hz,但您可以将其覆盖为信号所在的任何采样频率.

<小时>

因此,您可能应该从中了解的是,我无法真正告诉您如何设置参数.这完全取决于您拥有什么信号,但希望以上解释能让您更好地了解如何设置参数.

<小时>

祝你好运!

I am trying to plot the spectrogram of my time domain signal given:

N=5000;
phi = (rand(1,N)-0.5)*pi;
a = tan((0.5.*phi));
i = 2.*a./(1-a.^2);
plot(i);
spectrogram(i,100,1,100,1e3);

The problem is I don't understand the parameters and what values should be given. These values that I am using, I referred to MATLAB's online documentation of spectrogram. I am new to MATLAB, and I am just not getting the idea. Any help will be greatly appreciated!

解决方案

Before we actually go into what that MATLAB command does, you probably want to know what a spectrogram is. That way you'll get more meaning into how each parameter works.

A spectrogram is a visual representation of the Short-Time Fourier Transform. Think of this as taking chunks of an input signal and applying a local Fourier Transform on each chunk. Each chunk has a specified width and you apply a Fourier Transform to this chunk. You should take note that each chunk has an associated frequency distribution. For each chunk that is centred at a specific time point in your time signal, you get a bunch of frequency components. The collection of all of these frequency components at each chunk and plotted all together is what is essentially a spectrogram.

The spectrogram is a 2D visual heat map where the horizontal axis represents the time of the signal and the vertical axis represents the frequency axis. What is visualized is an image where darker colours means that for a particular time point and a particular frequency, the lower in magnitude the frequency component is, the darker the colour. Similarly, the higher in magnitude the frequency component is, the lighter the colour.

Here's one perfect example of a spectrogram:

Source: Wikipedia

Therefore, for each time point, we see a distribution of frequency components. Think of each column as the frequency decomposition of a chunk centred at this time point. For each column, we see a varying spectrum of colours. The darker the colour is, the lower the magnitude component at that frequency is and vice-versa.


So!... now you're armed with that, let's go into how MATLAB works in terms of the function and its parameters. The way you are calling spectrogram conforms to this version of the function:

spectrogram(x,window,noverlap,nfft,fs) 

Let's go through each parameter one by one so you can get a greater understanding of what each does:

  • x - This is the input time-domain signal you wish to find the spectrogram of. It can't get much simpler than that. In your case, the signal you want to find the spectrogram of is defined in the following code:

    N=5000;
    phi = (rand(1,N)-0.5)*pi;
    a = tan((0.5.*phi));
    i = 2.*a./(1-a.^2);
    

    Here, i is the signal you want to find the spectrogram of.

  • window - If you recall, we decompose the image into chunks, and each chunk has a specified width. window defines the width of each chunk in terms of samples. As this is a discrete-time signal, you know that this signal was sampled with a particular sampling frequency and sampling period. You can determine how large the window is in terms of samples by:

    window_samples = window_time/Ts

    Ts is the sampling time of your signal. Setting the window size is actually very empirical and requires a lot of experimentation. Basically, the larger the window size, the better frequency resolution you get as you're capturing more of the frequencies, but the time localization is poor. Similarly, the smaller the window size, the better localization you have in time, but you don't get that great of a frequency decomposition. I don't have any suggestions here on what the most optimal size is... which is why wavelets are preferred when it comes to time-frequency decomposition. For each "chunk", the chunks get decomposed into smaller chunks of a dynamic width so you get a mixture of good time and frequency localization.

  • noverlap - Another way to ensure good frequency localization is that the chunks are overlapping. A proper spectrogram ensures that each chunk has a certain number of samples that are overlapping for each chunk and noverlap defines how many samples are overlapped in each window. The default is 50% of the width of each chunk.

  • nfft - You are essentially taking the FFT of each chunk. nfft tells you how many FFT points are desired to be computed per chunk. The default number of points is the largest of either 256, or floor(log2(N)) where N is the length of the signal. nfft also gives a measure of how fine-grained the frequency resolution will be. A higher number of FFT points would give higher frequency resolution and thus showing fine-grained details along the frequency axis of the spectrogram if visualised.

  • fs - The sampling frequency of your signal. The default is 1 Hz, but you can override this to whatever the sampling frequency your signal is at.


Therefore, what you should probably take out of this is that I can't really tell you how to set the parameters. It all depends on what signal you have, but hopefully the above explanation will give you a better idea of how to set the parameters.


Good luck!

这篇关于什么是频谱图以及如何设置其参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆