File:Correlation function.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 765 × 765 pixels, file size: 69 KB)

    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 blue curve is the cross-correlation of a square wave and a cosine template, as the phase lag of the template varies over one cycle. The amplitude and phase at the maximum value are the polar coordinates of one harmonic in the Fourier series expansion of the square wave. The corresponding rectangular coordinates can be determined by evaluating the correlation at just two samples separated by 90°.
    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 source code of this SVG is invalid due to 5 errors.
     This W3C-invalid vector image was created with LibreOffice.
    Gnu Octave source
    InfoField
    click to expand

    This graphic was created with the help of the following Octave script:

      graphics_toolkit gnuplot
      pkg load signal
    #{
    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.
    #}
      set(0, "DefaultAxesTitleFontWeight", "bold")
      set(0, "DefaultAxesFontWeight",      "bold")
      set(0, "DefaultAxesFontSize",        14)
    
      P = 2000;                     % signal duration
      x = 0:P-1;			% sampling times
    
    % Any function will do for the signal.  It needn't be periodic, but a square wave is convenient.
      period=233;			% square wave period
      s = square((x-period*.67)*2*pi/period);
      n = 4;			% a harmonic (any harmonic will do)
    
      num_angles=1000;		% eval the correlation function at 1000 phases
      correl = [];
      phi = (0:1:num_angles-1)/num_angles;
      for m=phi
    % The right-hand side is equivalent to sum(s.*cos(2*pi*(n/P*x - m))
      correl(end+1) = real(sum(s.*exp(-i*2*pi*(n/P*x - m))));
      endfor
    
      figure("position",[1 1 700 700])
      plot(phi*360, correl, "color","b", "linewidth",3)
      xlim([0 360]);
      set(gca, 'xtick', [0 1 2 3 4]*90);
    
      [maxval,idx] = max(correl);
      cossin = sum(s.*exp(i*2*pi*n*x/P))
    % The next two things are equal
      mod(atan2(imag(cossin), real(cossin))*360/(2*pi), 360)
      (idx-1)*360/num_angles
    % The next two things are equal
      maxval
      abs(cossin)
    
      hold on
      stem((idx-1)*360/num_angles, correl(idx), "filled", "linewidth",4, "color",[1 0 1], "markerfacecolor",[1 0 1])
      stem( 0,correl( 0*num_angles/360+1),"filled", "linewidth",4, "color",[1 0 1], "markerfacecolor", [1 0 1])
      stem(90,correl(90*num_angles/360+1),"filled", "linewidth",4, "color",[1 0 1], "markerfacecolor", [1 0 1])
    
      title("Cross-correlation function", "fontsize",14);
      xlabel("phase lag (degrees)",       "fontsize",14)
      ylabel("correlation amplitude",     "fontsize",14)
    

    Captions

    Example of using two points of a correlation function to determine the location and height of its maximum

    Items portrayed in this file

    depicts

    11 April 2022

    image/svg+xml

    09d1bd458779569d05dacbd6a5732edae1476426

    70,305 byte

    765 pixel

    765 pixel

    File history

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

    Date/TimeThumbnailDimensionsUserComment
    current04:19, 12 April 2022Thumbnail for version as of 04:19, 12 April 2022765 × 765 (69 KB)wikimediacommons>Bob KUploaded own work with UploadWizard

    There are no pages that use this file.