Wednesday, November 28, 2012

Visualizing Wave Packets Lab

Gaussian Function Plot:

from pylab import *
center = 2
sigma = 2
coeff = 1 / sqrt(2*pi)*sigma
gauss_list = []

for x in arange(-10,10,0.1):
    gauss = coeff * exp(-(x - center)**2/(2. * sigma**2))
    gauss_list.append(gauss)
    print gauss
plot(gauss_list)
show()

Gaussian Function centered at 2 with Standard Deviation of 2

Sinusoidal Function Plot:

from pylab import *
A = 2
k = 1
sine_list = []
#coeff = 1 / sqrt(2*pi)*sigma

for x in arange(-3.14,3.14,0.1):
    f = A*sin(k*x)
    sine_list.append(f)
    print f
plot(sine_list)
show()

Single Sine function with Amplitude = 2 and k = 1

Multiple Sine Functions:

from pylab import *
A = 2
w = 1

for i in range (1,5):
    x = []
    sine_function = []
    for t in arange(-3.14,3.14,0.01):
        sine_f = A*sin(i*w*t)
        sine_function.append(sine_f)
        x.append(t)
    plot(x,sine_function)
show()

First 4 harmonics

Sinusoidal Superposition - Fourier Synthesis:


from pylab import *
A = 2
w = 1
Fourier_Series = []

for i in range (1,5):
    x = []
    sine_function = []
    for t in arange(-3.14,3.14,0.01):
        sine_f = A*sin(i*w*t)
        sine_function.append(sine_f)
        x.append(t)
    #plot(x,sine_function)
    Fourier_Series.append(sine_function)

superposition = zeros(len(sine_function))

for function in Fourier_Series:
    for i in range(len(function)):
        superposition[i]+= function[i]
      
plot(x,superposition)
show()

Superposition of first 4 harmonics

Now, for the first 19 harmonics;

from pylab import *
A = 2
w = 1
Fourier_Series = []

for i in range (1,20):
    x = []
    sine_function = []
    for t in arange(-3.14,3.14,0.01):
        sine_f = A*sin(i*w*t)
        sine_function.append(sine_f)
        x.append(t)
    #plot(x,sine_function)
    Fourier_Series.append(sine_function)

superposition = zeros(len(sine_function))

for function in Fourier_Series:
    for i in range(len(function)):
        superposition[i]+= function[i]
       
plot(x,superposition)
show()

Superposition of the first 19 harmonics

We can see that the more harmonics we add up, we can begin to see that the wave function starts to localize. If we had an infinite number of harmonics, the ripples would 'disappear'.


Gaussian Wave Packet:

from pylab import*
center = 3
sigma = 1
coeff = 1 / sqrt(2*pi)*sigma

A = 1
w = 1
Fourier_Series = []

for i in range (1,6):
    x = []
    sine_function = []
    A = coeff*exp(-(i-center)**2/(2.*sigma**2))

for t in arange(-3.14,3.14,0.01):
    sine_f = A*sin(i*w*t)
    sine_function.append(sine_f)
    x.append(t)
    Fourier_Series.append(sine_function)

superposition = zeros(len(sine_function))

for function in Fourier_Series:
    for i in range(len(function)):
        superposition[i]+= function [i]

plot(x,superposition)
show()

Gaussian centered at harmonic 3

No comments:

Post a Comment