[Matlab] Specgram

** 아래 그림은 explore에서는 안보일 수 있습니다 **

원문 : http://ece.uprm.edu/~caceros/stft/specgram.htm

Specgram 및 Specgramdemo 함수를 통한 Time-dependent frequency analysis
Specgram 함수는 한정된 시간동안의 signal을 특정 sampling rate로 STFT 분석을 시행한다.

Input parameters
specgram은 a vector를 반드시 필요로 하며, 나머지 값들은 specified되거나, 입력하지 않을 경우 default value를 사용한다.

specgram(a,nfft,fs,window,numoverlap)

a : input singal vector

nfft : specgram에서 사용할 FFT의 사이즈 (default value : min(256, length(a)))

fs : vector a의 sampling frequency (default value : 2)

window : nfff space에서 사용될 windowing function (default : nfff length에 대한 periodec Hann (Hanning) window)



주의사항 : length(window) < nfff

numoverlap : 이전 window와 얼만큼 overlap 되는지 (default : length(window)/2)
주의사항 : numoverlap < length(window)



nfff 가 window의 length보다 클 경우 zero padding된다.

Output values:
FFT를 시행한 값들은 matrix B에 저장된다.
matrix B는 가로열에는 t1, t2, t3….tk
세로열에는 f1, f2, f3…fnttt



k, 총 구간 수를 의미, 아래의 식으로 표현된다.
n은 vector a의 length

여기서 생각해봐야 하는 것은 k의 수가 nfft 값에 의존하는 것이 아니라는 점이다.
nfff는 사용하기로 결정한 주파수 해상도에 영향을 미칠 뿐이다.

length(window)<=nfft 이므로 FFT를 시행 후 반환되는 vector는 length (window) + zeropadding된 값의 길이와 같다.

vector f 는 FFT로 계산된 frequency값들을 포함한다. length는 input시 지정된 nfft값과 같다.

Here there are some examples of syntax:
 
specgram(a)                                                      This makes the specgram of a with default values.
                                                                        nfft=min(256,length(a)).
                                                                        fs=2.
                                                                        window=hann(nfft).
                                                                        numoverlap= length(window)/2.

B = specgram(a)                                               This assigns the ouput of the specgram to the matrix B.
                                                                        nfft=min(256,length(a)).

B = specgram(a,nfft)                                         This makes a specgram at specified value nfft. 
If nfft=256 then is equal to the one before.

[B,f] = specgram(a,nfft,fs)                                 Here the frequency output vector is returned.
                                                                        And the Sampling frequency is specified.
 
[B,f,t] = specgram(a,nfft,fs)                               Here the time vector is returned.
 
B = specgram(a,nfft,fs,window)                         Here a window is specified.
 
B = specgram(a,nfft,fs,window,numoverlap)        Here an overlap is specified.


Example:

note1 = sin([1:16000*0.5]*2*pi*440/16000)
note2 = sin([1:16000*0.5]*2*pi*880/16000)
note3 = sin([1:16000*0.5]*2*pi*1600/16000)

specgram([note1 note2 note3],256,16000,hann(256),100);

specgram([note1 note2 note3],512,16000,hann(256),100);

pecgram([note1 note2 note3],512,16000,hann(512),100);


Fig. 1. 과 Fig. 2.의 차이는 nfft의 숫자의 차이이다. resolution이 조금 더 높아진 것을 볼 수 있다.
Fig. 2. 와 Fig. 3.의 차이는 window length의 차이이다. 주파수가 조금더 specified된 것을 볼 수 있으나 중간에 overlap은 조금 더 넓어 보인다. 이것은 k를 구하는 식에서 분모가 커졌기 때문이다.

Frequency가 8000까지 구해지는 이유는 nyquist 정리에 의해 16000Hz의 값으로 구할 수 있는 최대 주파수는 1/2인 8000이기 때문이다.   fs를 8000으로 할 경우 Frequency는 절반으로 줄어들며 time은 두배로 늘어나게 된다.


Tip:
sin 함수로 음(note) 만들기

rf = 44100 (Hz)
t = 0:1/rf:5;
y = sin(2*pi*440*t);

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.