Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

4/7/2014

An Introduction to
Short-Time Fourier Transform (STFT)

Advanced Structural Dynamics

M Ahmadizadeh, PhD, PE

Contents

• Scope and Goals

• Fourier Transform Review


– Advantages of Fourier Transform
– Limitations of Fourier Transform

• Short Time Fourier Transform


– Concept
– Formulation
– Examples
• Use of MATLAB
– Applications

1
4/7/2014

Scope and Goals

• To expand the capabilities of Fourier transform for time-


varying signals

• In addition to showing the frequency content of the signals,


it is also desirable to have an idea of when each frequency
content is dominant

• Describing complicated signals with fewer number of


frequencies

Fourier Transform

• Fourier analysis expands signals or functions in terms


of sinusoids (or complex exponentials).
• It reveals all frequency components present in a
signal.

Inverse DFT

DFT

2
4/7/2014

Fourier Transform

• Example: 5 Hz Signal
5 Hz
1

0.5
Signal

-0.5

-1
0 0.2 0.4 0.6 0.8 1
Time (s) Output
Amplitude 20

10

0
0 20 40 60 80 100

5
Phase

-5
0 20 40 60 80 100
Frequency (Hz) 5

Fourier Transform

• Example: 15 Hz Signal
15 Hz
1

0.5
Signal

-0.5

-1
0 0.2 0.4 0.6 0.8 1
Time (s) Output
20
Amplitude

10

0
0 20 40 60 80 100

10
Phase

0
0 20 40 60 80 100
Frequency (Hz) 6

3
4/7/2014

Fourier Transform

• Example: 30 Hz Signal
30 Hz
1

0.5
Signal

-0.5

-1
0 0.2 0.4 0.6 0.8 1
Time (s) Output
Amplitude 20

10

0
0 20 40 60 80 100

10
Phase

0
0 20 40 60 80 100
Frequency (Hz) 7

Fourier Transform

• Example: Signal Containing 5, 15 and 30 Hz Components


3 Frequencies
3

1
Signal

-1

-2

-3
0 0.2 0.4 0.6 0.8 1 Output
Time (s) 15
Amplitude

10

0
0 20 40 60 80 100

10
Phase

0
0 20 40 60 80 100
Frequency (Hz)
8

4
4/7/2014

Fourier Transform - Limitations

• Cannot provide information about both time and


frequency – i.e. cannot provide simultaneous time and
frequency localization

–  Not suitable for analyzing time-variant, non-


stationary signals

• As an example, it cannot be used to analyze the signals


obtained from nonlinear or damaged structures, since they
may contain varying frequency content at different times

Fourier Transform - Limitations

• Signals: Stationary vs Non-stationary

– Stationary signals have properties (e.g frequency


content) that does not change over time
3 Frequencies
3

Sum of 3 signals, present at all


1
Signal

times -1

-2

-3
0 0.2 0.4 0.6 0.8 1
Time (s)

– Non-stationary signals may have different frequencies at


different times 1
3 Frequencies

0.5

Combination of 3 signals
Signal

occurring at different times -0.5

-1
0 0.2 0.4 0.6 0.8 1
Time (s)

10

5
4/7/2014

Fourier Transform - Limitations

• 5, 15 and 30 Hz Components at Different Times


3 Frequencies
1

0.5
Signal

-0.5

-1
0 0.2 0.4 0.6 0.8 1
Output
Time (s)
4

Amplitude
2

Excellent frequency 0
0 20 40 60 80 100
localization (shows all 50
existing frequencies), but 0
no time localization
Phase

-50

-100
0 20 40 60 80 100
Frequency (Hz)
11

Fourier Transform - Limitations

• Not appropriate for representing discontinuities or


sharp corners

–  Requires a large number of Fourier components to


represent discontinuities).

12

6
4/7/2014

Fourier Transform - Limitations

• El Centro Earthquake Record and its Fourier transform


El Centro
3

1
Acceleration

-1

Output
-2 3

Amplitude
-3 2

-4 1
0 5 10 15 20 25 30 35
Time 0
0 5 10 15 20 25 30

500
Phase

-500
0 5 10 15 20 25 30
Frequency (Hz) 13

Fourier Transform - Limitations

• El Centro Earthquake Record and its Fourier transform


El Centro
3

