Sunteți pe pagina 1din 66

Spectral Analysis: Fourier

Transform(FT), Short-time
Fourier Transform(STFT) and
Wavelet Transform(WT)
Zafar Ahmed
University of Oklahoma
A few concepts

A few concepts
Complex Numbers.
Analog Signal.
Discrete time signal vs continuous time signal.
Nyquist rate for signal sampling.
Time Domain VS frequency Domain
Discrete Fourier Transform.
Dirichlets equation.
Orhogonality of functions.
Discrete and Continuous Frequency Domain
Multi-resolution analysis
STFT short time fourier transform
Complex numbers
Review: complexnumbers
Rectangular form: s =a+j b, j =

1
a =Re(s), b=Im(s)
Polar form: s =re
j
Eulers formula: e
j
=cos+j sin
Complex conjugate: s

=aj b=re
j
ss

=|s|
2
=a
2
+b
2
0
Re s
Im s

a
b
r =|s| = a
2
+b
2
=tan
1
b
a
MaximRaginsky Lecture II: Continuous-Time and Discrete-Time Signals
Analog Signal
Mathematically, a signal is a function of time.
Most fundamental signal sinusoidal
Any periodic signal is composed of may different sine and
cosine signals.
Three parameters
Amplitude
The absolute value of how up the wave goes
Angular Frequency
How many times the signal repeats itself within a unit of time.
Phase Angle
Phase in waves is the fraction of wave cycles that has elapsed after an arbitrary point.
Continuous time VS discrete
time signals
Continuous time signals are defined at any value of time
Discrete time signals are defined only at discrete values of time.
Continuous time signal takes a value at every point in time
discrete time signal takes values on at discrete points in time. For
the rest of the points in time , we dont know the value.
Continuous time signal contains infinite values of time and the
corresponding amplitude.
Discrete time signal only contains
Periodic discrete-timesignals
x[n] is periodic if thereexists a positiveinteger T, such that
x[n +T] =x[n], for all n.
Fundamental period: smallest positiveinteger T, such that theabove
holds.
x[n]
n 0
fundamental period = 6
Example: x[n] =A cos(n +) is periodic if and only if thereare
positiveintegers q and r, such that =2q/ r (in other words, if is a
rational multipleof 2).
MaximRaginsky Lecture II: Continuous-Time and Discrete-Time Signals
Periodic continuous-timesignals
x(t) is periodic if thereexists a number T >0, such that
x(t +T) =x(t), for all t.
Fundamental period: smallest positiveT, such that theaboveholds.
Examples:
0
x(t)
t
period = 2 /
sinusoid x(t) =A cos(t +)
0
x(t)
-
1
1
period
triangular wave
MaximRaginsky Lecture II: Continuous-Time and Discrete-Time Signals
Nyquist Rate
A signals sampling rate must be twice of the highest frequency
contained within that signal.
Nyquist frequency = half the sampling frequency of a signal processing
system (a system which samples a signal).
So, if the highest frequency contained within a signal is 40 Hz then that
signal must be sampled at a rate of nyquist rate (80 times/sec) to
prevent antialiasing.
Time Domain VS Frequency Domain
Time Domain is a curve of Amplitude (Y axis ) VS Time (X - Axis)
Frequency Domain is a discrete or continuous thing of magnitude (Y -
axis) vs Frequency(Hz) (X-axis)
Time Domain & Frequency Domain K. Craig 18
Converting from time
domain to frequency
domain
Discrete Fourier Transform
Time Domain & Frequency Domain K. Craig 13
Discrete Fourier Transform (Contd)
How do we analyze the frequency components of a complex signal
Time space x(t) Frequency space X()
single frequency signal
0

t

0
t
X() is complex -- complex conjugate encodes phase
Fourier transform is invertable
Some properties
it
e
Cos(t) +iSin(t)
it
e
Cos(t) +iSin(t)
FFT in MATLAB
We want this
as a result
of FFT of
this
as output (in
frequency
domain)
as input
(in time
domain)
Look at this
Discrete Fourier Transform(Example)
Fourier Transform tells me
Which frequency components are present in a signal
What is the amplitude and phase of that frequency component in the signal
Here is a sample code of fourier transform
fs = 100; % Sample frequency (Hz)
t = 0:1/fs:10-1/fs; % 10 sec sample
x = (1.3)*sin(2*pi*15*t) + (1.7)*sin(2*pi*30*t); % 40 Hz component
% + (2.5)*randn(size(t)); % Gaussian noise;

figure(3)
plot(t,x)

m = length(x); % Window length
n = pow2(nextpow2(m)); % Transform length
y = fft(x,n); % DFT
f = (0:n-1)*(fs/n) % Frequency range
power = y.*conj(y)/n; % Power of the DFT this is done to take all amplitudes in the positive
direction

