zoukankan      html  css  js  c++  java
  • On the use of spectrogram function in matlab

    from http://stackoverflow.com/questions/19161304/on-the-use-of-spectrogram-function-in-matlab

    Consider the following example:

    Fs=40;% sampling frequency
    x =0:(1/Fs):4;% time domain
    y =[sin(2* pi *5* x(x <=2)), sin(2* pi *10* x(x >2))];% signal
    
        N = length(x);%Length of signal
    
        NFFT =2^nextpow2(N);%Next power of 2from length of y
        Y = fft(y,NFFT)/N;
        f =Fs/2*linspace(0,1,NFFT/2+1);%Generate the plot, title and labels.
        fh = figure(1);%set(fh,'color','white','visible','off');
        subplot(311);
        plot(x,y,'k');
        xlabel('Time (s)','FontName','Times New Roman','fontsize',10);
        ylabel('Amplitude','FontName','Times New Roman','fontsize',10);set(gca,'FontName','Times New Roman','fontsize',10);%# Frequency domain plots
        subplot(312);
        plot(f,2*abs(Y(1:NFFT/2+1))) 
        xlabel('Frequency (cycles/second)','FontName','Times New Roman','fontsize',10);
        ylabel('Amplitude','FontName','Times New Roman','fontsize',10);set(gca,'FontName','Times New Roman','fontsize',10);
    
        subplot(313);
        window = x(1:10:end);[S,F,T]= spectrogram(y,window);
        pcolor(T,F,abs(S));shading interp;
        xlabel('Time (s)');
        ylabel('Frequency (cycles/second)');
    

    The STFT (short-time Fourier transform) here does not demonstrate what I expected. I would have expected the y axis to be the same as the xaxis in subplot(312) and the xaxis to be the same as the xaxis in subplot(311).

    edited Oct 3 '13 at 14:30

    Luis Mendo

    asked Oct 3 '13 at 14:01

    KatyB

    1 Answer

    The issue with the x axis is because you are not specifying the sample frequency when calling spectrogram. Try

    [S,F,T]= spectrogram(y,window,[],[],Fs);
    

    Also, I think you are misinterpreting the window argument. It refers to window shape (by the way you define it, maybe you are thinking it defines the window positions?). So I would use something like

    window = ones(1,10);
    

    (or try window shapes other than rectangular).

    As for the y axis, in 313 the y axis is (instantaneous) frequency, whereas in 312 it is spectral amplitude. So they are not comparable. In principle, you could compare the color (z axis) of 313 with the y axis of 312, as both are spectral amplitude; however, their normalization is probably different.

    edited Oct 6 '13 at 18:55

    answered Oct 3 '13 at 14:24

    Luis Mendo



    修改

     subplot(313);

    %     window = x(1:10:end);

        window = ones(1,80);

       [S,f,t,p] = spectrogram(y,window,[],[],Fs);

       surf(t,f,10*log10(abs(p)),'EdgeColor','none');   

         axis xy; axis tight; colormap(jet); view(0,90);

         xlabel('Time');

         ylabel('Frequency (Hz)');

  • 相关阅读:
    BZOJ3514:GERALD07加强版(LCT,主席树)
    BZOJ2729:[HNOI2012]排队(组合数学)
    BZOJ4517:[SDOI2016]排列计数(组合数学,错排公式)
    BZOJ3123:[SDOI2013]森林(主席树,启发式合并)
    BZOJ3786:星系探索(Splay,括号序)
    BZOJ2212:[POI2011]Tree Rotations(线段树合并)
    BZOJ5329:[SDOI2018]战略游戏(圆方树,虚树)
    CF613D:Kingdom and its Cities(树形DP,虚树)
    BZOJ3611:[HEOI2014]大工程(树形DP,虚树)
    BZOJ2286:[SDOI2011]消耗战(树形DP,虚树)
  • 原文地址:https://www.cnblogs.com/gisalameda/p/12840614.html
Copyright © 2011-2022 走看看