You are on page 1of 5

1

Using MATLAB to generate waveforms, plotting level curves and


Fourier expansions. Task 1.

CONTENTS

1.
2.
3.

Formulation
The task for computations
Example

1. FORMULATION

One of the basic applications of the sine and cosine functions is simple harmonic motion. An
object displays harmonic motion if its motion is modeled by a sine or cosine function, y(t) =
A sin(t + ) + d or y(t) = A cos(t + ) + d where y is the displacement from a point of reference,
usually the rest position, and t is time. The rest position is the place where the object would
naturally stay in place; but since the object is actually in motion it is moving though its rest
position.

Figure 1: Simple Harmonic Motion

Many objects have simple harmonic motion. We consider examples which have only simple
harmonic fluctuations (when there is no friction).
The interpretation of the characteristics of the sinusoidal wave is:
Amplitude A: the maximum distance from the rest position that the object moves.
Period T : time it takes the object to complete 1 cycle, a graphical period.
Phase Shift: the time difference from t = 0 to the start of the 1st cycle. The phase shift is usually
not used unless we are comparing 2 objects in harmonic motion.
Vertical Shift: The distance from the rest position to the reference point, i.e. ground level. The
vertical shift is usually not used since the rest position is usually used as the reference point.
A quantity related to the period is frequency. The frequency is the number of cycles per time
unit. Thus, if the frequency = f , then
f=

1
1

1
=
=
=
T
period
2/
2

and

2f = .

The units for frequency is hertz,


1 hertz = 1 hz = 1

cycle
second

So while the period is a measure of the amount of time per cycle, the frequency is a measure of
the number of cycles per time. Sometimes the functions for simple harmonic motion are written as
y = a sin(2f t + ) + d and y = a cos(2f t + ) + d to show the frequency.

And now lets introduce the concept of simple harmonic oscillator.


A simple harmonic oscillator is an oscillator that is neither driven nor damped. It consists of
a mass m, which experiences a single force, F , which pulls the mass in the direction of the point
x = 0 and depends only on the masss position x and a constant k. Balance of forces (Newtons
second law) for the system is
d2 x
dt2
Solving this differential equation, we find that the motion is described by the function
F = ma = m

x(t) = A cos (t + ) ,
where

k
2
=
.
m
T
The motion is periodic, repeating itself in a sinusoidal fashion with constant amplitude, A. In
addition to its amplitude, the motion of a simple harmonic oscillator is characterized by its period
T, the time for a single oscillation or its frequency f = T1 , the number of cycles per unit time. The
position at a given time t also depends on the phase, , which determines the starting point on
the sine wave. The period and frequency are determined by the size of the mass m and the force
constant k, while the amplitude and phase are determined by the starting position and velocity.
The velocity and acceleration of a simple harmonic oscillator oscillate with the same frequency
as the position but with shifted phases. The velocity is maximum for zero displacement, while the
acceleration is in the opposite direction as the displacement.
The potential energy stored in a simple harmonic oscillator at position x is
=

1
U = kx2 .
2
A waveform is the shape and form of a signal such as a wave moving in a physical medium or
an abstract representation.
In many cases the medium in which the wave is being propagated does not permit a direct
visual image of the form. In these cases, the term waveform refers to the shape of a graph of
the varying quantity against time or distance. An instrument called an oscilloscope can be used to
pictorially represent a wave as a repeating image on a screen. By extension, the term waveform
also describes the shape of the graph of any varying quantity against time.
Vector diagrams can be used to refer to Fourier series. The Fourier series describes the decomposition of periodic waveforms, such that any periodic waveform can be formed by the sum
of a (possibly infinite) set of fundamental and harmonic components. Finite-energy non-periodic
waveforms can be analyzed into sinusoids by the Fourier transform.
2. TASK FOR COMPUTATIONS

Exercise I
Study first theoretical introduction to the laboratory work and the definition of the harmonic
oscillator according to http : //en.wikipedia.org/wiki/Harmonic oscillator.
It is necessary to simulate harmonic oscillators using MATLAB. To do this, write a program
(a MATLAB code) that visualizes functions specified in the particular task with a given set of
parameters (option).
You need to identify and demonstrate the changes of graphs behavior for the variable system parameters (amplitude, frequency, initial phase).
1) Create a function sig1 = A1 sin(f1 t) + A2 sin(f2 t) + A3 sin(f3 t + ), where A1 = 0.03,
A3 = 1, f2 = 5000, f3 = 2000, = 4 . Values A2 and f1 are given as free parameters, in order to
monitor for changes in graphs behavior.
2) Plot sig1 in the interval containing three periods for two different values of A2 , f1 , and of
your own.
3) Save the plots as two different figures (.jpg files).
4) Make clear figure captions that indicate the form of the function and values of all parameters.

