MATLAB``频谱图''参数 [英] MATLAB 'spectrogram' params

查看:92
本文介绍了MATLAB``频谱图''参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MATLAB的初学者,我应该对EEG信号进行频谱分析,以绘制功率谱密度和频谱图的图表.我的信号长度为10秒,采样频率为160 Hz,总计为1600 samples,并且对如何在MATLAB中查找函数的参数有一些疑问,包括:

I am a beginner in MATLAB and I should perform a spectral analysis of an EEG signal drawing the graphs of power spectral density and spectrogram. My signal is 10 seconds long and a sampling frequency of 160 Hz, a total of 1600 samples and have some questions on how to find the parameters of the functions in MATLAB, including:

pwelch (x, window, noverlap, nfft, fs);

spectrogram (x, window, noverlap, F, fs);

然后我的问题是在哪里可以找到参数windownoverlap的值,我不知道它们的用途.

My question then is where to find values ​​for the parameters window and noverlap I do not know what they are for.

推荐答案

了解窗口功能&它们的用法,让我们首先看一下在进行有限长度样本的DFT时会发生什么.离散傅里叶变换的定义隐含一个假设,即您正在考虑的信号的有限长度是周期性的.

To understand window functions & their use, let's first look at what happens when you take the DFT of finite length samples. Implicit in the definition of the discrete Fourier transform, is the assumption that the finite length of signal that you're considering, is periodic.

考虑正弦波,对其进行采样以捕获整个周期.复制信号后,您可以看到它作为不间断的信号周期性地继续.产生的DFT仅具有一个非零分量,并且处于正弦波的频率.

Consider a sine wave, sampled such that a full period is captured. When the signal is replicated, you can see that it continues periodically as an uninterrupted signal. The resulting DFT has only one non-zero component and that is at the frequency of the sinusoid.

现在考虑一个具有不同周期的余弦波,对其进行采样以便仅捕获部分周期.现在,如果您复制信号,您会看到信号中的不连续性,并标记为红色.不再有平滑的过渡,因此您将有其他频率的泄漏,如下所示

Now consider a cosine wave with a different period, sampled such that only a partial period is captured. Now if you replicate the signal, you see discontinuities in the signal, marked in red. There is no longer a smooth transition and so you'll have leakage coming in at other frequencies, as seen below

光谱泄漏通过旁瓣发生.要了解更多信息,您还应该阅读 sinc函数及其傅里叶变换,即

This spectral leakage occurs through the side-lobes. To understand more about this, you should also read up on the sinc function and its Fourier transform, the rectangle function. The finite sampled sequence can be viewed as an infinite sequence multiplied by the rectangular function. The leakage that occurs is related to the side lobes of the sinc function (sinc & rectangular belong to self-dual space and are F.Ts of each other). This is explained in more detail in the spectral leakage article I linked to above.

窗口功能

窗口函数用于信号处理,以最大程度地减少频谱泄漏的影响.基本上,窗函数的作用是使末端的有限长度序列逐渐变细,以便在平铺时具有周期性的结构,且没有间断,从而减少了光谱泄漏.

Window functions are used in signal processing to minimize the effect of spectral leakages. Basically, what a window function does is that it tapers the finite length sequence at the ends, so that when tiled, it has a periodic structure without discontinuities, and hence less spectral leakage.

一些常见的窗口是Hanning,Hamming,Blackman,Blackman-Harris,Kaiser-Bessel等.您可以从Wiki链接中阅读更多内容,相应的MATLAB命令是hannhammingblackmanblackmanharriskaiser.这是不同窗口的一小部分示例:

Some of the common windows are Hanning, Hamming, Blackman, Blackman-Harris, Kaiser-Bessel, etc. You can read up more on them from the wiki link and the corresponding MATLAB commands are hann, hamming,blackman, blackmanharris and kaiser. Here's a small sample of the different windows:

您可能想知道为什么会有这么多不同的窗口功能.原因是因为它们每个具有非常不同的光谱特性,并且具有不同的主瓣宽度和旁瓣幅度.没有免费的午餐:如果您想获得良好的频率分辨率(主瓣很细),旁瓣就会变大,反之亦然.不能两者兼有.通常,窗口功能的选择取决于特定的需求,并且总是归结为妥协. 是一篇很好的文章,内容涉及使用窗口函数,您一定要通读它.