1
Acceleration

-1 -3 El Centro - Components: 1
x 10
1
-2

-3
0.5
-4
0 5 10 15 20 25 30 35
Acceleration

Time
0

Included Signals: 1 -0.5

-1
0 5 10 15 20 25 30 35
Time

14

7
4/7/2014

Fourier Transform - Limitations

• El Centro Earthquake Record and its Fourier transform


El Centro
3

1
Acceleration

-1 El Centro - Components: 10
0.15
-2
0.1
-3
0.05
-4
0 5 10 15 20 25 30 35

Acceleration
Time 0

-0.05

Included Signals: 10 -0.1

-0.15

-0.2
0 5 10 15 20 25 30 35
Time

15

Fourier Transform - Limitations

• El Centro Earthquake Record and its Fourier transform


El Centro
3

1
Acceleration

-1 El Centro - Components: 50
1.5
-2

-3 1

-4 0.5
0 5 10 15 20 25 30 35
Acceleration

Time
0

-0.5
Included Signals: 50
-1

-1.5
0 5 10 15 20 25 30 35
Time

16

8
4/7/2014

Fourier Transform - Limitations

• El Centro Earthquake Record and its Fourier transform


El Centro
3

1
Acceleration

-1 El Centro - Components: 200


3
-2

-3 2

-4 1
0 5 10 15 20 25 30 35

Acceleration
Time
0

-1
Included Signals: 200
-2

-3
0 5 10 15 20 25 30 35
Time

17

Fourier Transform - Limitations

• El Centro Earthquake Record and its Fourier transform


El Centro
3

1
Acceleration

-1 El Centro - Components: 800


3
-2
2
-3
1
-4
0 5 10 15 20 25 30 35
Acceleration

Time 0

-1

Included Signals: 800 -2

-3

-4
0 5 10 15 20 25 30 35
Time

18

9
4/7/2014

Short-Time Fourier Transform

• Basic Concept:

– Break up the signal in time domain to a number of


signals of shorter duration, then transform each signal
to frequency domain

• Requires fewer number of harmonics to regenerate the


signal chunks

• Helps determine the time interval in which certain


frequencies occur

19

Short-Time Fourier Transform

• Consider the first 3 seconds of the El Centro Record


El Centro
3

1
Acceleration

-1

-2
Output
4
-3
Amplitude

-4 2
0 0.5 1 1.5 2 2.5 3 3.5
Time

0
0 5 10 15 20 25 30

100

50
Phase

-50
0 5 10 15 20 25 30
Frequency (Hz)

20

10
4/7/2014

Short-Time Fourier Transform

• Consider the first 3 seconds of the El Centro Record


El Centro
3

1
Acceleration

-1

-2 El Centro - Components: 10
3
-3
2
-4
0 0.5 1 1.5 2 2.5 3 3.5
Time 1

Acceleration
0
Included Signals: 10
-1

-2

-3
0 0.5 1 1.5 2 2.5 3 3.5
Time

21

Short-Time Fourier Transform

• Consider the first 3 seconds of the El Centro Record


El Centro
3

1
Acceleration

-1

-2 El Centro - Components: 30
3
-3
2
-4
0 0.5 1 1.5 2 2.5 3 3.5
Time 1
Acceleration

0
Included Signals: 30
-1

-2

-3
0 0.5 1 1.5 2 2.5 3 3.5
Time

22

11
4/7/2014

Short-Time Fourier Transform

• Consider the first 3 seconds of the El Centro Record


El Centro
3

1
Acceleration

-1

-2 El Centro - Components: 80
3
-3
2
-4
0 0.5 1 1.5 2 2.5 3 3.5 1
Time

Acceleration
0

Included Signals: 80 -1

-2

-3

-4
0 0.5 1 1.5 2 2.5 3 3.5
Time

23

Short-Time Fourier Transform

• Or consider the first chunk of non-stationary record


3 Frequencies
1

Knowing the
location of the
0.5
considered chunk
in time and its
frequency
Signal

0 content, we can
get an idea of the
time each
-0.5 frequency exists.

-1
0 0.2 0.4 0.6 0.8 1
Time (s)

24

12
4/7/2014

Short-Time Fourier Transform

 Need a local analysis scheme for a time-frequency