y0 = fftshift(y); % Rearrange y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = y0.*conj(y0)/n; % 0-centered power

figure(1);
stem(f0,power0,'r')
% plot(f,power)
xlabel('Frequency (Hz)')
ylabel('Power')
title('{\bf Periodogram}')
clear x;
clear y;
clear power;
clear f0;
clear y0;
clear power0;
Inpu
t
sign
al
Outpu
t
signal
Short-time Fourier Transform

Sample code for STFT


Multi-resolution analysis

The time window is not fixed anymore.

MRA analyzes different frequency at different time


resolution. So, every spectral component is not
resolved equally.
MRA gives
At high frequency : Good time resolution but poor freq
resolution
At low frequency : Good freq resolution but poor time resolution

The above is tolerable when we have high freq


component for short period of time and low freq
component for long period of time.

Most of the practical signals are of this type.


Wavelet Transform
We have looked at Fourier Transform now it is time to look at
others.
A few other signal processing techniques are
Hilbert transform
Short-time Fourier transform (more about this later)
Wigner distributions
Radon Transform
Wavelet transform

THE LIST IS LONG!!!!


Each one has its own characteristics and utilities.
We will particularly look at the Wavelet Transform.
What makes it different and possibly in cases more useful than
Fourier Transform
What are the uses of Fourier Transform.
Wavelet Transform

We can do fourier Transform


Fourier Transform is a reversible transform we can go back and
forth between time domain and frequency domain
But we cannot have both at the same time in time domain
signal we do not have frequency information and in frequency
domain (fourier transformed signal ) ,we do not have time
information.
What if we want to have both at the same time?
That means fourier transform can tell us which frequency
component is contained in the signal but it cannot say when it
occurs in time in the signal.
When in time the
signal with this
frequency
component occurs??
When in time the
signal with this
frequency
component
occurs??
When do we need WT??

First we have to understand when we dont need the


WT ??
When the signal is stationary (stationary signals are very
important in signal analysis)
Definition - The signal whose frequency components do not
change with time is called stationary signal. In other words, the
frequency components of the signal do not change with time.
So, all the frequency components exist all the time so one
does not need to know which frequency component comes into
play at what point in time.
Ex : x(t)=cos(2*pi*10*t)+cos(2*pi*25*t)+cos(2*pi*50*t)
+cos(2*pi*100*t)
There are 4 frequency components 10Hz, 25Hz, 50Hz and 100Hz
These 4 components exist at every point in time.
FFT
When do we need WT??

But look at the following signal. It does not have all the
frequency component present at all the time!!!
The frequency
changes with
time!!!
0 300
ms
100 Hz
sine
300
600 ms
has a
50Hz
sine
600-
800 ms
has a
25Hz
sine
800
1000 has
a 10 Hz
sine
Consider another
one
FFT of
this
Results
in
Shows the 4 component frequency
but does not say at which point in
time these 4 frequencies occur
When do we need Wavelet
Transform??

So, for non-stationary signals, if we dont need the


time information related to the occurrence of each
component frequency, Fourier transform is enough.

Otherwise, go for the wavelet transform.

Some practical non-stationary signals


ECG - ecocardiogram
EEG - electroencephalograph
EMG electromyogram

Wavelet transform gives time frequency information at


the same time. Some other transforms gives it too.
Short time fourier analysis
Wigner transform
Do I need Wavelet Transform

Our need spectral analysis of accelerometer reading


of human gait
Is human gait a non-stationary signal?
Is it possible that at certain points in one gait cycle, some
frequency components occur ?
We dont know the answer we need to figure out.
What is resolution????

In this discussion resolution is directly analogous to


precision.

Precision = how near you can go to the exact value


99.999999999999% = this is high precision when exact value is
100
Accuracy = Is the value you are producing correct??
f(x) = x^2 ; f(2) should be 4, you produce 3; so, not accurate.

Generally, we need higher resolution(precision) for


smaller values
f = 2.3; if we say 2.1 then we are loosing (2.3-2.1 = 0.2/2.1 =
10% ) a lot for such a small range
So we need to be more precise (have higher resolution) for
smaller values

We can have lower resolution at higher values


f = 10000;if we say f = 9950 then(10000-9950 = 50/9950 =
0.5%) , so we do not loose much.
So, we can afford less resolution at higher values of frequency
Resolution contd

In signal analysis = higher frequency components occur


less time
Freq is higher = so low resolution is OK. Time is smaller, so high
reolution is needed

In signal analysis = lower frequency components occur


for more time
Time is higher = so lower resolution is OK, frequency is smaller
= so higher resolution is needed

