+ All Categories
Home > Documents > Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

Date post: 06-Jul-2018
Category:
Upload: alvaro-quintana-carvacho
View: 246 times
Download: 0 times
Share this document with a friend

of 25

Transcript
  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    1/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true

    Spectrogram using short-time Fourier transform

    s = spectrogram(x)   example

    s = spectrogram(x,window)

    s = spectrogram(x,window,noverlap)   example

    s =  spectrogram(x,window,noverlap,nfft)   example

    [s,w,t] = spectrogram(  ___ )

    [s,f,t] = spectrogram(  ___ ,fs)   example

    [s,w,t] = spectrogram(x,window,noverlap,w)

    [s,f,t] = spectrogram(x,window,noverlap,f,fs)

    [  ___ ,ps] = spectrogram( ___ )

    [  ___ ] = spectrogram( ___ ,'reassigned')   example

    [  ___ ,ps,fc,tc] = spectrogram( ___ )   example

    [  ___ ] = spectrogram( ___ ,freqrange)

    [  ___ ] = spectrogram( ___ ,spectrumtype)

    [  ___ ] = spectrogram( ___ ,'MinThreshold',thresh)   example

    spectrogram(  ___ )   example

    spectrogram(  ___ ,freqloc)   example

    example

    example

    example

    spectrogram

    Syntax

    Description

    s  = spectrogram(x) returns the short-time Fourier transform of the input signal, x. Each columnof s contains an estimate of the short-term, time-localized frequency content of x.

    s  = spectrogram(x,window) uses window to divide the signal into sections and performwindowing.

    s  = spectrogram(x,window,noverlap) uses noverlap  samples of overlap between adjoiningsections.

    s  = spectrogram(x,window,noverlap,nfft) uses nfft sampling points to calculate thediscrete Fourier transform.

    http://www.mathworks.com/help/signal/ref/spectrogram.html#bultpz_-2http://www.mathworks.com/help/signal/ref/spectrogram.html#bupm9cjhttp://www.mathworks.com/help/signal/ref/spectrogram.html#buvvogkhttp://www.mathworks.com/help/signal/ref/spectrogram.html#bumgty_http://www.mathworks.com/help/signal/ref/spectrogram.html#bupbguuhttp://www.mathworks.com/help/signal/ref/spectrogram.html#buvf01yhttp://www.mathworks.com/help/signal/ref/spectrogram.html#buu60k7http://www.mathworks.com/help/signal/ref/spectrogram.html#buu60jahttp://www.mathworks.com/help/signal/ref/spectrogram.html#bupbguqhttp://www.mathworks.com/help/signal/ref/spectrogram.html#bultpz_-2http://www.mathworks.com/help/signal/ref/spectrogram.html#bupm9cjhttp://www.mathworks.com/help/signal/ref/spectrogram.html#buvvogk

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    2/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 2

    example

    example

    example

    example

    example

    example

    Open This Example

    collapse all

    [s,w,t] = spectrogram(  ___ ) returns a vector of normalized frequencies, w, and a vector of timeinstants, t, at which the spectrogram is computed. This syntax can include any combination of input arguments from previous syntaxes.

    [s,f,t] = spectrogram(  ___ ,fs)  returns a vector of cyclical frequencies, f, expressed in termsof the sample rate, fs.

    [s,w,t] = spectrogram(x,window,noverlap,w) returns the spectrogram at the normalizedfrequencies specified in w.

    [s,f,t] = spectrogram(x,window,noverlap,f,fs) returns the spectrogram at the cyclicalfrequencies specified in f.

    [  ___ ,ps] = spectrogram(  ___ ) also returns a matrix, ps, containing an estimate of the power spectral density (PSD) or the power spectrum of each section.

    [  ___ ] = spectrogram( ___ ,'reassigned') reassigns each PSD or power spectrum estimate tothe location of its center of energy. If your signal contains well-localized temporal or spectralcomponents, then this option generates a sharper spectrogram.

    [  ___ ,ps,fc,tc] = spectrogram(  ___ ) also returns two matrices, fc and tc, containing thefrequency and time of the center of energy of each PSD or power spectrum estimate.

    [  ___ ] = spectrogram( ___ ,freqrange) returns the PSD or power spectrum estimate over thefrequency range specified by freqrange. Valid options for freqrange are 'onesided','twosided', and 'centered'.

    [  ___ ] = spectrogram( ___ ,spectrumtype)  returns PSD estimates if spectrumtype is specifiedas 'psd' and returns power spectrum estimates if spectrumtype is specified as 'power'.

    [  ___ ] = spectrogram( ___ ,'MinThreshold',thresh) sets to zero those elements of ps suchthat 10 log (ps) ≤ thresh. Specify thresh  in decibels.

    spectrogram(  ___ )  with no output arguments plots the spectrogram in the current figure window.

    spectrogram(  ___ ,freqloc) specifies the axis on which to plot the frequency.

    Examples

    Default Values of Spectrogram

    Generate samples of a signal that consists of a sum of sinusoids. Thenormalized frequencies of the sinusoids are rad/sample and rad/sample. Thehigher frequency sinusoid has 10 times the amplitude of the other sinusoid.

    N = 1024;n = 0:N‐1;

    w0 = 2*pi/5;

    x = sin(w0*n)+10*sin(2*w0*n);

    Compute the short-time Fourier transform using the function defaults. Plot the spectrogram.

    s = spectrogram(x);

    spectrogram(x,'yaxis')

    10

    http://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_fhttp://www.mathworks.com/help/signal/ref/spectrogram.html#inputarg_fhttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_fhttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_whttp://www.mathworks.com/help/signal/ref/spectrogram.html#inputarg_whttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_whttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_fhttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_thttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_fhttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_thttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_whttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_thttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_whttp://www.mathworks.com/help/signal/ref/spectrogram.html#bumgty_http://www.mathworks.com/help/signal/ref/spectrogram.html#bupbguuhttp://www.mathworks.com/help/signal/ref/spectrogram.html#buvf01yhttp://www.mathworks.com/help/signal/ref/spectrogram.html#buu60k7http://www.mathworks.com/help/signal/ref/spectrogram.html#buu60jahttp://www.mathworks.com/help/signal/ref/spectrogram.html#bupbguq

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    3/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 3

    Repeat the computation.

    Divide the signal into sections of length .

    Window the sections using a Hamming window.

    Specify 50% overlap between contiguous sections.

    To compute the FFT, use points, where .

    Verify that the two approaches give identical results.

    Nx = length(x);

    nsc = floor(Nx/4.5);

    nov = floor(nsc/2);

    nff = max(256,2^nextpow2(nsc));

    t = spectrogram(x,hamming(nsc),nov,nff);

    maxerr = max(abs(abs(t(:))‐abs(s(:))))

    maxerr =

    0

    Divide the signal into 8 sections of equal length, with 50% overlap between sections. Specify the same FFTlength as in the preceding step. Compute the short-time Fourier transform and verify that it gives the sameresult as the previous two procedures.

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    4/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 4

    Open This Example

    ns = 8;

    ov = 0.5;

    lsc = floor(Nx/(ns‐(ns‐1)*ov));

    t = spectrogram(x,lsc,floor(ov*lsc),nff);

    maxerr = max(abs(abs(t(:))‐abs(s(:))))

    maxerr =

    0

    Frequency Along x -Axis

    Generate a quadratic chirp, x, sampled at 1 kHz for 2 seconds. The frequency of thechirp is 100 Hz initially and crosses 200 Hz at t = 1 s.

    t = 0:0.001:2;

    x = chirp(t,100,1,200,'quadratic');

    Compute and display the spectrogram of x.

    Divide the signal into sections of length 128, windowed with a Hamming window.

    Specify 120 samples of overlap between adjoining sections.

    Evaluate the spectrum at frequencies andtime bins.

    spectrogram(x,128,120,128,1e3)

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    5/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 5

    Replace the Hamming window with a Blackman window. Decrease the overlap to 60 samples. Plot the timeaxis so that its values increase from top to bottom.

    spectrogram(x,blackman(128),60,128,1e3)

    ax = gca;

    ax.YDir = 'reverse';

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    6/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 6

    Open This Example

    Power Spectral Densities of Chirps

    Compute and display the PSD of each segment of a quadratic chirp that starts at 100 Hzand crosses 200 Hz at t  = 1 s. Specify a sample rate of 1 kHz, a segment length of 128samples, and an overlap of 120 samples. Use 128 DFT points and the default Hamming

    window.

    t = 0:0.001:2;

    x = chirp(t,100,1,200,'quadratic');

    spectrogram(x,128,120,128,1e3,'yaxis')

    title('Quadratic Chirp')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    7/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 7

    Compute and display the PSD of each segment of a linear chirp that starts at DC and crosses 150 Hz at t  = 1s. Specify a sample rate of 1 kHz, a segment length of 256 samples, and an overlap of 250 samples. Use thedefault Hamming window and 256 DFT points.

    t = 0:0.001:2;

    x = chirp(t,0,1,150);

    spectrogram(x,256,250,256,1e3,'yaxis')

    title('Linear Chirp')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    8/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 8

    Compute and display the PSD of each segment of a logarithmic chirp sampled at 1 kHz that starts at 20 Hzand crosses 60 Hz at t  = 1 s. Specify a segment length of 256 samples and an overlap of 250 samples. Usethe default Hamming window and 256 DFT points.

    t = 0:0.001:2;

    x = chirp(t,20,1,60,'logarithmic');

    spectrogram(x,256,250,[],1e3,'yaxis')

    title('Logarithmic Chirp')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    9/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 9

    Use a logarithmic scale for the frequency axis. The spectrogram becomes a line.

    ax = gca;

    ax.YScale = 'log';

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    10/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 10

    Open This Example

    Spectrogram and Instantaneous Frequency

    Use the spectrogram function to measure and track the instantaneous frequency of asignal.

    Generate a quadratic chirp sampled at 1 kHz for two seconds. Specify the chirp so that its frequency is initially100 Hz and increases to 200 Hz after one second.

    Fs = 1000;

    t = 0:1/Fs:2‐1/Fs;

    y = chirp(t,100,1,200,'quadratic');

    Estimate the spectrum of the chirp using the short-time Fourier transform implemented in the spectrogramfunction. Divide the signal into sections of length 100, windowed with a Hamming window. Specify 80 samplesof overlap between adjoining sect ions and evaluate the spectrum at frequencies. Suppressthe default color bar.

    spectrogram(y,100,80,100,Fs,'yaxis')

    view(‐77,72)

    shading interp 

    colorbar off 

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    11/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 1

    Track the chirp frequency by finding the maximum of the power spectral density at each of the time points. View the spectrogram as a two-dimensional graphic. Restore the

    color bar.

    [s,f,t,p] = spectrogram(y,100,80,100,Fs);

    [q,nd] = max(10*log10(p));

    hold on 

    plot3(t,f(nd),q,'r','linewidth',4)

    hold off 

    colorbar

    view(2)

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    12/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 12

    Open This Example

    Reassigned Spectrogram of Quadratic Chirp

    Generate a chirp signal sampled for 2 seconds at 1 kHz. Specify the chirp so that itsfrequency is initially 100 Hz and increases to 200 Hz after 1 second.

    Fs = 1000;

    t = 0:1/Fs:2;

    y = chirp(t,100,1,200,'quadratic');

    Estimate the reassigned spectrogram of the signal.

    Divide the signal into sections of length 128, windowed with a Kaiser window with shape parameter .

    Specify 120 samples of overlap between adjoining sections.

    Evaluate the spectrum at frequencies and timebins.

    spectrogram(y,kaiser(128,18),120,128,Fs,'reassigned','yaxis')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    13/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 13

    Open This Example

    Spectrogram with Threshold

    Generate a chirp signal sampled for 2 seconds at 1 kHz. Specify the chirp so that itsfrequency is initially 100 Hz and increases to 200 Hz after 1 second.

    Fs = 1000;

    t = 0:1/Fs:2;

    y = chirp(t,100,1,200,'quadratic');

    Estimate the time-dependent power spectral density (PSD) of the signal.

    Divide the signal into sections of length 128, windowed with a Kaiser window with shape parameter .

    Specify 120 samples of overlap between adjoining sections.

    Evaluate the spectrum at frequencies and timebins.

    Output the frequency and time of the center of gravity of each PSD estimate. Set to zero those elements of the PSD smaller than dB.

    [~,~,~,pxx,fc,tc] = spectrogram(y,kaiser(128,18),120,128,Fs, ... 

    'MinThreshold',‐30);

    Plot the nonzero elements as functions of the center-of-gravity frequencies and times.

    plot(tc(pxx>0),fc(pxx>0),'.')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    14/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 14

    Open This Example

    Spectrogram Reassignment and Thresholding

    Generate a signal sampled at 1024 Hz for 2 seconds.

    nSamp = 2048;Fs = 1024;

    t = (0:nSamp‐1)'/Fs;

    During the first second, the signal consists of a 400 Hz sinusoid and a concave quadratic chirp. Specify thechirp so that it is symmetric about the interval midpoint, starting and ending at a frequency of 250 Hz andattaining a minimum of 150 Hz.

    t1 = t(1:nSamp/2);

    x11 = sin(2*pi*400*t1);

    x12 = chirp(t1‐t1(nSamp/4),150,nSamp/Fs,1750,'quadratic');x1 = x11+x12;

    The rest of the signal consists of two linear chirps of decreasing frequency. One chirp has an initial frequencyof 250 Hz that decreases to 100 Hz. The other chirp has an initial frequency of 400 Hz that decreases to 250Hz.

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    15/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 15

    t2 = t(nSamp/2+1:nSamp);

    x21 = chirp(t2,400,nSamp/Fs,100);

    x22 = chirp(t2,550,nSamp/Fs,250);

    x2 = x21+x22;

     Add white Gaussian noise to the signal. Specify a s ignal-to-noise ratio of 20 dB. Reset the random number generator for reproducible results.

    SNR = 20;

    rng('default')

    sig = [x1;x2];

    sig = sig + randn(size(sig))*std(sig)/db2mag(SNR);

    Compute and plot the spectrogram of the signal. Specify a Kaiser window of length 63 with a shape parameter , 10 fewer samples of overlap between adjacent segments, and an FFT length of 256.

    nwin = 63;

    wind = kaiser(nwin,17);nlap = nwin‐10;

    nfft = 256;

    spectrogram(sig,wind,nlap,nfft,Fs,'yaxis')

    Threshold the spectrogram so that any elements with values smaller than the SNR are set to zero.

    spectrogram(sig,wind,nlap,nfft,Fs,'MinThreshold',‐SNR,'yaxis')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    16/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 16

    Reassign each PSD estimate to the location of its center of energy.

    spectrogram(sig,wind,nlap,nfft,Fs,'reassign','yaxis')

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    17/25

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    18/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 18

    Open This Example

    Track Chirps in Audio Signal

    Load an audio signal that contains two decreasing chirps and a wideband splatter sound.Compute the short-time Fourier transform. Divide the waveform into 400-samplesegments with 300-sample overlap. Plot the spectrogram.

    load splat 

    % To hear, type soundsc(y,Fs) 

    sg = 400;

    ov = 300;

    spectrogram(y,sg,ov,[],Fs,'yaxis')

    colormap bone 

    Use the spectrogram function to output the power spectral density (PSD) of the signal.

    [s,f,t,p] = spectrogram(y,sg,ov,[],Fs);

    Track the two chirps using the medfreq function. To find the stronger, low-frequency chirp, restrict the searchto frequencies above 100 Hz and to times before the start of the wideband sound.

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    19/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 19

    Open This Example

    f1 = f > 100;

    t1 = t < 0.75;

    m1 = medfreq(p(f1,t1),f(f1));

    To find the faint high-frequency chirp, restrict the search to frequencies above 2500 Hz and to times between0.3 seconds and 0.65 seconds.

    f2 = f > 2500;

    t2 = t > 0.3 & t < 0.65;

    m2 = medfreq(p(f2,t2),f(f2));

    Overlay the result on the spectrogram. Divide the frequency values by 1000 to express them in kHz.

    hold on 

    plot(t(t1),m1/1000,'linewidth',4)

    plot(t(t2),m2/1000,'linewidth',4)

    hold off 

    3D Spectrogram Visualization

    Generate two seconds of a signal sampled at 10 kHz. Specify the instantaneousfrequency of the signal as a triangular function of time.

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    20/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 20

    fs = 10e3;

    t = 0:1/fs:2;

    x1 = vco(sawtooth(2*pi*t,0.5),[0.1 0.4]*fs,fs);

    Compute and plot the spectrogram of the signal. Use a Kaiser window of length 256 and shape parameter . Specify 220 samples of section-to-section overlap and 512 DFT points. Plot the frequency on the y -

    axis. Use the default colormap and view.

    spectrogram(x1,kaiser(256,5),220,512,fs,'yaxis')

    Change the view to display the spectrogram as a waterfall plot. Set the colormap to bone.

    colormap bone 

    view(‐45,65)

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    21/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 2

    collapse all

    Related Examples

    Formant Estimation with LPC Coefficients

    Input Arguments

    x — Input signal

    vector 

    Input signal, specified as a row or column vector.

    Example: cos(pi/4*(0:159))+randn(1,160) specifies a sinusoid embedded in white Gaussian noise.

    Data Types: single | double Complex Number Support: Yes

    window — Windowinteger | vector | []

    Window, specified as an integer or as a row or column vector. Use window  to divide the signal into sections:

    If window is an integer, then spectrogram  divides x  into sections of length window and windows eachsection with a Hamming window of that length.

    If window  is a vector, then spectrogram  divides x  into sections of the same length as the vector andwindows each section using window.

    If the length of x cannot be divided exactly into an integer number of sections with noverlap  overlappingsamples, then x is truncated accordingly.

    http://www.mathworks.com/help/signal/ug/formant-estimation-with-lpc-coefficients.html

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    22/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 22

    If you specify window as empty, then spectrogram uses a Hamming window such that x is divided into eightsections with noverlap overlapping samples.

    For a list of available windows, see Windows.

    Example: hann(N+1) and (1‐cos(2*pi*(0:N)'/N))/2 both specify a Hann window of length N + 1.

    Data Types: single | double

    noverlap — Number of overlapped samplespositive integer | []

    Number of overlapped samples, specified as a positive integer.

    If window  is scalar, then noverlap must be smaller than window.

    If window  is a vector, then noverlap must be smaller than the length of window.

    If you specify noverlap as empty, then spectrogram uses a number that produces 50% overlap betweensections. If the section length is unspecified, the function sets noverlap  to ⌊N  /4.5⌋, where N   is the length of the input signal.

    Data Types: double | single

    nfft — Number of DFT points

    positive integer scalar | []

    Number of DFT points, specified as a positive integer scalar. If you specify nfft as empty, then spectrogramsets the parameter to max(256,2 ), where p = ⌈log N  ⌉ for an input signal of length N  .

    Data Types: single | double

    w  — Normalized frequencies

    vector 

    Normalized frequencies, specified as a vector. w must have at least two elements. Normalized frequencies arein rad/sample.

    Example: pi./[2 4]

    Data Types: double | single

    f — Cyclical frequencies

    vector 

    Cyclical frequencies, specified as a vector. f must have at least two elements. The units of f are specified bythe sample rate, fs.

    Data Types: double | single

    fs — Sample rate

    1 Hz (default) | positive scalar 

    Sample rate, specified as a positive scalar. The sample rate is the number of samples per unit time. If the unitof time is seconds, then the sampling frequency is in Hz.

     x x 

     p2   x x 

    http://www.mathworks.com/help/signal/ug/windows.html

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    23/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 23

    Data Types: double | single

    freqrange — Frequency range for PSD estimate

    'onesided' | 'twosided' | 'centered'

    Frequency range for the PSD estimate, specified as 'onesided', 'twosided', or 'centered'. For real-valued signals, the default is 'onesided'. For complex-valued signals, the default is 'twosided', andspecifying 'onesided' results in an error.

    'onesided' — returns the one-sided spectrogram of a real input signal. If nfft  is even, then ps has lengthnfft/2 + 1 and is computed over the interval [0, π ] rad/sample. If nfft is odd, then ps has length(nfft + 1)/2 and the interval is [0, π ) rad/sample. If you specify fs, then the intervals are respectively[0, fs/2] cycles/unit time and [0, fs/2) cycles/unit time.

    'twosided' — returns the two-sided spectrogram of a real or complex signal. ps has length nfft and iscomputed over the interval [0, 2π ) rad/sample. If you specify fs, then the interval is [0, fs) cycles/unittime.

    'centered' — returns the centered two-sided spectrogram for a real or complex signal. ps has lengthnfft. If nfft  is even, then ps is computed over the interval (–π , π ] rad/sample. If nfft is odd, then ps iscomputed over (–π , π ) rad/sample. If you specify fs, then the intervals are respectively

    (–fs/2, fs/2] cycles/unit time and (–fs/2, fs/2) cycles/unit time.

    Data Types: char

    spectrumtype — Power spectrum scaling

    'psd' (default) | 'power'

    Power spectrum scaling, specified as 'psd' or 'power'.

    Omitting spectrumtype, or specifying 'psd', returns the power spectral density.

    Specifying 'power' scales each estimate of the PSD by the equivalent noise bandwidth of the window.

    The result is an estimate of the power at each frequency. If the 'reassigned' option is on, the functionintegrates the PSD over the width of each frequency bin before reassigning.

    Data Types: char

    thresh — Threshold

    ‐Inf (default) | real scalar 

    Threshold, specified as a real scalar expressed in decibels. spectrogram sets to zero those elements of pssuch that 10 log (ps) ≤ thresh.

    freqloc — Frequency display axis'xaxis'  (default) | 'yaxis'

    Frequency display axis, specified as 'xaxis' or 'yaxis'.

    'xaxis' — displays frequency on the x -axis and time on the y -axis.

    'yaxis' — displays frequency on the y -axis and time on the x -axis.

    This argument is ignored if you call spectrogram with output arguments.

    Data Types: char

    10

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    24/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    http://www.mathworks.com/help/signal/ref/spectrogram.html?refresh=true 24

    ˗

    ˗

    collapse allOutput Arguments

    s — Short-time Fourier transform

    matrix

    Short-time Fourier transform, returned as a matrix. Time increases across the columns of s and frequencyincreases down the rows, starting from zero.

    If x is a signal of length N  , then s has k  columns, where

    k  = ⌊(N   – noverlap)/(window – noverlap)⌋  if window is a scalar 

    k  = ⌊(N   – noverlap)/(length(window) – noverlap)⌋ if window  is a vector.

    If x  is real and nfft  is even, then s has (nfft/2 + 1) rows.

    If x  is real and nfft is odd, then s has (nfft + 1)/2 rows.

    If x is complex, then s has nfft  rows.

    Data Types: double | single

    w  — Normalized frequencies

    vector 

    Normalized frequencies, returned as a vector. w has a length equal to the number of rows of s.

    Data Types: double | single

    t — Time instants

    vector 

    Time instants, returned as a vector. The time values in t correspond to the midpoint of each section.

    Data Types: double | single

    f — Cyclical frequencies

    vector 

    Cyclical frequencies, returned as a vector. f has a length equal to the number of rows of s.

    Data Types: double | single

    ps — Power spectral density or power spectrum

    matrix

    Power spectral density (PSD) or power spectrum, returned as a matrix.

    If x is real, then ps contains the one-sided modified periodogram estimate of the PSD or power spectrum of each section.

    If x  is complex, or if you specify a vector of frequencies, then ps contains the two-sided modifiedperiodogram estimate of the PSD or power spectrum of each section.

    Data Types: double | single

    fc,tc  — Center-of-energy frequencies and times

     x 

     x 

     x 

    http://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_fhttp://www.mathworks.com/help/signal/ref/spectrogram.html#outputarg_w

  • 8/17/2019 Spectrogram using short-time Fourier transform - MATLAB spectrogram.pdf

    25/25

    2/5/2016 Spectrogram using short- time Four ier transform - MATLAB spectrogram

    collapse all

    matrices

    Center-of-energy frequencies and times, returned as matrices of the same size as the short-time Fourier transform. If you do not specify a sample rate, then the elements of fc are returned as normalizedfrequencies.

    More About

    Tips

    If a short-time Fourier transform has zeros, its conversion to decibels results in negative infinities that cannotbe plotted. To avoid this potential difficulty, spectrogram adds eps to the short-time Fourier transform whenyou call it with no output arguments.

    References

    [1] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing . 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999.

    [2] Rabiner, Lawrence R., and Ronald W. Schafer. Digital Processing of Speech Signals. Englewood Cliffs, NJ:Prentice-Hall, 1978.

    [3] Chassande-Motin, Éric, François Auger, and Patrick Flandrin. "Reassignment." In Time-Frequency Analysis:Concepts and Methods. Edited by Franz Hlawatsch and François Auger. London: ISTE/John Wiley and Sons,2008.

    [4] Fulop, Sean A., and Kelly Fitz. "Algorithms for computing the time-corrected instantaneous frequency(reassigned) spectrogram, with applications." Journal of the Acoustical Society of America. Vol. 119, January2006, pp. 360–371.

    See Also

    goertzel  | periodogram  | pwelch

    Introduced before R2006a

    http://www.mathworks.com/help/signal/ref/pwelch.htmlhttp://www.mathworks.com/help/signal/ref/periodogram.htmlhttp://www.mathworks.com/help/signal/ref/goertzel.html

Recommended