representation (TFR).
 Windowed F.T. or Short Time F.T. (STFT)
 Segmenting the signal into narrow time intervals (i.e.,
narrow enough to be considered stationary).
 Take the Fourier transform of each segment.
Non-Stationary
1

0.5
Signal

-0.5

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (s)

25

Short-Time Fourier Transform

• Steps:
– Choose a window function of finite length
• A window function is a function that is multiplied by the signal to
keep a certain portion of it

– Place the window on top of the signal at t=0

– Truncate the signal using this window


26

13
4/7/2014

Short-Time Fourier Transform

• Steps (continued)
– Compute the FT of the truncated signal, save results.
• For each time location where the window is centered, we
obtain a different FT
– Each FT provides the spectral information of a separate time-
slice of the signal, providing simultaneous time and frequency
information

– Incrementally slide the window to the right

– Repeat until window reaches the end of the signal

27

Short-Time Fourier Transform

• What is being Fourier-transformed: Window Length: 0.2s


Hann Windowed Non-Stationary Signal Hann Windowed Non-Stationary Signal Hann Windowed Non-Stationary Signal
0.8 1 1

0.6

0.4 0.5 0.5

0.2
Signal
Signal

Signal

0 0 0

-0.2

-0.4 -0.5 -0.5

-0.6

-0.8 -1 -1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Time (s) Time (s) Time (s)

  0.1s   0.5s   0.9s


Hann Windowed Non-Stationary Signal Hann Windowed Non-Stationary Signal
0.8 1

0.6

0.4 0.5

0.2
Signal

Signal

0 0

-0.2

-0.4 -0.5

-0.6

-0.8 -1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Time (s) Time (s)

  0.3s   0.7 s
28

14
4/7/2014

Short-Time Fourier Transform

• Fourier transforms of windowed signal:

Output Output Output


1.5 1.5 1.5
Amplitude

Amplitude

Amplitude
1 1 1

0.5 0.5 0.5

0 0 0
0 20 40 60 80 100
0 20 40 60 80 100
0 20 40 60 80 100

  0.1s   0.5s   0.9s


5 4 20

0 2
Phase
Phase

Phase
10
-5 0
Output Output
-10 1 -2 1 0
0 20 40 60 80 0
100 20 40 60 80 100
0 20 40 60 80 100
Frequency (Hz) Frequency (Hz) Frequency (Hz)
Amplitude

Amplitude
0.5 0.5

0 0
0 20 40 60 80 100 0 20 40 60 80 100

  0.3s   0.7 s
0 300

-100 200
Phase

Phase

-200 100 29

-300 0
0 20 40 60 80 100 0 20 40 60 80 100
Frequency (Hz) Frequency (Hz)

Short-Time Fourier Transform

• Now we can plot the spectra next to each other to


generate a surface:

Amplitude (Window) Time

Frequency
30

15
4/7/2014

Short-Time Fourier Transform

• Formulation:
– Continuous STFT

STFT  x(t ) ,    X  ,     x(t ) w  t    e
 it
dt

of the phase result of the STFT


axis, τ, and frequency axis, ω, to suppress any jump discontinuity
Often phase unwrapping is employed along either or both the time


x(t ) Time-domain signal to be transformed

 Time (slow time; lower resolution than t)


 Frequency

w t  Window function, commonly a Hann window or


Gaussian window bell centered around zero

X  ,   A complex function representing the phase and


magnitude of the signal over time and frequency (this
is essentially the Fourier Transform of x (t ) w t   ) 
31

Short-Time Fourier Transform

• Formulation:
Time discretized, frequency continuous; but if
– Discrete STFT FFT is used, they both will be discrete.

STFT  xn  m,    X  m,    xw
n 
n nm e  itn

xn Sequence of discretized time-domain signal to


be transformed
m Time index
 Frequency

wn Sequence of discretized window function

X  m,   STFT of the time-domain sequence

32

16
4/7/2014

Short-Time Fourier Transform

• Inverse STFT
– The original signal can be recovered from the transform
by the Inverse STFT. The most widely accepted way of
inverting the STFT is by using the overlap-add (OLA)
method, which also allows for modifications to the STFT
complex spectrum.

• Calculating the Inverse STFT:


– First, it is required that the window function must be
scaled such that the area underneath the window
function is unity:

33

