File:Comparison of spectral leakage of several window functions.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 1,750 × 750 pixels, file size: 3.79 MB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: The spectral leakage of several window functions are plotted on the same coordinate system for comparison.
    Date
    Source Own work
    Author Bob K
    Permission
    (Reusing this file)
    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    SVG development
    InfoField
     The SVG code is valid.
    V
     This vector image was created with GNU Octave.
    Gnu Octave source
    InfoField
    click to expand
      graphics_toolkit gnuplot
    #{
    The gnuplot graphics toolkit is not actively maintained and has a number
    of limitations that are unlikely to be fixed.  Communication with gnuplot
    uses a one-directional pipe and limited information is passed back to the
    Octave interpreter so most changes made interactively in the plot window
    will not be reflected in the graphics properties managed by Octave.  For
    example, if the plot window is closed with a mouse click, Octave will not
    be notified and will not update its internal list of open figure windows.
    The qt toolkit is recommended instead.
    #}
    % Just a bunch of defaults copied from File:Window_function_and_frequency_response_-_Rectangular.svg
    set(0, "DefaultAxesFontName", "Microsoft Sans Serif")
    set(0, "DefaultTextFontName", "Microsoft Sans Serif") 
    set(0, "DefaultAxesTitleFontWeight", "bold")
    set(0, "DefaultAxesFontWeight",      "bold")
    set(0, "DefaultAxesFontSize", 14)
    set(0, "DefaultAxesLineWidth", 2)
    set(0, "DefaultAxesBox", "on")
    set(0, "DefaultAxesGridLineStyle", "-")
    set(0, "DefaultAxesGridColor", [0 0 0])  	% black
    set(0, "DefaultAxesGridAlpha", 0.1)		% opaqueness of grid
    set(0, "DefaultAxesLayer", "bottom")     	% grid not visible where overlapped by graph
    
    M = 2^12;   				% interpolation factor
    % An unusually large number is needed to resolve the first null of the Tukey window
    
    DFT_length = 2^10;
    window_length = DFT_length + 1;
    DTFT_length = M*DFT_length;
    dr = 100; 				% dynamic range
    % These are the indices of the DTFT array that will be plotted logarithmically
    a = M/4 : DTFT_length/2;
    
    % These are the bin numbers to be assigned to the indices
    x = (a-1)/M;
    
    n = 2*pi*(0:DFT_length-1)/DFT_length;
    
    %============================================
    % Rectangular window
    window = ones(1,DFT_length);
    window(1) = 2*window(1);	% periodic summation
    
    H = abs(fft(window, DTFT_length));
    H = H(a);
    
    H = H/max(H);
    H = 20*log10(H);
    H = max(-dr,H);
    
    figure("position", [1 1 1400 600])
    semilogx(x, H, "color","black", "linewidth",1)
    xlim([.25 20])		% display only 20 bins
    ylim([-dr 2])
    set(gca,"XTick", [.5 1:10])
    set(gca,"XTickLabel",[".5"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"; "10"])
    set(gca, "ygrid", "on");
    
    ylabel("dB", "FontSize",14, "FontWeight","bold")  
    xlabel("DFT bins", "FontSize",14, "FontWeight","bold")
    title("Spectral leakage of several window functions", "FontSize",20)
    hold on
    
    %============================================
    % Hann window
    window = 0.5 - 0.5*cos(n);
    window(1) = 2*window(1);	% periodic summation
    H = abs(fft(window, DTFT_length));
    H = H(a);
    
    H = H/max(H);
    H = 20*log10(H);
    H = max(-dr,H);
    semilogx(x, H, "color","red", "linewidth",1)
    
    %============================================
    % Hamming window
    window = 0.53836 - 0.46164*cos(n);
    window(1) = 2*window(1);	% periodic summation
    H = abs(fft(window, DTFT_length));
    H = H(a);
    
    H = H/max(H);
    H = 20*log10(H);
    H = max(-dr,H);
    semilogx(x, H, "color","blue", "linewidth",1)
    
    %============================================
    % Tukey window
    alpha = 0.5;
    b = alpha*DFT_length/2;
    window = ones(1,window_length);
    m = 0 : b;
    if( max(m) == b )
      m = m(1:end-1);
    endif
    M = length(m);
    window(1:M) = 0.5*(1-cos(pi*m/b));
    window(window_length:-1:window_length-M+1) = window(1:M);
    
    window(1) = 2*window(1);	% periodic summation
    window = window(1:end-1);
    H = abs(fft(window, DTFT_length));
    H = H(a);
    
    H = H/max(H);
    H = 20*log10(H);
    H = max(-dr,H);
    dark_green = [0 128 0]/256;
    semilogx(x, H, "color",dark_green, "linewidth",2)
    
    %============================================
    % Blackman window
    window = 0.42 - 0.5*cos(n) + 0.08*cos(2*n);
    window(1) = 2*window(1);	% periodic summation
    H = abs(fft(window, DTFT_length));
    H = H(a);
    
    H = H/max(H);
    H = 20*log10(H);
    H = max(-dr,H);
    gold = [251 159 3]/256;
    semilogx(x, H, "color",gold, "linewidth",2)
    
    %============================================
    % Flat top window
    b = [0.21557895 0.41663158 0.277263158 0.083578947 0.006947368];
    window = b(1) - b(2)*cos(n) + b(3)*cos(2*n) -b(4)*cos(3*n) +b(5)*cos(4*n);
    window(1) = 2*window(1);	% periodic summation
    H = abs(fft(window, DTFT_length));
    H = H(a);
    
    H = H/max(H);
    H = 20*log10(H);
    H = max(-dr,H);
    semilogx(x, H, "color","magenta", "linewidth",2)
    
    h = legend(['rectangular'],...
               ['hann'],...
               ['hamming'],...
               ['tukey'],...
               ['blackman'],...
               ['flattop'],...
               "location","west");
    legend boxoff
    set(h, "fontsize",16);
    

    Captions

    The spectral leakage of several window functions are plotted on the same coordinate system for comparison.

    Items portrayed in this file

    depicts

    1 May 2022

    image/svg+xml

    1845502a673ee569f1a89c513b609ff3f658bf26

    3,972,356 byte

    750 pixel

    1,750 pixel

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current12:47, 1 May 2022Thumbnail for version as of 12:47, 1 May 20221,750 × 750 (3.79 MB)wikimediacommons>Bob Kenlarge legend and add a tick at x=.5

    There are no pages that use this file.