This preview shows pages 1–3. Sign up to view the full content.
Sheet1
Page 1
###########################################################################
#
# correlation.py
#
###########################################################################
#
# Introduction
#
# This example covers some basic Python programming techniques,
# such as functions, loops, and lists, which are demonstrated
# in the context of a simple crosscorrelation implementation.
#
###########################################################################
#
# CrossCorrelation
#
# There are several slightly different definitions for correlation.
# Some of the definitions contain normalizing scale factors.
# Different implementations of correlation handle the edges of the vectors
# differently (for example, some implementations zeropad the shorter
# vector in order to make the vectors the same length).
#
# The crosscorrelation in this demo is implemented to behave like
# MATLAB's "xcorr" function. The reason for this is that maintaining
# some consistency with MATLAB will make it easier when switching
# back and forth between MATLAB and Python. The main difference between
# the Python and MATLAB implementations is that Python list indexing
# begins at zero, whereas MATLAB vector indexing begins at one.
#
# Documentation about MATLAB's "xcorr" function can be found here:
# http://www.mathworks.com/access/helpdesk/help/toolbox/signal/xcorr.html
#
###########################################################################
#
# Python Tips
#
# 1. Syntax
#
#
 Unlike C, Python does not use lots of punctuation (such as braces "{}")
#
to group sets of statements. Instead, it uses indentation to determine
#
which statements are contained in constructs such as functions and loops.
#
# 2. Lists
#
#
 Use square brackets "[]" to create lists.
#
(Parentheses "()" are used for tuples, which are similar to lists,
#
but their contents cannot be modified. Use braces "{}" for
#
dictionaries, which are another type of data structure.)
#
#
 Python starts indexing arrays at zero (like C),
#
unlike MATLAB (which starts indexing at one).
#
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentSheet1
Page 2
#
 Lists are one of the most basic data structures in Python.
#
You can index into them like arrays (using the square bracket "[]"
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '10
 Wy
 Python Programming

Click to edit the document details