mae 315-lab 2 dsp writeup
TRANSCRIPT
MAE 315 Lab 2:
Digital Signal Processing
Alexander SpiridakisProfessor Glauser
1
TABLE OF CONTENTS
Abstract p.3
Introduction
o Digital Signal Processing………………………………………………………………p. 4-9
o Analog/Digital systems and conversion p. 4-6
o Data acquisition p. 6-8
o Resolution p. 8
o Nyquist frequency p. 9
o Signal Conditioning……………………………………………………………………p. 10-13
o Filters p. 10-12
o Amplifiers p. 12-13
o Errors…………………………………………………………………………………………p. 14-17
o Aliasing p. 14-15
o Quantization p. 15-16
o Clipping p. 16-17
o Fourier Analysis………………………………………………………………………..p. 18-28
o Background p. 18-20
o Calculations p. 21-28
Procedure p.29-32
Results and Discussion
o Aliasing and Filtering……………………………………………………………….p. 32-34
o Fourier Analysis: Simulation and Experiment …………………………..p.35-39
o Reconstruction Graphs: Simulation v. Experimental…………………..p.41-42
o Quantization…………………………………………………………………………….p.43-44
o Clipping……………………………………………………………………………………p.45-46
o Noise and Filtering……………………………………………………………………p.47-48
Conclusion p. 49-50
Appendix
2
ABSTRACT
Digital signal processing (DSP) and Fourier analysis were used to develop a basic
understanding of how signals are manipulated and analyzed. In this lab, analog to digital
converters (A/D) were used to digitize signals. Through the data acquisition system used,
these digitized signals were fed into the A/D converter and then displayed on a computer.
Using these tools to visually display the signals allowed for analysis and computation of
Fourier coefficients. The lab had two main sections: a simulation and an experimental
section. During the simulation, the signals were displayed and manipulated theoretically.
The experimental section was then conducted, using the simulation results as the ideal
results that should have been obtained. In both experimental and simulation sections,
sine, square, and triangle waves were manipulated by using filters and intentionally
implementing errors, such as aliasing, clipping, and quantization errors.
The parameters, such as fundamental frequency, sampling rate, and bipolar
voltage were changed for the signals from section to section to examine when and how
errors occurred. It was determined that aliasing can be eliminated through the use of low-
pass filters or by increasing the sampling frequency to a value of over twice the signal’s
fundamental frequency. It also became evident that clipping occurred when an incorrect
voltage range was used to record and display the signal. Quantization error related most
closely to the resolution or number of bits used to process a signal. The fewer the bits
processed in the A/D conversion, the more “noise” appeared due to quantization error.
Lastly, it was demonstrated that Fourier analysis could be used to accurately reconstruct
3
signals (periodic functions). The Fourier analysis and plots showed that the accuracy of
the reconstructions positively correlated to the number of harmonics used in the analysis.
INTRODUCTION
1. Digital Signal Processing
Background
Digital signal processing is the action of taking one or more input signals and
digitizing them. Input signals can be anything from vocal, audio, or visual samples to
physical properties such as temperature or pressure. Digitizing a signal creates a visual
representation of the inputs that can be mathematically analyzed and applied to real world
situations. Both analog and digital signals can be processed and analyzed accordingly.
Analog systems produce or process continuous signals, while digital systems produce or
directly process signals that vary in discrete steps.1
Figure 11 below shows a visual representation of an analog signal to the left and an example of a digital signal to the right.
DSP and Analog to Digital Conversion
Analog to digital converters (A/D converters) are used to convert continuous,
analog signals into digital, discrete signals. Signals in the real world, such as light, sound,
1 http://lcs3.syr.edu/faculty/glauser/MAE315/index.html
4
and most others, are analog.2 In order to analyze them via computer or transfer signals
over wire, they must first be converted to digital. Telephones use A/D converters to relay
audio since the user’s voice is analog and the information must be transferred digitally.
Scanners take analog information given by a picture (light) and convert it into digital to
be displayed on a computer screen.2 Likewise, digital to analog converters (D/A
converters) use the opposite process to generate an analog signal from digital data. Some
examples of various A/D converters and their applications are listed below in Table 1.
2 http://www.hardwaresecrets.com/article/317
5
Table 11: A/D converters and there given applications.
One of the most useful advantages in converting analog to digital is the reduction
of noise. Since analog signals can be assumed to have any value, there is no way to
distinctly separate the analog wave from noise without using a filter. Since digital signals
can only maintain two values, zero and one, any other values get discarded.2 For
example, this is why noise is heard on vinyl records and not on CDs. The needle on the
record player reads analog signals and cannot differentiate between the sound coming
directly from the record and the dust lying on the record, so noise from dust is played
through speakers. CDs, on the other hand, don’t experience this because the noise has
already been filtered out in the A/D conversion.
A/D conversion essentially happens by using precise mathematical
approximations, such as integrals and summations. A/D conversion provides a series of
numbers, each of which corresponds to the weighted integral of the analog signal over
some time period, s, called the aperture, which is less than or equal to the sampling
period .1 Equation 1 below demonstrates the relation between an analog signal and its
corresponding digitally sampled signal.
Equation 11: Where u(t) refers to the original signal, un is the digital sample, is
quantization noise, and t is time.
6
The reconstruction of the wave in the end depends on how the fundamental period
of a wave, s, relates to the sampling period, .
Figure 21: When period s is less than or equal to sampling period
Data Acquisition
Data acquisition is the process of retrieving data inputs to be later analyzed. In
selecting a system to acquire the data, the most important question to consider is, “what
sort of information is ultimately going to be acquired?”1 Answering this helps the user
choose what instrumentation will be best suited for acquiring data. DAQ systems
conventionally consist of a sensor, a DAQ device, such as an analog to digital converter,
and a computer. The sensor reads an analog signal while the A/D convertor changes the
signal from analog to digital so the computer can interpret it.3
With data acquisition systems, other questions must also be considered such as,
how accurate the instrumentation needs to be to accurately process a signal, how fast
must the wave be sampled at, and how will the data be stored? The speed at which the
wave is sampled is termed acquisition speed, and, as can be seen from Figure 3,
3 http://www.ni.com/data-acquisition/what-is/
7
acquisition speed can vary greatly depending on how accurately the data must be
sampled.
Figure 31
1. Low speed: < 1 sample/sec2. Intermediate speed: 100 samples/sec – 1000 samples/sec3. High speed: > 1000 samples/sec
Figure 4 – The original analog signal (top). The wave is then sampled at a given rate,
converted, and reconstructed (bottom).
The more sampling points used in the A/D conversion, the more perfectly the
reconstructed wave will resemble the original. The only downside to this is that the more
samples taken, the more storage space it takes to store them all. Too few samples, and the
data won’t be reconstructed accurately. So, an ideal sample rate should be found used for
8
A/D and D/A converting so as to accurately reconstruct a wave and not take up too much
space.
Resolution and Nyquist Frequency
Resolution directly corresponds to the number of bits per each sample. A bit is
simply a binary digit. By varying resolution, the user can vary how much extraneous
noise comes through from the signal, resulting in quantization error, which will be
discussed further later on. Figure 5 shows two waves, each sampled at full resolution, ½
resolution, and then ¼ resolution. As the number of bits per sample decrease, the shape of
the wave becomes less defined. Bits and sampling both play a part in determining
resolution. Whereas the sampling rate changes with respect to time, resolution changes
with respect to the number of samples.
Figure 54: The definition of the waves changes with the resolution of the wave.
4 http://www.iac.es/proyecto/magnetism/pages/activities/instrumentation.php
9
The Nyquist frequency is defined as being equal to half of the sampling frequency
of that signal.5 If the signal is continuous, Nyquist frequency also refers to the highest
frequency that the sampled signal can unambiguously represent.5 For example, if a signal
is sampled at accurately at 22000 Hz, the highest frequency that we can expect to be
present in the sampled signal is 11000 Hz.
2. Signal Conditioning
Filters
Filters are used in digital signal processing for two general purposes: separation of
signals that have been combined, and restoration of signals that have been distorted in
some way.6 Various filters affect signals in different ways. For example, a low-pass filter
allows the low-frequency signals to pass and significantly reduces signals at a higher
frequency than the preset cutoff. A high-pass filter filters out low-frequency signals and
lets high frequencies pass. Band-pass filters allow frequencies to pass within a given
range, and band-reject filters are the opposite. Low-pass and high-pass filters work in the
time domain, while band-pass and band reject filters work in the frequency domain.1
Frequency domain filters are used when the information contained relates to amplitude,
frequency and phase components of a wave, and the goal of these filters is to separate one
band of frequencies from another, while time domain filters are used for things such as
5 http://www.fon.hum.uva.nl/praat/manual/Nyquist_frequency.html6 http://www.dspguide.com/ch14.htm
10
smoothing and shaping waveformsError! Bookmark not defined.6 High-pass, band-
pass, and band-reject filters are designed by starting with a low-pass filter, and then
converting to obtain the desired response Figure 6 shows a visual a visual representation
of how these filters are combined and created.
Figure 6
There are two main methods for turning low-pass into high-pass filters: spectral
inversion and spectral reversal. Spectral inversion (shown in Figure 6) changes a filter
from low-pass to high-pass, high-pass to low-pass, band-pass to band reject, and band-
reject to band-pass. Spectral inversion works differently in that a high-pass and a low-
pass filter are added to create a band-reject filter. This process is demonstrated below in
Figure 7.
11
Filters help with cleaning up signals that are digitally processed. For example, a
low-pass filter can be used to filter out frequencies below the Nyquist frequency of a
signal. This is a preventative measure so that noise doesn’t come up and ensures the
signal won’t experience aliasing. So, filters can remove the useless data from a processed
signal and can prevent error.
Amplifiers
Amplifiers essentially take a signal in one form and translate it into another. Most
amplifiers take an input signal and produce a different, more powerful, output signal.7
Figure 8 below demonstrates the use of a conventional amp in amplifying sound
7 http://electronics.howstuffworks.com/amplifier1.htm
12
Figure 87
In digital signal processing, operation amplifiers (op-amps) are used to modify
signals and even produce frequency filtering. Op-amps have two inputs and a single
output. The two main types of op-amps worth considering are inverting and non-
inverting. With an inverting amplifier, the gain delivered to the output signal is
determined by two resistors, as shown in Figure 9 and Equation 2 below. The output
signal of an inverting amplifier is the negative of the input signal.
Figure 98 (left) Equation 2 (right)
8 http://electronics.stackexchange.com/questions/32084/transfer-function-for-inverting-amplifier
13
The gain delivered to a signal from a non-inverting op-amp is created by
multiplying the input voltage by a constant greater than one. Figure 10 and Equation 3
show a diagram of how a non-inverting amplifier would be set up in a circuit and how to
calculate the output voltage given a certain input.
Figure 108 (left) Equation 3 (right)
3. Errors
When digitizing or processing digital signals as performed in this experiment, one
can encounter a number of errors based on various parameters used in the processing
method.
Aliasing
Aliasing is a phenomenon that occurs when the sampling rate of a signal being
digitized is not high enough to accurately reconstruct the original analog wave. An
aliased signal may look deceptively correct when being displayed in the time domain, but
14
will result in incorrect signal measurements.9 Since aliasing results from not having
sampled a wave at enough points, an aliased signal doesn’t correctly display all of the
information needed for collection, and, therefore, creates error in data. To show an
example, Figure 11 displays a wave (top) that is accurately sampled and the same wave
(below) superimposed on one that is aliased.
Figure 11
(graphed in the time domain)9
The Shannon Sampling Theory (or Nyquist sampling theorem) states that aliasing
can be prevented by setting a sampling frequency greater than or equal to two times the
highest frequency contained in the signal.10 In reality, sampling at twice the bandwidth
signal only preserves frequency information. For accurate amplitude and shape
measurements in the time-domain, the sampling rate must be at least ten times the signal
bandwidth. This will ensure that a sufficient number of points are sampled to accurately
reconstruct the input analog wave. To summarize, the higher the sampling rate, the more
9 http://www.ni.com/white-paper/10669/en/10 http://www.siggraph.org/education/materials/HyperGraph/aliasing/alias1.htm
15
processing power and time it takes to recreate a signal, but aliasing is prevented and error
is minimized.
Quantization and Quantization Error
Quantization is the process of mapping a larger set of values onto a smaller set.11
Quantization error results from trying to represent a continuous analog signal with
discrete, stepped, digital data.12 As previously discussed, analog signals can assume
virtually any value, while digital signals can only have finite values in discrete steps.
What happens when an analog value falls between these two digital “steps”? If a signal is
quantized, some round off error occurs as the analog signal assumes the digital value it is
closest to. Figure 12 below shows an ideal analogue wave and the quantization error as it
is converted to digital.
11 http://www.thefreedictionary.com/quantization12 http://www.sweetwater.com/insync/quantization-error/
16
Figure 12: To the left, an ideal sample of an original wave and then its quantized
sample as its converted to its closest digital wave.13 To the right, a full sample of an
original wave superimposed on a quantized signal and the quantized error are displayed.
Quantization error is represented in Equation 1 (above) as variable “mu” and acts
as noise introduced by the sampling process. In order to get rid of this, enough gain must
be applied to the input signal to ensure that voltage levels rise above any possible
quantization noise.1 Alternatively, a higher resolution A/D converter can used to reduce
quantization noise to acceptable levels. In other words, if you increase the number of bits
to convert the signal, the reconstruction will not be as severely quantized.
Clipping
Clipping is one of the most analytically simple errors to recognize and
understand. Clipping occurs when a signal is limited to an amplitude value less than its
true amplitude, either because of limits on instrumentation (the fact that an A/D converter
has a finite range) or signal gain. A pure sinusoidal wave that is clipped will look like one
or more of its peaks have been cut off. Instead of having rounded peaks, the wave will
develop flat lines that occur at a cutoff amplitude. A clipped wave will not give the user
sufficient or accurate data. In order to prevent clipping, the instrumentation being used to
collect data must be programmed to be able to capture a wave’s peak-to-peak amplitude.
For example, choosing the right bipolar range for the data is crucial in preventing
clipping.
13http://www.diracdelta.co.uk/science/source/q/u/quantization%20error/source.html#.UmW4C2TwLqs
17
Figure 13 – Shows a clean signal (left)
and that same signal clipped (right).14
Fourier Analysis
Fourier analysis is a way to mathematically analyze various waveforms in terms
of series, sequences, and trigonometric functions.15 With Fourier analysis comes the
introduction of the fundamental frequency and harmonics, which are used together to
determine the overall shape of a wave. Fourier, a mathematician, proved that any
continueous function could be produced as an infinite sum of sine and cosine waves.16
14 http://ccs.exl.info/installation/crossovers-installation-tweaking/tweaking/15 http://whatis.techtarget.com/definition/Fourier-analysis16 http://hyperphysics.phy-astr.gsu.edu/hbase/audio/fourier.html-
18
As long as the function considered is periodic, its representative Fourier series, or
summation of sinusoids, can be expressed using Equation 4 below, where f is the
fundamental frequency, n is the number of harmonics, and t is time.
Equation 4
In Fourier analysis, the objective is to calculate coefficients an and bn up to the
largest possible value of n. The more harmonics that are assimilated into the equation, the
more accurate the reconstructed signal becomes to the original signal. The coefficients
are calculated using integral calculus with the equations below, where x(t) is the equation
of the original signal:
Equation 5 Equation 6 Equation 7
Since ∫– T /2
T /2
x (t ) dt is the area beneath function f over the given interval, a0 can be
geometrically interpreted as the average value of function f on that given interval or as
the new center of oscillation.17 The combinations of sine and cosine waves in the Fourier
equation develop a complete orthonormal basis for all continuous sinusoidal functions.
Based on that, the developed Fourier series is equivalent to building x(t) from the basis
sine and cosine vectors, and the coefficients an and bn indicate how many of each sine or
17 http://math.stackexchange.com/questions/340429/intuition-behind-fourier-coefficients
19
cosine vectors are needed. Ideally, the Fourier reconstruction would be an infinite
combination of the basis vectors.
If the function at hand is considered odd, then the cosine term in Equation 4 will
go to zero along with the an coefficient. Similarly, if the function is even, the sine term
will go to zero, and so will the bn coefficient. With an odd function, there is a bn
coefficient at a certain value corresponding to the sine term, and an even function has an
an coefficient corresponding to the cosine term.
For a uniform sine wave, a0 and an will always be zero. The bn coefficient will
always have a value equal to the amplitude of the specific sine wave being analyzed. A
sine wave only has one harmonic (n=1) because theoretically, it only takes one sine wave
to make up a sine wave. Therefore, the reconstruction of a uniform sine wave will be:
bn=A
x (t )=A∗sin (2 πn f 0 t)
A = amplitude
f = frequency (1/T)
t = time
n = harmonics
For an odd function square wave, a0 and an coefficients will again be zero, and bn
will have a nonzero value. Also, there will be more than one harmonic for a square wave,
seeing as though it takes multiple superimposed sine waves to create a square-like
waveform shape. The greater number of harmonics, the better the reconstruction looks.
20
The bn value for an odd square wave is equal to four times the wave’s amplitude divided
by the product of the number of harmonics with pi.
bn=4 Anπ
x (t )=4 Anπ
sin (2 π nf 0t)
Lastly for an even function triangle wave, a0 and bn will be zero. As discussed
before, with even functions, bn, the coefficient for sine, will be zero, and an will have a
nonzero value. Like the square wave, many harmonics are needed for a good
reconstruction of a triangle wave.
an={ 0 , whenn is even8 An2 π2 ,when n is odd
x (t )= 8 A
n2 π2∗cos (2 πn f 0t )
Fourier Derivations
Sine wave (a0)
A = Amplitude, T= Period, L=T/2, f = Frequency = 1/T f*L = ½
x(t) = Asin (2πft )
21
a0=A∗1
T∫−T
2
T2
sin (2 πft ) dt= 12 L
∫−L
L
sin (2 πft ) dt
a0=A∗12 L [−cos (2 πft )
2πf ]−L
L
a0=A
2 L ( 12 πf ) [−cos (2 πfL)−(−cos (0 ))]
a0=A
2 π[−1−(−1)]
a0=0
Sine wave (an)
an=2T∫−T
2
T2
x ( t ) cos (2 πnft )dt = A2 L
∫−L
L
sin (2 πft ) cos (2 πnft )dt
Using identity: sin(u)*cos(v) = sin(u+v) + sin(u-v),
22
an=A
2 L∫−L
L
sin (2 πft+2 πnft )+¿ sin (2 πft−2 πnft ) dt ¿
an=A
2 L∫−L
L
sin (t (2 πf +2 πnf ) )+sin (t (2 πf −2 πnf ) ) dt
an=A
2 L [−cos (t (2 πf +2 πnf ) )2 πf +2 πnf
+−cos (t (2 πf−2 πnf ) )
2 πf −2 πnf ]−L
L
an=A
2 L [−cos ( L (2 πf +2πnf ) )2 πf +2 πnf
+−cos ( L (2πf −2πnf ) )
2 πf −2πnf ]− A2 L [−cos (−L (2πf +2 πnf ) )
2 πf +2 πnf+−cos (−L (2 πf −2 πnf ) )
2 πf −2 πnf ]an=
−cos ( L (2πf +2 πnf ) )2 πf+2 πnf
+−cos ( L (2πf −2πnf ) )
2 πf −2 πnf+
cos (−L (2πf +2 πnf ) )2 πf +2πnf
+−cos (−L (2 πf−2 πnf ) )
2 πf −2 πnf
Terms cancel because cos(x) = -cos(x) and –cos(x)+cos(x) = 0
Therefore, an=0
bn=2T
∫−T /2
T /2
x ( t ) sin (2 πnft ) dt = bn=1L∫−L
L
Asin (2 πft )sin (2 πnft )dt
bn=AL [ cos (2 πft )sin (2 πnft )−nsin (2πft ) cos (2πnft )
n2−1 ]−L
L
bn=AL [ cos (2 πfL) sin (2πnfL )−nsin (2 πfL) cos (2 πnfL)
n2−1 ]− AL [ cos (−2πfL )sin (−2πnfL )−nsin (−2πfL ) cos (−2πnfL )
n2−1 ]
bn=AL [ cos ( π ) sin (πn )−nsin (π )cos (πn )
n2−1 ]− AL [ cos (−π ) sin (−πn )−nsin (−π )cos (−πn )
n2−1 ]For harmonic n=1, bn= 0/0. L’Hospital’s rule applied:
23
limn →1
AL [ cos ( π ) sin (πn )−nsin ( π ) cos ( πn )
T2
(n2−1 ) ]+ AL [ cos (−π ) sin (−πn )−nsin (−π ) cos (−πn )
T2
(n2−1 ) ]limn →1
AL [ cos ( π ) cos (πn ) π−nsin ( π )(−sin (πn ))π−cos (πn)sin (π )
T2
(2n) ]+ AL
¿¿
As n goes to 1, the limit becomes: bn=A( 12+ 1
2 )=A
Square Wave (a0)
A = Amplitude, T= Period, L=T/2, f = Frequency = 1/T f*L = ½
x (t )={−A ,∧−L≤ t<0A ,∧0≤t <L
a0=1T∫−T
2
0
−A dt + 1T∫0
T2
A dt
a0=1
2 L∫−L
0
−A dt+ 12 L
∫0
L
A dt
a0=1
2 L[−At ]−L
0 + 12 L
[ At ]0L
a0=−12 L
(−A (−L ) )+ 12 L
( A ( L ))
a0=0
Square Wave (an)
an=2T∫−T
2
T2
x (t ) cos (2 πnft )dt
an=1L [∫
−L
0
−A cos (2πnft ) dt+∫0
L
Acos (2 πnft )dt ]24
an=1L [−Asin (2 πnft )
2πnf ]−L
0
+ 1L [ Asin (2 πnft )
2πnf ]0
L
an=1L [ Asin (−2 πnfL)
2πnf+
Asin (2 πnfL)2πnf ]
Since sin(-t) = sin(t) and –sin(t) + sin(t) = 0,
an=0
Square Wave (bn)
bn=2T
∫−T /2
T /2
x ( t ) sin (2 πnft ) dt
bn=1L [∫
−L
0
−Asin (2 πnft )dt +∫0
L
Asin(2 πnft)]bn=
1L [ Acos (2 πnft )
2 πnf ]−L
0
+ 1L [−Acos (2πnft )
2πnf ]0
L
bn=1L [ Acos (0 )
2 πnf−
Acos (2 πnfL )2πnf ]+ 1
L [−Acos (2 πnfL )2 πnf
−−Acos (0 )
2πnf ]bn=
1L [ A
2 πnf−
Acos ( πn )2 πnf ]+ 1
L [−Acos ( πn )2 πnf
+ A2 πnf ]
bn=Aπn
(2−cos (πn )−cos ( πn ) )= Aπn
(2−2 cos ( πn ))
For n odd, bn=4 Aπn
25
Triangle wave (ao)
*NOTE: The triangle wave has been analyzed below as an even function whereas
the sine and square waves have been analyzed above as odd functions.
A = Amplitude, T= Period, L=T/2, f = Frequency = 1/T f*L = ½
x (t )=A−A( 2 tL )
a0=2∗1
T∫0
T2
x (t ) dt
a0=2∗12 L
∫0
L
(A−A ( 2tL ))dt
a0=1L [ At−
A t2
L ]0
L
a0=1L [ AL− A L2
L ]a0=0
26
Triangle wave (an)
*NOTE: The triangle wave has been analyzed below as an even function whereas
the sine and square waves have been analyzed above as odd functions.
an=2∗2
T∫0
T2
x ( t ) cos (2 πnft ) dt=2∗1L
∫0
L
[ A−A ( 2 tL )]cos (2 πnft ) dt
an=2 AL∫
0
L
[cos (2 πnft )−( 2tL )cos (2πnft )]dt
Integration by parts: u = 2t/L , dv = cos(2ft) dt
an=2 AL [ sin (2 πnft )
2 πnf ]0
L
−2 AL [ [ 2t
Lsin (2 πnft )
2 πnf ]0
L
−∫0
L2L (sin (2 πnft )
2 πnf )dt ]an=
2 AL [ sin (2 πnft )
2 πnf ]0
L
−2 AL [ [ 2 t
Lsin (2 πnft )
2 πnf ]0
L
−[ 2 (−cos (2 πnft ) )
L( 12 πnf )
2 ]0
L]an=
2 AL [ sin (2 πnfL)
2 πnf ]−2 AL [ 2 Lsin (2 πnfl )
2 πnfL ]−[ 1Lπnf (−cos (2πnfL )
2 πnf—
−cos (0 )2 πnf )]
an=2 AL [ sin (2 πnfL)
2 πnf ]−[ sin ( πn )πnf
−( 1πn ( (1−cos (πn ))
πnf ))]
27
an=2 Asin ( πn )
πn−
4 Asin ( πn )πn
+( 4 A−4 Acos ( πn ) )
π 2n2
For n odd, an=8 A
π2 n2
Triangle wave (bn)
*NOTE: The triangle wave has been analyzed below as an even function whereas
the sine and square waves have been analyzed above as odd functions.
bn=2∗2T
∫0
T2
x ( t ) sin (2 πnft ) dt=2∗1L
∫0
L
[A−A ( 2tL )]sin (2 πnft ) dt
bn=2 AL∫
0
L
[sin (2 πnft )−( 2 tL )sin (2 πnft )]dt
Integration by parts: u = 2t/L , dv = sin(2ft) dt
bn=2 AL [−cos (2πnft )
2πnf ]0
L
−2 AL [[ −2 t
Lcos (2 πnft )
2πnf ]0
L
−∫0
L−2L ( cos (2πnft )
2 πnf )dt ]bn=
2 AL [−cos (2πnft )
2πnf ]0
L
−2 AL [[ −2 t
Lcos (2 πnft )
2πnf ]0
L
−[−2 (sin (2 πnft ) )
L( 12 πnf )
2 ]0
L]Terms cancel because cos(x) = -cos(x) and –cos(x)+cos(x) = 0 and
sin(2) = sin(0) = 0.
bn=0
28
PROCEDURE
Simulation
In the simulation, the computer alone digitally generated all signals using LabView. No
A/D converter was used.
2.1 – Digital Oscilloscope Simulation
A sine wave was selected as the input function.
The fundamental frequency was set at 1000 Hz
The amplitude of the wave was set to 5 volts
Sampling frequency was set to 5 kHz
Resolution was set to 12 bits
Bipolar range was set to +/- 10 volts
Low pass filter setting OFF
Press Run
SAVE FILE
2.2 – Fourier Analysis Simulation
Simulated a square and triangle wave in both in time and frequency domains
Square wave was selected as the input function
Waveform frequency was set to 1000 Hz
Sampling frequency was set to 45 kHz
Resolution, amplitude, and bipolar range were taken from previous section 2.1
29
Low pass filter setting ON
Press Run
SAVE FILE (Filtered square wave)
Repeat the above process with the Low pass filter setting OFF
SAVE FILE (Unfiltered square wave)
Repeat above steps with triangle wave
SAVE FILE (Filtered triangle wave)
SAVE FILE (Unfiltered triangle wave)
2.3.1 – Quantization Error and Resolution
Sine wave was selected as input function
Waveform frequency was set to 1000 Hz
Sampling frequency was set to 45 kHz
Resolution was set to 12 bit
Amplitude and bipolar range were taken from previous sections (2.1 and 2.2)
Low pass filter setting ON
Press Run
Run and SAVE (12 bit sine wave)
Repeat above steps with resolution set to 4 bits
Run and SAVE (4 bit sine wave)
2.3.2 – Clipping
Sine wave was selected as input function
30
Waveform frequency was set to 4000 Hz
Amplitude was set to 5 volts
Sampling frequency was set to 80 kHz
Resolution was set to 12 bit
Bipolar range was set to +/- 1.0 volts
Clipping of the sine wave peaks was noted
SAVE FILE (Clipped sine wave)
Experiment
In the experiment, the function generator was used instead of the computer to create the
waveforms needed. The waveforms were still analyzed through LabView.
3.1– Digital Signal Acquisition
Sine wave was selected on the waveform selector
Frequency was set to 1000 Hz on function generator
Sampling frequency was set to 45 kHz on Labview VI
Press Run
Measured actual frequency of sine wave using cursor
Compare wave to section 2.1 of Simulation
SAVE FILE (Not aliased sine wave)
3.2 – Anti-Aliasing and Filtering
31
Repeat process from previous section 3.1 using a sampling frequency of 1500
Hz
SAVE FILE (Aliased sine wave)
Run the function generator through the Krohn-Hite filter
Krohn-Hite filter was set to a cutoff frequency of 750 Hz
Repeat the above procedure
SAVE FILE (Second aliased sine wave)
3.3 – Fourier Analysis Experiment
Square wave was selected on the waveform selector
Frequency was set to 1000 Hz
Sampling frequency was set to 45 kHz
Measured actual frequency and amplitude of wave using cursor on the
computer
SAVE FILE
Repeat for triangle wave
SAVE FILE
CHANGED to B&K function generator and turn on white noise setting
Sampling frequency to 45 kHz
SAVE FILE (White noise)
Used Low pass filter at cutoff frequency of 7000 Hz
Filter white noise from previous file through low pass filter
SAVE FILE (White noise filtered through low pass filter)
32
RESULTS and DISCUSSION
The simulation and the experimental sections were started first by creating a
standard sine wave from which to work off of. The more detailed results and analysis of
the simulation and experiment are below. To examine the sine wave done in simulation
section 2.1, refer to the plots in Appendix 2.1 To look at the sine wave created by the
function generator; refer to the information in Appendix 3.1.
1. Aliasing and Filtering
From experimental section 3.2, the function generator created two sine waves
with the same parameters. Both of these waves experienced aliasing. The first wave
through was sampled at a rate far below its Nyquist frequency. The second wave had the
same frequency as the first and was sampled at the same rate, and it was put through a
low pass filter (Krohn Hite filter). Even though the filter was on, the second wave still
experienced aliasing because the sampling rate was still too low to accurately reconstruct
the wave. The filter prevented some “noise” from coming through at higher frequencies.
The aliasing could’ve been predicted using the Shannon or Nyquist Sampling Theorem.
Aliasing of the wave without the low pass filter can be seen in Figure 1.1, and aliasing of
the wave with the filter can be seen in Figure 1.2. Additional information and plots
associated wit experimental section 3.2 can be found in Appendix 3.2.
Amplitude 3.3817 volts ±0.0012 volts
Frequency 1000 Hz± 500 HzCutoff filter frequency 750 Hz ± 375 HzSampling frequency 1500 Hz ± 750 Hz
33
Number of Samples 8192
Figure 1.1
Figure 1.2
34
2. Fourier Analysis: Simulation and Experiment
From simulation section 2.2, square and triangle waves were created with the
parameters listed below. The waves were both run a second time through a low pass
filter.
Amplitude Frequency Sampling frequency Number of samples
5 volts ± 0.0012 v 1000 Hz± 500 Hz 45 kHz± 22.5 Hz 8192
The first square wave that was simulated without the filter was close to a perfect
square. The square wave with the low pass filter on developed peaking where the wave
was originally flat. The slopes of the filtered wave were more noticeable slanted instead
of clearly resembling straight vertical lines. The differences occurred as a result of the
low pass filter being turned on. The low pass filter blocked higher frequencies from
coming through that were needed to make a more precise square waveform. The
unfiltered square wave can be seen in Figure 2.1 while the filtered can be seen in Figure
2.2.
The triangle wave experienced the same thing as the square wave. The unfiltered
triangle wave had peaks that were more pointed compared to the filtered wave that had
peaks that were more rounded. Again, this was a result of the filter cutting out
frequencies in the higher range. These high frequencies are needed in triangle and square
waveforms to create the visible pointed edges. The unfiltered triangle wave and filtered
triangle wave can be seen in Figures 2.3 and 2.4, respectively. The Nyquist plots
35
corresponding to simulation 2.2 can be found in Appendix 2.2, while the Fourier
reconstruction graphs can be found on pages 38-40 in this section.
Figure 2.1
36
Figure 2.2
Figure 2.3
37
Figure 2.4
In the first two steps of experimental section 3.3, both square and triangle
waveforms were created through the function generator.
Amplitude 3.6
Frequency 1111.11 Hz ± 555
Sampling frequency 45 kHz ± 22.5
Number of Samples 8192
Harmonics n=1,3,5,…,63,65,67
The data showed that the square and triangle waveforms in the experimental
section resembled the corresponding waveforms in the simulation very closely. The data
collected in the time domain showed that the results were accurate. In the frequency
38
domain, the experimental graphs had noticeably more peaks than the frequency domain
graphs of the simulation. The frequency peaks were a result of needing more frequencies
to accurately reconstruct the waves. Square and triangle waves have pointed edges
whereas sine waves do not, and therefore, they need multiple frequencies to increase the
definition around the pointed edges. The experimental square and triangle waves can be
seen in Figures 2.5 and 2.6, respectively. Additional information on experiment 3.3 can
be found in Appendix 3.3.
Figure 2.5
39
Figure 2.6
3. Reconstruction Graphs
The square and triangle waves from simulation section 2.2 and experimental
section 3.3 were reconstructed using harmonics. Below are the results displaying each
reconstruction up to 75 harmonics. The results showing progressive reconstruction using
a few harmonics at a time and Nyquist plots are in Appendix 2.2 for simulation 2.2 and
Appendix 3.3 for experimental section 3.3. The results show that enough harmonics were
used to reconstruct the graphs, and the reconstructed graphs from the simulation closely
resemble the reconstructed graphs from the experiment.
40
Reconstruction: Unfiltered Square wave Simulation 2.2
41
Reconstruction: Unfiltered Square wave Experiment 3.3
Reconstruction: Unfiltered Triangle wave Simulation 2.2
42
Reconstruction: Unfiltered Triangle wave Experiment 3.3
4. Quantization Error
From simulation 2.3.1, a sine wave was simulated once with 12 bit resolution and
the second time with 4 bit resolution. The sine wave with 12 bits appeared smooth and
uniform. The sine wave taken with 4 bit resolution appeared more jagged and had edges
as opposed to curves. The low pass filter was activated to prevent any aliasing from
occurring.
Amplitude 2 volts
Frequency 1000 Hz± 500 Hz
Sampling Frequency 45 kHz± 22.5 Hz
Bi-polar range +/- 10 volts
Low pass filter cutoff 27.5 kHz± 13.75 Hz
43
The low resolution caused quantization error to appear for the second wave. The
number of bits used for each wave dictated how many data points could be recorded. The
wave generated with 4 bits had significantly fewer data points and much larger spaces in
between each point. The quantized wave taken at 4 bits experienced significantly more
error than the reference sine wave. This created the quantization error seen in figure 4.2.
The reference sine wave can be seen in Figure 4.1. The remaining data for these two
waves can be found in Appendix 2.3.1.
Amplitude Uncertainty for 12-bit +/- 0.001 volts
Amplitude Uncertainty for 4-bit +/- 0.333 volts
Figure 4.1
44
Figure 4.2
5. Clipping
In simulation 2.3.2, a sine wave was taken with the parameters listed below with a
bipolar range of +/-10 volts. That same sine wave was then simulated with a bipolar
range of +/-1 volt.
Amplitude 5 volts ± 1.22(1 0−4) volts
Frequency 4000 Hz± 2000 Hz
Sampling Frequency 80 kHz± 40 Hz
Resolution 12 bit
45
Figure 5.1
46
Figure 5.2
The clipping in above Figure 5.2 is a direct result of decreasing the bipolar range.
The flat peaks of the sine wave are notably where the bipolar range cuts off. The slopes
leading up to the peaks are slightly more curved when the wave is clipped. Figure 5.1 can
be used as a reference to see what the wave would look like if it had not been clipped. It
should be noted that the frequency domain plots are slightly different. The clipped wave
is no longer a perfect sine wave and, therefore, needs more frequencies to accurately
reconstruct its shape. More information can be found on the clipped wave in Appendix
2.3.2.
6. Noise and Filtering
In the last part of experiment section 3.3, white noise was created using the
function generator. The noise was produced with frequencies varying 2 to 20,000 Hz. The
data taken for the noise can be seen in Figure 6.1 below.
47
Figure 6.1
The noise coming out of the generator was then run through a low pass filter with
a cutoff frequency of 7000 Hz. The results can be seen in Figure 6.2 below. As expected,
the filter cleared most of the frequencies above the cutoff. However, the filter used was
not perfect. There was a negative slope in the frequency domain plot of Figure 6.2
indicating that the filter did not cutoff exactly at 7000 Hz and still let some of the higher
frequencies pass through. This is general error associated with low pass filters. As shown,
the instrumentation is not perfect. The data shows that the filter significantly helped in
reducing the original noise and stopped most noise frequencies from passing above 7000
Hz.
48
Figure 6.2
CONCLUSION
Through analysis and comparison of the results, multiple conclusions can be
drawn regarding error, Fourier analysis, and applications regarding digital signal
processing. Comparison of the experimental results to the results of the simulation
showed how close the actual experimental results were to what would have happened in
ideal conditions with minimal error. As expected, the experimental results had a larger
margin of error than the results taken from the simulation.
49
The Fourier analysis conducted in digital signal processing tied together
mathematical theory with real world application. Fourier analysis allowed for the
reconstruction of the experimental and simulated waves using harmonics. Looking at the
square and triangle wave reconstruction graphs, it became evident that the more
harmonics incorporated, the more the reconstructed plot resembled the original. The
reconstructed graphs were close but never exactly as precise as the original because a
finite number of harmonics was used in each case. To have a reconstructed graph using
harmonics identical to the original, theoretically an infinite number of harmonics must be
incorporated. Essentially, an infinite number of sine waves must be used to create a
perfect square or perfect triangle waveform. Any other number of sine waves will
produce a waveform that is only close to a perfect square or triangle wave. The Fourier
coefficients that were found in the analysis were used to create an accurate
reconstruction. Overall, the simulations, the experimental graphs, and the Fourier
reconstruction were similar, meaning the experimental results behaved as predicted, and
the Fourier reconstructions were done accurately.
The exercises both in the simulated and experimental tests showed how various
waveforms behaved given certain parameters. The types of waveforms that were
examined were pure sine, square, and triangle, and the three prominent errors that
occurred were aliasing, quantization error, and clipping. The errors occurred in the
process of converting an analog signal into its digital counterpart. By simulating these
errors, a lot was learned on why these errors happen circumstantially and how to prevent
them from happening in future signal processing. Aliasing is the most difficult to analyze
because, as discussed, a wave that is aliased can still give certain correct information.
50
Aliasing occurred when the sampling rate was not twice the frequency of the wave.
Sampling at a good rate and filtering a signal through low-pass filters can prevent
aliasing. Quantization error occurred in this experiment when the resolution was set
incorrectly. Altering the resolution for a signal to increase the number of bits would
prevent this error. Clipping occurred simply when a wave was processed using an
incorrect voltage range. Clipping is obvious when a visual representation is created of the
signal in the time-domain and can be corrected by simply changing the bipolar voltage.
Digital signal processing is indisputably significant in today’s technological
world. This experiment in particular provided a lot of information on how different
waveforms are manipulated and used, the errors that can occur when processing them,
and how to recognize and fix them when they do occur. Along with Fourier analysis, this
knowledge can be applied to anything involving vibrations and waves, such as speakers
and telephones used in everyday life or waves traveling through solid objects.
Uncertainty Equations
ut=±12
t
u f=±12
f
uA=±12 ( Range
2N−1 )ubn
=√ f 2+u f2+ A2+ua
2
51