Wavelet gives us just that thing for lower values (of


either time or frequency) it gives higher resolution.
Example Non Stationary Signal
x = (1.3)*sin(2*pi*15*power(t,2)) +
(1.7)*sin(2*pi*30*power(t,2));

Corresponding Signal in MATLAB


The signal looks like
Correspondi
ng FFT
Fourier Transform VS Wavelet Transform
X( f ) x(t)
jt
e

dt
The input signal
The complex exponential
,
[ ]
x

CWT
(, s)
x

(, s)
1
s
x(t)

t
s

_
,
dt
The input signal
The mother wavelet
Fourier Transform VS Wavelet Transform
The mother
wavelet is
translated
gradually from
the beginning to
the end of the
input signal
Then the mother
wavelet is
scaled(dilated or
compacted) and
the whole
translation
process is
repeated again.
Similarity between FT and WT

Both breaks a signal to its constituent parts for


analysis.
Classification of WT
Actually there is nothing continuous about scale and translation when it comes to
computer simulation of wavelet transform. Because computers does not generate
continuous points it generates discrete points. We can only say that CWT is much
Smoother than DWT.
Result analysis

How to interpret the results of the wavelet transform.

First we try to understand what the MATLAB function


returns
Co-efficients = cwt(x(t),scaleRange,waveletName)
computes the wavelet transform of the input signal x(t) with the
positive scaleRange using the mother wavelet with
waveletName
Ex: Co-efficients = cwt(x(t),1:128,haar) mother wavelet is
haar, the scale is 1 to 128 .So, there are 128 rows of output co-
efficient values where each row corresponds to 1 scale. Column
dimension each row = duration length of input signal.
Result Analysis

Wavelet transform
output in 2D and 3D plot
Input signal
Different mother wavelet produces different Wavelet transform result on the same input
CWT using
Morlet
mother wavelet
CWT using
Haar mother
wavelet
Signals at 3
different
scales (10,50
and 90)
Signals at 3
different
scales(10,50
and 90)
Fouriers Idea
Describe complicated function as a weighted sum of simpler functions!
-
simpler functions are known
-
weights can be found

Simpler functions - sines and cosines are orthogonal on period T, i.e.
f(mt) f(nt)
0
T

dt 0 for m n
period T period T
Basics of Signal Processing
SIGNAL SOURCE
RECEIVER
describe waves in terms of their
significant features
understand the way the waves originate
effect of the waves
will the people in the boat notice ?
ACTION
frequency = 1/T
speed of sound T, where T is a period
sine wave
period (frequency)
amplitude
phase

f (t) Asin(2t/T+ )

f (t) Asin(t+ )

Asin(t+ /2)
Acos(t)
sine cosine
Phase
Sinusoidal grating of image

Fourier idea

describe
the signal
by a sum of
other well
defined
signals
T
O
Fourier Series
A periodic function as an infinite weighted
sum of simpler periodic functions!
f(t) w
i
i0

f
i
(t)
A good simple function
T
i
=T
0
/ i

f
i
(t) sin(i
2
t+),
where
2
2 / T
2

f (t) k
i
sin(i
0
i1

+
n
)
[b
i
i1

sin(i
0
) + a
i
cos(i
0
)]
Re

c
i
e
j
0
n
i 0

,

c complex
e.t.c. ad infinitum

f (t) k
i
sin(i
0
i1

+
n
) [b
i
i1

sin(i
0
) + a
i
cos(i
0
)]
T=1/f
e.t.c
T=1/f
e.t.c
Fouriers Idea
Describe complicated function as a weighted sum of simpler functions!
-
simpler functions are known
-
weights can be found

Simpler functions - sines and cosines are orthogonal on period T, i.e.
f(mt) f(nt)
0
T

dt 0 for m n
period T period T
Orthogonality

sin nt cos mtdt 0
0
T

cos nt cos mtdt 0 for n mand


T
2
0
T

for n m
sin nt sin mtdt 0 for n mand
T
2
0
T

for n m
0
+
-
0
+
-
0
+
-
x
0
+ +
- -
x
0
+ +
=
0
+ +
- -
=
area is positive (T/2) area is zero
f(t) = 1.5 + 3sin(2t/T) + 4sin(4t/T)
= +
+
0 T

1
T
f(t)dt
0
T

1.5
0 T
1.5

b
1

2
T
f
0
T

(t)sin(
2t
T
)dt 3
=
+
+
0 T
0 3 0
=

f(t) DC+ a
i
cos(
2it
T
) + b
1
sin(
2it
T
)



1
]
1

i1

DC+ a
1
cos(
2t
T
) + b
1
sin(
2t
T
) + a
2
cos(
4t
T
) + b
2
sin(
4t
T
) + a
3
cos(
6t
T
) + b
3
sin(
6t
T
) + .........

