matlab---spectrogram短时傅里叶变换与chrip信号
文章目錄
- 0、背景
- 1、chrip信號
- 1、matlab幫助文檔對chirp的解釋
- 2、非線性調頻
- 1、高斯包絡的調頻信號
- 2、spectrogram
- 利用surf根據spectrogram的返回參數值繪制三維
0、背景
本來這一節其實可以放在《matlab文檔查閱使用訓練(手把手教你閱讀matlab文檔)全網首發原創》,但是由于這兩個函數非常重要,所以想單獨拿出來記錄,以便后續使用。
1、chrip信號
A chirp is a signal in which the frequency increases (up-chirp) or decreases (down-chirp) with time. In some sources, the term chirp is used interchangeably with sweep signal. It is commonly used in sonar and radar, but has other applications, such as in spread-spectrum communications.
chirp是頻率隨時間增加或減小的一種信號。在某些領域中,chirp這個詞可以與掃頻信號的名詞互換使用。通常用于雷達,聲吶中,但是也有別的用途,例如擴頻通信。
1、matlab幫助文檔對chirp的解釋
從上面描述可以知道,一般來說我們常用的syntax的第一種形式,其中t是變量,包含了我們的時間點數(采樣率),而f0和t1以及f1都是固定的,f0代表了在時間0的瞬時頻率,f1代表了在時間t1時刻的瞬時頻率。
下面是句法2的用法,method可以指定掃頻的選項,也就是說,我們也可以非線性掃頻。
第二種掃頻模式是quadratic,也就是說要求t,是需要開平方根的。
第三種是對數形式,也就是說要求時間,是需要求對數的。
指定凹凸可以使掃頻上凸或者凹的頻率上升和下降
2、非線性調頻
1、高斯包絡的調頻信號
w = gausswin(N,Alpha)返回一個N點高斯窗口,Alpha與標準差的倒數成正比。窗口的寬度是α的值成反比。更大的α值產生一個窄窗口。α的值默認為2.5。
現在,我要產生一個高斯包絡的線性調頻信號,但是頻率逐漸增高,到了中間點,頻率達到最高,然后頻率在逐漸減小,以中間為對稱。
clc clear close allt1 = 0:1/1e3:(1-1/1e3)/2; %以1KHZ的頻率采樣0.5秒鐘 y1 = chirp(t1,0,(1-1/1e3)/2,200); y2 = chirp(t1,200,(1-1/1e3)/2,0); y=[y1,y2]; t=[t1,t1+0.499000000000000+1/1e3]; g=gausswin(length(y),2.5);%默認標準的高斯包絡是2.5 g=g.'; H=y.*g; subplot(3,1,1) plot(t,y) subplot(3,1,2) spectrogram(y,256,250,256,1e3,'yaxis') subplot(3,1,3) plot(t,H);2、spectrogram
- s=spectrogram(x)
表示將x進行默認的短時傅里葉變換,默認窗口使用海明窗,將x分成8段。
如果x不能被平分成8段,則會做截斷處理。默認情況下,其他參數的默認值為
window—窗函數,默認為nfft長度的海明窗Hamming
noverlap—每一段的重疊樣本數,默認值是在各段之間產生50%的重疊
nfft—做FFT變換的長度,默認為256和大于每段長度的最小2次冪之間的最大值。
另外,此參數除了使用一個常量外,還可以指定一個頻率向量F
fs—采樣頻率,默認值歸一化頻率
案例:
Generate samples of a signal that consists of a sum of sinusoids. The normalized frequencies of the sinusoids are rad/sample and rad/sample. The higher frequency sinusoid has 10 times the amplitude of the other sinusoid.
產生一個正弦曲線,歸一化頻率都是rad/sample,更高的頻率的正弦信號是低正弦信號幅度的10倍。
正弦信號1:2π/5;
正弦信號2: 4π/5;
- Power Spectral Densities of Chirps
Compute and display the PSD of each segment of a quadratic chirp that starts at 100 Hz and crosses 200 Hz at t = 1 s. Specify a sample rate of 1 kHz, a segment length of 128 samples, and an overlap of 120 samples. Use 128 DFT points and the default Hamming window.
計算chirp信號的功率譜,chirp信號以頻率100HZ到200HZ,指定采樣率是1KHZ,一段的采樣長度是128個點,overlap是120個點,使用128點的DFT,采用默認的漢明窗。
也就是說,在時間域上,分為了t/8, 這么多個時間段,因為非覆蓋部分是128-120。時間片段分的越細,頻率隨著時間的變化也就越精確。
下面我們來看看,overlap不重疊。下面就是將時間分為了15段。精度是比較差的。
下面再看一個實例
Compute and display the PSD of each segment of a linear chirp that starts at DC and crosses 150 Hz at t = 1 s. Specify a sample rate of 1 kHz, a segment length of 256 samples, and an overlap of 250 samples. Use the default Hamming window and 256 DFT points.
計算并且展示每一段線性chirp信號的PSD,這個信號從直流到在時間1s的時候150HZ,指定采樣率是1KHZ,每一段的長度是256個采樣點,overlap為250個,使用默認的漢明窗口,做256個點的DFT。
上面我們就已經把基本的用法都講解完畢了
下面,我們來看返回參數的spectrogram
其實,我們只要會這句有參數返回值的語法就好:
[S,F,T,P]=spectrogram(x,window,noverlap,nfft,fs)
參考:
https://blog.csdn.net/zhuguorong11/article/details/77801977
k = fix((length(x)-120)/(128-120))
k =235
搞懂參數返回值的意義后,我們再來看如何利用參數返回值進行畫圖
clc; clear; t = 0:0.001:2-0.001; x = chirp(t,0,1,150,'li'); [s,f,T,p]=spectrogram(x,128,120,128,1e3,'yaxis'); figure; plot(x); figure; surf(T,f,10*log10(p),'edgecolor','none'); axis tight; title('linear Chirp'); xlabel('Time (Seconds)'); ylabel('Hz');這里我們要講解一下,這里我們已經得到了返回參數值S F T P 。這四個參數的含義,就不必多說了,具體參考發的鏈接。
下面看一下surf這個函數。
利用surf根據spectrogram的返回參數值繪制三維
surf(X,Y,Z) creates a three-dimensional surface plot. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y. The function also uses Z for the color data, so color is proportional to height.
這個函數用于繪制三維圖,這個函數繪制以Z為高度,以X-Y為平面,這個函數使用Z為顏色數據。
surf(___,Name,Value) specifies surface properties using one or more name-value pair arguments. For example, ‘FaceAlpha’,0.5 creates a semitransparent surface. Specify name-value pairs after all other input arguments.
surf(,Name,Value)使用一個或多個名稱-值對參數指定表面屬性。例如,‘FaceAlpha’,0.5創建一個半透明的表面。在所有其他輸入參數之后指定名稱-值對。
下圖是僅僅使用
surf(T,f,10*log10§);
也就是說以時間軸T為X軸,f為頻率軸,功率譜是10log10§.
Use s to access and modify properties of the surface object after it is created. For example, turn off the display of the edges by setting the EdgeColor property.
s.EdgeColor = ‘none’;
使用上述edgecolor可以關閉邊緣線。
clc; clear; t = 0:0.001:2-0.001; x = chirp(t,0,1,150,'li'); [s,f,T,p]=spectrogram(x,128,120,128,1e3,'yaxis'); figure; plot(x); figure; Q=surf(T,f,10*log10(p)); axis tight; Q.EdgeColor='none'; title('linear Chirp'); xlabel('Time (Seconds)'); ylabel('Hz');總結
以上是生活随笔為你收集整理的matlab---spectrogram短时傅里叶变换与chrip信号的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 记录一次血崩式的CPLD不稳定 bug经
- 下一篇: ISE_软件基本使用流程(win10 的