Short-Time Fourier Transform

• Calculating the Inverse STFT (Continued):


– It follows that:

– Hence:

– The continuous Fourier transform is:

– Substituting from above:

34

17
4/7/2014

Short-Time Fourier Transform

• Calculating the Inverse STFT (Continued):


– Swap the integration order:

– Since the inverse Fourier transform is:

– Then the time-domain signal can be recovered:

35

Short-Time Fourier Transform

• Calculating the Inverse STFT (Continued):

– Or:

– Alternatively, one can obtain windowed grain or wavelet


of x(t) as:

36

18
4/7/2014

Short-Time Fourier Transform

• Time and Frequency Resolution:


– The STFT has a fixed resolution
• The width of the windowing function relates to how the
signal is represented

• It determines whether there is good frequency resolution


(frequency components close together can be separated)
or good time resolution (the time at which frequencies
change).

• A wide window (wideband transform) gives better


frequency resolution but poor time resolution.

• A narrower window (narrowband transform) gives good


time resolution but poor frequency resolution.
37

Short-Time Fourier Transform

• Time and Frequency Resolution (Continued):


– That is, we cannot have good resolutions in both time
and frequency.

Good time resolution, poor Good frequency resolution,


frequency resolution poor time resolution

38

19
4/7/2014

Short-Time Fourier Transform

• Time and Frequency Resolution (Continued):


– To explain this limitation, note that in Fourier transform:
• To increase the frequency resolution of the window the
frequency spacing of the coefficients (sequence in
frequency domain) needs to be reduced.

– Decreasing Nyquist (max) frequency (and keeping N constant)


will cause the window size to increase — since there are now
fewer samples per unit time.

– The other alternative is to increase N, but this again causes


the window size to increase.

– So any attempt to increase the frequency resolution causes a


larger window size and therefore a reduction in time
resolution—and vice-versa.

39

Short-Time Fourier Transform

• Time and Frequency Resolution (Continued):


– Best simultaneous resolution of both is reached with a
Gaussian window function. This STFT with some
modifications for multi-resolution becomes the Morlet
wavelet transform.

– Window should be narrow enough to make sure that the


portion of the signal falling within the window is
stationary.

– Very narrow windows do not offer good localization in


the frequency domain.

40

20
4/7/2014

Short-Time Fourier Transform

• Time and Frequency Resolution (Continued):


– Windowing Function infinitely long: w(t )  1
• STFT turns into FT, providing excellent frequency
localization, but no time information.


X  ,     x(t )e
 it
dt  X  


– Windowing Function infinitely short: w(t )   (t )


• gives the time signal back, with a phase factor, providing
excellent time localization but no frequency information.

X  ,     x(t ) (t   )e
 it
dt  x( )e  i

41

Short-Time Fourier Transform

• Heisenberg (Uncertainty) Principle:

1
t f 
4

Time resolution: How well Frequency resolution:


two spikes in time can be How well two spectral
separated from each other components can be
in the transform domain. separated from each other
in the transform domain.

𝜟𝒕 𝒂𝒏𝒅 𝜟𝒇 𝒄𝒂𝒏𝒏𝒐𝒕 𝒃𝒆 𝒎𝒂𝒅𝒆 𝒂𝒓𝒃𝒊𝒕𝒓𝒂𝒓𝒊𝒍𝒚 𝒔𝒎𝒂𝒍𝒍 !

42

21
4/7/2014

Short-Time Fourier Transform

• Heisenberg (Uncertainty) Principle (Continued):

– One cannot know the exact time-frequency


representation of a signal.

– We cannot precisely know at what time instance a


frequency component is located.

– We can only know what interval of frequencies are


present in which time intervals.

43

Short-Time Fourier Transform

• Example:
– Chirp Signal (linear frequency variation 10-200 Hz)

0.5
x(t)

-0.5

-1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1


Time (sec)

500 points spaced at 0.002 s, variable window sizes

44

22
4/7/2014

Short-Time Fourier Transform

• Example (Continued):
– Chirp Signal – Ordinary Fourier Transform

Output
0.8

Amplitude 0.6

0.4

0.2

0
0 50 100 150 200 250

-100

-200
Phase

-300

-400

-500
0 50 100 150 200 250
Frequency (Hz)
45

Short-Time Fourier Transform