f(t)sin(
2t
T
)dt
0
T

{DC
0
T

sin(
2t
T
) + a
1
cos(
2t
T
)sin(
2t
T
) + b
1
sin(
2t
T
)sin(
2t
T
) + a
2
cos(
4t
T
)sin(
2t
T
) + b
2
sin(
4t
T
)sin(
2t
T
) + .........}dt
0 0 b
1
T/2 0 0
area=b
1
T/2
area=b
2
T/2

f(t) DC+f
1
(t) +f
2
(t) DC+b
1
sint +b
2
sin2t

sin
2
0
T

(
t
T
) dt
T
2
T=2
+
-
+ +
+ + + +
+
+
+
+
+ +
- -
- - - -
f(t)
f(t) sin(2t)
f(t) sin(4t)
area = DC area = b
1
T/2 area = b
2
T/2
Spacing of spectral components is 1/T
Periodicity in one domain (here time)
implies discrete representation in the dual
domain (here frequency)
0 1/T 2/T
frequency
0 1/T 2/T
frequency
Phase spectrum Magnitude spectrum
Aperiodic signal
Discrete spectrum becomes continuous (Fourier integral)
0 1/T
0
2/T
0
frequency
0 1/T
0
2/T
0
frequency
Phase spectrum Magnitude spectrum
Spacing of spectral components is f
0
=1/T
0
Magnitude spectrum of voiced
speech signal
frequency
log | S() |
F
1
F
2
F
3
F
4
f
0
1/f
0
1/F
1
1/F
2
Waveform
Logarithmic power spectrum
f
0
F
1
F
2
F
3
P
R
O
C
E
S
S
I
N
G
One way of signal processing
Going digital
sampling
22 samples per 4.2 ms 0.19 ms per sample 5.26 kHz
t
s
=1/f
s
Sampling
> 2 samples per period,
f
s
> 2 f
T = 10 ms (f = 1/T=100 Hz)
Sinusoid is characterized by three parameters
1.Amplitude
2.Frequency
3.Phase
We need at least three samples per the period
T = 10 ms (f = 1/T=100 Hz)
t
s
= 7.5 ms (f
s
=133 Hz < 2f )
Undersampling
T = 40 ms
(f= 25 Hz)
Sampling at the Nyquist frequency
2 samples per period,
f
s
= 2 f
Nyquist rate
t
s
= 5 ms (f
s
=200 Hz)
?
??
f
s
> 2 f
Sampling of more complex signals
period period
highest frequency
component
Sampling must be at the frequency which is higher than the twice
the highest frequency component in the signal !!!
f
s
> 2 f
max
Sampling
1. Make sure you know what is the highest
frequency in the signal spectrum f
MAX
2. Chose sampling frequency f
s
> 2 f
MAX
NO NEED TO SAMPLE ANY FASTER !
Periodicity in one domain implies discrete
representation in the dual domain
0 1/T 2/T
frequency
Magnitude spectrum T
frequency
F

=1/t
s
f
s
= 1/T
time
t
s
T
Sampling in time implies periodicity in frequency !


1
0
2
1
) ( ) (
N
n
N
kn
j
N
e k X n x


1
0
2
1
) ( ) (
N
n
N
kn
j
N
e n x k X

Discrete and periodic in both domains (time and frequency)


DISCRETE FOURIER TRANSFORM
Recovery of analog signal
Digital-to-analog converter (sample-and-hold)
Low-pass filtering
0.000000000000000
0.309016742003550
0.587784822932543
0.809016526452407
0.951056188292881
1.000000000000000
0.951057008296553
0.809018086192214
0.587786969730540
0.309019265716544
0.000000000000000
-0.309014218288380
-0.587782676130406
-0.809014966706903
-0.951055368282511
-1.000000000000000
-0.951057828293529
-0.809019645926324
-0.587789116524398
-0.309021789427363
-0.000000000000000
Quantization
11 levels
21 levels
111 levels
a part of vowel /a/
16 levels (4 bits) 32 levels (5 bits) 4096 levels (12 bits)
Quantization

Quantization error = difference between the


real value of the analog signal at sampling
instants and the value we preserve

Less error less quantization distortion


Discrete Fourier Transform (DFT)
Takes a discrete signal in time domain transform the signal into
discrete frequency domain representation.
2 concepts Discrete Fourier Transform(DFT), Discrete time Fourier
Transform(DTFT).
Discrete time signal [DFT] Discrete Frequency Domain
Discrete Time Signal [DTFT] Continuous frequency domain
In DTFT, frequency becomes continuous but in DFT , frequency is
discrete.
We are working with DFT only.

S-ar putea să vă placă și