You might wonder why there are so many different window functions. The reason is because each of these have very different spectral properties and have different main lobe widths and side lobe amplitudes. There is no such thing as a free lunch: if you want good frequency resolution (main lobe is thin), your sidelobes become larger and vice versa. You can't have both. Often, the choice of window function is dependent on the specific needs and always boils down to making a compromise. This is a very good article that talks about using window functions, and you should definitely read through it.

现在,当您使用窗口功能时,锥形端的信息较少.因此,解决此问题的一种方法是使用重叠的滑动窗口,如下所示.想法是,将它们放在一起时,它们会尽可能地近似原始序列(即,底行应尽可能接近于固定值1).典型值介于33%到50%之间,具体取决于应用程序.

Now, when you use a window function, you have less information at the tapered ends. So, one way to fix that, is to use sliding windows with an overlap as shown below. The idea is that when put together, they approximate the original sequence as best as possible (i.e., the bottom row should be as close to a flat value of 1 as possible). Typical values vary between 33% to 50%, depending on the application.

使用MATLAB的频谱图

语法为spectrogram(x,window,overlap,NFFT,fs)

其中

  • x是您的整个数据向量
  • window是您的窗口函数.如果仅输入一个数字,例如说W(必须为整数),则MATLAB将您的数据切成每个W样本的块,并从中形成频谱图.这等效于使用长度为W个样本的矩形窗口.如果要使用其他窗口,请提供hann(W)或您选择的任何窗口.
  • overlap是您需要重叠的样本数.因此,如果需要50%的重叠,则此值应为W/2.如果W可以取奇数值,请使用floor(W/2)ceil(W/2).这只是一个整数.
  • NFFT是FFT长度
  • fs是数据向量的采样频率.您可以将其保留为空,然后MATLAB会根据归一化频率和时间轴将图形绘制为简单的数据块索引.如果输入它,MATLAB将相应地缩放轴.
  • x is your entire data vector
  • window is your window function. If you enter just a number, say W (must be integer), then MATLAB chops up your data into chunks of W samples each and forms the spectrogram from it. This is equivalent to using a rectangular window of length W samples. If you want to use a different window, provide hann(W) or whatever window you choose.
  • overlap is the number of samples that you need to overlap. So, if you need 50% overlap, this value should be W/2. Use floor(W/2) or ceil(W/2) if W can take odd values. This is just an integer.
  • NFFT is the FFT length
  • fs is the sampling frequency of your data vector. You can leave this empty, and MATLAB plots the figure in terms of normalized frequencies and the time axis as simply the data chunk index. If you enter it, MATLAB scales the axis accordingly.

您还可以获取可选输出,例如时间向量和频率向量以及计算出的功率谱,以用于其他计算或需要以不同方式绘制图形样式.有关更多信息,请参考文档.

You can also get optional outputs such as the time vector and frequency vector and the power spectrum computed, for use in other computations or if you need to style your plot differently. Refer to the documentation for more info.

在此示例中,以1000 Hz采样的频率从20 Hz到400 Hz的线性线性调频信号为1秒.使用两个窗口功能,HanningBlackman-Harris,有和没有重叠.窗口长度为50个样本,使用时重叠率为50%.在每个图中,这些图被缩放到相同的80dB范围.

Here's an example with 1 second of a linear chirp signal from 20 Hz to 400 Hz, sampled at 1000 Hz. Two window functions are used, Hanning and Blackman-Harris, with and without overlaps. The window lengths were 50 samples, and overlap of 50%, when used. The plots are scaled to the same 80dB range in each plot.

由于重叠,您会注意到图中的差异(上下​​).如果使用重叠,则可以得到更清晰的估计.您还可以观察到我前面提到的主瓣宽度和旁瓣幅度之间的权衡.汉宁的主瓣(沿斜对角线的突出线)较细,可以得到更好的频率分辨率,但旁瓣泄漏(从外部明亮的颜色可以看出).另一方面,布莱克韦尔·哈里斯(Blackwell-Harris)的主瓣较厚(对角线较粗),但光谱泄漏较少,这是由均匀较低的(蓝色)外部区域所证实的.

You can notice the difference in the figures (top-bottom) due to the overlap. You get a cleaner estimate if you use overlap. You can also observe the trade-off between main lobe width and side lobe amplitude that I mentioned earlier. Hanning has a thinner main lobe (prominent line along the skew diagonal), resulting in better frequency resolution, but has leaky sidelobes, seen by the bright colors outside. Blackwell-Harris, on the other hand, has a fatter main lobe (thicker diagonal line), but less spectral leakage, evidenced by the uniformly low (blue) outer region.

这篇关于MATLAB``频谱图''参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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