5) Analyze the results in the report using the Example below as a sample text.
Exercise II
Let
F (x) Sn = a1 sin

 x 
a


+ a2 sin

2x
a


+ + an sin

 nx 
a

n
X


aj sin

j=1

jx
a

be the first n terms of the sine Fourier serie for a given function F (x), x (a, a).
For the cosine Fourier serie,


n
X
jx
G(x) Cn =
aj cos
a
j=0

For the given a > 0, n > 2, and Fourier coefficients aj , plot all the graphs of S1 , . . . Sn , or C1 ,
. . . Cn , try to plot all in different colors on the same graph. Analyze the results, save the figures
as .jpg files and make clear figure captions that specify all the used quantities and parameter values.
f (x) = x, a = , n = 1, 2, 3, 4. Sn = S4 = 2 sin(x) sin(2x) + 32 sin(3x) 12 sin(4x).
Exercise III
Determine the periods with respect to X and Y and plot on the same figure the level curves of
the functions F1 and F2 . Save figures as .jpg files.
Fn [X, Y ] = An sin(aX) cos(bn Y ), n = 1, 2, a = 3, b1 = 1, b2 = 4, A1 = 4, A2 = 0.5,
0 < X < a , 4 < Y < 4 for F1 and 4 < Y < 8 for F2 .
3. EXAMPLE

Exercise I A MATLAB function sig = A1 cos(f1 t) + A2 cos(f2 t) is created using a MATLAB


code below.
Programm file:
function [ ] = sig( A1 , f1 , A2 , f2 )
Create a time vector
t=0:0.05e-3:5e-3;
Form the signal vector
sig1 = A1 . (cos(pi. f1 . t));
sig2 = A2 . (cos(pi. f2 . t));
sig = sig1 + sig2;
sigfft = fft(sig);
Plot the signal
plot(t,sig,t,sigfft);
Label graph and axes
title(0 sig = A1 cos(f1 t) + A2 cos(f2 t)0 );
xlabel(0 time0 );
ylabel(0 sig0 );
We fix frequency f1 of the first oscillation and consider how to change the nature of the resulting
motion by varying the frequency of the second oscillation f2 .
1. f2 = 0 (|f | = f)
The equation of motion has the form
y(t) = A1 cos(f1 t) + A2 .
This is a harmonic motion with constant frequency f1 and a constant amplitude, the equilibrium
position is raised by the value of A2 producing harmonic oscillations.

Figure 2: Graphs of sig and sigfft.

2. f2 > 0 f2 << f1 (|f | f)


The equation of motion has the form
y(t) = A1 cos(f1 t) + A2 cos(f2 t).
This is a harmonic motion with constant frequency f1 whose equilibrium position varies according
to the harmonic law from A1 to A2 giving oscillation with varying equilibrium position.
3. f2 = f1 , (f = 0)
The equation of motion has the form
sig = (A1 + A2 ) cos(f1 t).
This is a harmonic motion with constant frequency f1 and constant amplitude A1 + A2 presenting
harmonic oscillations.
4. f2 f1 (f 0)
|f | << f
The equation of motion has the form
y(t) = A(t) cos(t),

A23 = A21 A22 + 2A1 A2 cos(f t),

1 A2 A1
f +
f.
2 A1 + A2

It represents beating giving harmonic oscillations at a constant frequency whose amplitude is


slowly changing from |A1 A2 | to A1 + A2 .
5. f2 6= f1 (f > 0)
|f | < f. Here we study all cases that are not included in 1-4.
The equation of motion has the form
y(t) = A(t) cos(ft + (t)),

A23 = A21 A22 + 2A1 A2 cos(f t),

tg((t)) =

A2 A1
1
tg( f t).
A1 + A2
2

It is a motion with variable frequency and variable amplitude, and therefore it is an example of
non-harmonic oscillations.
The described cases have no clear-cut boundaries on the frequency scale and gradually merge
into one another.
All ranges of frequencies in which there is movement of one species are both right and the left of
the fixed frequency f1 . The extent of areas with the same character of the movement is not identical to the right and to the left of the fixed frequency f1 and depend on the values of this frequency.
Exercise III
[X, Y] = meshgrid(0:0.05:, -1:0.05:1);
F = 2 sin(2X) cos(1.5Y )(1 X 2 )Y (1 Y );
mesh(X,Y,F)
surf(X,Y,F)
colorbar
levels = [0:0.01:0.5];
contour3(X, Y, F, levels)
colorbar

[CMatr, h] = contour(X, Y, F);


clabel(CMatr, h)
grid on
contourf(X, Y, F, 20)
colorbar
title(F = 2 sin(2X) cos(1.5Y )(1 X 2 )Y (1 Y ),fontsize,12);

You might also like