• Example (Continued):
– Chirp Signal – Window Size: 128 points
Window size = 128 Window type = Hann Window size = 128 Window type = Hann
250

20 200
Frequency (Hz)

15

150
10

5 100

0
250
50
200 1
150 0.8
100 0.6
0.4
50 0.2 0
0 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency (Hz) Time (sec) Time (sec)

46

23
4/7/2014

Short-Time Fourier Transform

• Example (Continued):
– Chirp Signal – Window Size: 64 points
Window size = 64 Window type = Hann Window size = 64 Window type = Hann
250

20 200

Frequency (Hz)
15
150
10

5 100

0
250 50
200 1
150 0.8
100 0.6
0.4
50 0.2 0
0 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency (Hz) Time (sec) Time (sec)

47

Short-Time Fourier Transform

• Example (Continued):
– Chirp Signal – Window Size: 32 points
Window size = 32 Window type = Hann Window size = 32 Window type = Hann
250

20
200

15
Frequency (Hz)

150
10

5 100

0
250
50
200 1
150 0.8
100 0.6
0.4
50 0.2 0
0 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency (Hz) Time (sec) Time (sec)

48

24
4/7/2014

Short-Time Fourier Transform

• Use of MATLAB:
– The MATLAB command to perform STFT is spectrogram:

[B, f, t] = spectrogram(x, window, noverlap, nfft, fs)

– Spectrogram inputs:
• x: input signal (signal to be transformed)
• window function (discrete window at the same input rate)
• window overlap (in terms of number of points)
• sampling points for FFT (number of points used in FFT)
• sampling frequency (rate of sampling for the input signal
and the window function)

– Spectrogram outputs: Transformed signal, frequencies


and times.
49

Short-Time Fourier Transform

• Applications:

– Signal processing of any non-stationary signal (audio


signals, earthquake excitations, structural responses to
ambient vibrations, …)

– In structural dynamics, STFT can be used to:


• Determine the dominant modes of vibration (and their
shapes and frequencies) at any time interval
• Health monitoring and damage detection through the study
of dominant frequencies
– e.g. a reduction in frequency is generally indicative of
damages leading to softer structures

50

25
4/7/2014

Short-Time Fourier Transform

• Applications:
– Damage Detection Example:
• 2-Story structure, natural frequencies 2.2 and 5.8 Hz
• Response simulated to El Centro record
• Linear Response
5
x 10
0.04 2
Displacement, m

0.02 1

Force, N
0 0

-0.02 -1

-0.04 -2
0 10 20 30 40 -0.02 -0.01 0 0.01 0.02
Time, s Displacement, m
4
x 10
2.5 1
51
Number of Iterations

2 0.8
Energy, N-m

1.5 0.6
Internal
1 Input 0.4

0.5 0.2

0 0
0 10 20 30 40 0 10 20 30 40
Time, s Time, s

Short-Time Fourier Transform

• Applications:
– Damage Detection Example:
• 2-Story structure, natural frequencies 2.2 and 5.8 Hz
• Response simulated to El Centro record
• Nonlinear Response (by defining a yield displacement)
5
x 10
0.04 2
Displacement, m

0.02 1
Force, N

0 0

-0.02 -1

-0.04 -2
0 10 20 30 40 -0.02 -0.01 0 0.01 0.02
Time, s Displacement, m
4
x 10
2.5 30
52
Number of Iterations

2
Energy, N-m

20
1.5
Internal
1 Input
10
0.5

0 0
0 10 20 30 40 0 10 20 30 40
Time, s Time, s
26
4/7/2014

Short-Time Fourier Transform

• Applications:
– Damage Detection Example: Linear Response
0.02

0.01
x(t)

-0.01

-0.02
0 5 10 15 20 25 30 35
Time (sec)

Window size = 2048 Window type = Chebyshev


10
Frequency (Hz)

0
0 5 10 15 20 25 30
Time (sec)
53

Short-Time Fourier Transform

• Applications:
– Damage Detection Example: Nonlinear Response
0.02

0.01
x(t)

-0.01

-0.02
0 5 10 15 20 25 30 35
Time (sec)

Window size = 2048 Window type = Chebyshev


10
Frequency (Hz)

0
0 5 10 15 20 25 30
Time (sec)
54

27

You might also like