0% found this document useful (0 votes)
74 views69 pages

Lecture2 Noise Freq

Very Very good notes

Uploaded by

Zain Ul Abideen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views69 pages

Lecture2 Noise Freq

Very Very good notes

Uploaded by

Zain Ul Abideen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Biomedical Signals

Signals and Images in Medicine


Lecture 2
Dr Nabeel Anwar

Noise Removal: Time Domain


Techniques
1. Synchronized Averaging (covered in lecture 1)
2. Moving Average Filters (todays topic)
3. Derivative based operations to remove low frequency
artifacts (todays topic)
4. Introduction to frequency domain

Moving Average Filters


Problem:
Propose a time-domain technique to remove random noise
given only one realization of the signal or event of interest.

Moving Average (MA) Filter


Ensemble of several realizations not available
synchronized averaging is not possible.
Consider temporal averaging for noise removal
Temporal window of samples moved to obtain output at
various points of time: moving-window averaging or movingaverage (MA) lter.

Average weighted combination of samples

Moving Average (MA) Filter


Rangarajs book 3.3.2
x and y: input and output of lter.
bk: lter coefcients or tap weights.
N: order of lter.

Moving Average (MA) Filter


Basic Concept OF Z-Transform
Z-Transform is a digital operation
When identified with a digital data
sequence, such as x(n) , zn represents an interval shift of n samples, or an
associated time shift of nTs seconds.
Every data sample in the sequence x(n) is associated with a unique power
of z, and this power of z defines a samples position in the sequence.
For example, the time shifting characteristic of the Z-transform can be
used to define a unit delay process, z1. For such a process, the output is
the same as the input, but shifted (or delayed) by one data sample

Delay of one Sample

Consider the system y[n] = x[n-1], i.e., the onesample-delay system.


The z-transform system function is

H z z 1

Z-1

Delay of k Samples

Similarly, the system y[n] = x[n-k], i.e., the k-sampledelay system, is the z-transform of the impulse
response x[n - k].

H z z

Z-k

Moving Average (MA) Filter

Signal-flow diagram of a moving-average filter of order N. Each block with the symbol
z1 represents a delay of one sample, and serves as a memory unit for the
corresponding signal sample value.

Example: Running Average Algorithm


xk xk 1 xk 2 xk 3
yk
4

(Non-Recursive)

1 z 1 z 2 z 3
z3 z2 z 1
Y z X z
X z
4
4z 4

Block Diagram

Z Transform

Transfer Function

Y
z3 z2 z 1
z
X
4z 4

Note: Each [Z-1] block can be thought of as a memory cell,


storing the previously applied value.

Moving Average (MA) Filter


Moving Average can be symmetrical or non-symmterical.
e.g. Y[80] = ( x[80] + x[79]+x[78] +x[77]) / 4 : non-

symmterical.
Y[80] = ( x[79] + x[80]+x[81] ) / 3 : symmterical
A potential problem is look-ahead

Moving Average (MA) Filter

See Fig 15-1 in DSP Guide

Moving Average (MA) Filter


Examples of moving average
Moving average term is used for any process that uses a moving
set of multiplier weights. That means we have finite number of
weights. It gives the concept that
An MA filter is a finite impulse response (FIR) filter:
Output depends only on the present input sample and a few
past input samples.

MA: Application Example


ECG signal with 1000 Hz noise

8 points moving average filter

Moving average is Recursive


A tremendous advantage of the moving average filter is that it can be
implemented with an algorithm that is very fast.

Assignment 2
Apply an 8 point moving average filter on the raw ECG data
already provided.
Apply a 32 point filter on the raw ECG data.

What is the difference? Does 32 point filter preserved


information?

Frequency Analysis

Next few slides are taken from book Advanced Engineering Mathematics by Erwin Kreyszig John Wiley & Sons,
Inc. Consult the book for further info.

Pages 478-479b

Advanced Engineering
Mathematics by Erwin Kreyszig
Copyright 2007 John Wiley &
Sons, Inc. All rights reserved.

Advanced Engineering
Mathematics by Erwin Kreyszig
Copyright 2007 John Wiley &
Sons, Inc. All rights reserved.

Pages 480-482c

Fourier Transform
Before we start, lets discuss a little about Fourier Transform.
The basic idea is: A signal can be decomposed into periodic
cosine and sine waves with different frequencies.

Fourier Analysis has four categories (Slide 30-31: taken from


Smiths book)

Frequency Spectra
example : g(t) = sin(2f t) + (1/3)sin(2(3f) t)

Frequency Spectra

Example: Music
We think of music in terms of frequencies at different
magnitudes

Time information is LOST

Fourier Transforms
All of us has basic concept of functions.
In signal processing, most functions fall into two categories:
1. waveforms, images, or other data;
2. and entities that operate on waveforms, images, or other data
The later group can be further divided into functions
i.
that modify the data,
ii. and functions used to analyze or probe the data.
For example, the basic filters use functions (the filter coefficients) that
modify the spectral content of a waveform.
The Fourier Transform detailed uses functions (harmonically related
sinusoids) to analyze the spectral content of a waveform.
Functions that modify data are also termed operations or transformations.

Fourier Transform
A transform can be thought of as a re-mapping of the original
data into a function that provides more information than the
original.
The Fourier Transform is classic example as it converts the
original time data into frequency information which often
provides greater insight into the nature and/or origin of the
signal.

Fourier Transform
How we do that?....

Many of the transforms are achieved by comparing the signal of


interest with some sort of probing function. This comparison
takes the form of a correlation (produced by multiplication) that
is averaged (or integrated) over the duration of the waveform,
or some portion of the waveform:

Fourier Transform
It is a technique for examining signals in the frequency domain.
Our immediate goal is to represent a given function as a
convergent series in the elementary trigonometric functions
(already studied them few slides before)

f(x)

Fourier
Transform

F(w)

Fourier Analysis
a0
2nt
2nt
f (t ) an cos
bn sin
2 n 1
T
T
n 1
DC Part

Even Part

Odd Part

T is a period of all the above signals

with the first term


a0 representing the direct current (DC) component;
the remaining sine and cosine waves weighted by the an and bn coefficients
represent the alternating current (AC) components of the signal. It is very important to
find correct amplitude of ao , an and bn

ao can be calculated by

bn all coefficients are zero except bn

General formula for an

Fourier Analysis (in words)


The above expression has a real part of cosine of frequency f, and an imaginary part of sine of
frequency f. So what we are actually doing is, multiplying the original signal with a complex
expression which has sines and cosines of frequency f. Then we integrate this product (In other
words, we add all the points in this product). If the result of this integration (which is nothing but
some sort of infinite summation) is a large value, then we say that : the signal x(t), has a dominant
spectral component at frequency "f". This means that, a major portion of this signal is composed of
frequency f. If the integration result is a small value, than this means that the signal does not have
a major frequency component of f in it. If this integration result is zero, then the signal does not
contain the frequency "f" at all.
How this integration works: The signal is multiplied with the sinusoidal term of frequency "f". If the
signal has a high amplitude component of frequency "f", then that component and the sinusoidal
term will coincide, and the product of them will give a (relatively) large value. This shows that, the
signal "x", has a major frequency component of "f".
However, if the signal does not have a frequency component of "f", the product will yield zero,
which shows that, the signal does not have a frequency component of "f". If the frequency "f", is
not a major component of the signal "x(t)", then the product will give a (relatively) small value. This
shows that, the frequency component "f" in the signal "x", has a small amplitude, in other words, it
is not a major component of "x.

Fourier: Examples
The typical syntax for computing the FFT of a signal is FFT(x,N)
where x is the signal, x[n], you wish to transform, and N is the
number of points in the FFT. N must be at least as large as the
number of samples in x[n]. Matlab Example: To demonstrate
the effect of changing the value of N,
i.e 64, 128,256, 512

Matlab example

Fourier: Examples
N = 16
20
10
0

0.1

0.2

0.3

0.4

0.5
N = 32

0.6

0.7

0.8

0.9

0.1

0.2

0.3

0.4

0.5
N = 64

0.6

0.7

0.8

0.9

0.1

0.2

0.3

0.4

0.5
N = 128

0.6

0.7

0.8

0.9

0.1

0.2

0.3

0.4

0.5
N = 256

0.6

0.7

0.8

0.9

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

20
10
0
20
10
0
20
10
0
20
10
0

Fourier: Examples
In the previous slide

Upon examining the plot one can see that each of the transforms
adheres to the same shape, differing only in the number of FFT
samples used to approximate that shape.
But once the number of FFT points are very small the shape is
different (N=16 and N=32).

When the FFT is computed with an N larger than the number of


samples in x[n], it fills in the samples after x[n] with zeros. For
example if x[n] is 30 samples long, and the length FFT is 256. When
Matlab computes the FFT, it automatically fills the spaces from n=
30 to n = 255 with zeros. This is called zero padding.

Fourier: Examples
1. The FFT does not directly give you the spectrum of a signal. As we
have seen with the last two examples, the FFT can vary
dramatically depending on the number of points (N) of the FFT,
and the number of periods of the signal that are represented.
2. The FFT contains information between 0 and fs, however, we
know that the sampling frequency must be at least twice the
highest frequency component. Therefore, the signal's spectrum
should be entirly below fs/2 , the Nyquist frequency.
3. Also real signal should have a transform magnitude that is
symmetrical for positive and negative frequencies. So instead of
having a spectrum that goes from 0 to fs, it would be more
appropriate to show the spectrum from fs/2 to fs/2 .

Fourier: Examples
16
14
12
10
8
6
4
2
0
-0.5

-0.4

-0.3

-0.2

-0.1
0
0.1
frequency / f s

0.2

0.3

0.4

0.5

A bit More on FFT


It is clear that fft gives you a two sided spectrum. The basic
computations for analyzing signals include converting from a
two-sided power spectrum to a single-sided power spectrum.
Converting from a Two-Sided Power Spectrum to a SingleSided Power Spectrum
In a two-sided spectrum, half the energy is displayed at the
positive frequency, and half the energy is displayed at the
negative frequency. Therefore, to convert from a two-sided
spectrum to a single-sided spectrum, discard the second
half of the array and multiply every point except for DC by two.

DC component
remains same

Others are multiplied


by 2.

FFT: Spectrum Type and Scaling


FFT returns complex-valued amplitudes
Real part represents cosine components,
imaginary part represents sine components (90 phase
difference)
Can be converted to magnitude and phase
Squared magnitude represents signal power

Limitations of Fourier Analysis


1. Cannot not provide simultaneous time and frequency
localization.

2. Not useful for analyzing time-variant, non-stationary signals.


3. Not efficient for representing discontinuities or sharp corners
(i.e., requires a large number of Fourier components to represent
discontinuities).

Limitations of Fourier Analysis


f 4 (t ) cos(2 5 t )
cos(2 25 t )
cos(2 50 t )

Provides excellent
localization in the
frequency domain
but poor localization
in the time domain.

Limitations of Fourier Analysis


1. Cannot not provide simultaneous time and frequency
localization.

2. In its current form Not useful for analyzing time-variant, nonstationary signals.
3. Not appropriate for representing discontinuities or sharp corners
(i.e., requires a large number of Fourier components to represent
discontinuities).

Stationary vs non-stationary
signals
Stationary signals: timeinvariant spectra

Non-stationary signals:
time-varying spectra

Stationary vs non-stationary
signals
Stationary signal:

Three frequency
components,
present at all
times!

Stationary vs non-stationary
signals
Non-stationary signal:

The reason of the noise like


thing in between peaks show
that, those frequencies also
exist in the signal. But the
reason they have a small
amplitude, is because, they
are not major spectral
components of the given
signal, and the reason we see
those, is because of the
sudden change between the
frequencies.

Short Time Fourier Transform


What's the solution to tackle the problems of non-stationary signal?
We Need a local analysis scheme for a time-frequency representation.
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.

Short Time Fourier Transform


Steps :
1.
2.
3.
4.
5.
6.

Choose a window function of finite length


Place the window on top of the signal at t=0
Truncate the signal using this window
Compute the FT of the truncated signal, save results.
Incrementally slide the window to the right
Go to step 3, until window reaches the end of the signal

Short Time Fourier Transform


Each FT provides the spectral information of a separate timeslice of the signal, providing simultaneous time and frequency
information

Short Time Fourier Transform


Time
parameter

Frequency
parameter

Signal to
be analyzed

1D 2D

STFT fu (t , u ) f (t ) W (t t ) e j 2 ut dt
t

STFT of f(t):
computed for each
window centered at t=t

Windowing
function

centered at t=t

Choosing Window W(t)


What shape should it have?
Rectangular, Gaussian, Elliptic?

How wide should it be?


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.

STFT Window Size


STFT fu (t , u ) f (t ) W (t t ) e j 2 ut dt
t

W(t) infinitely long: W (t ) 1 STFT turns into FT,


providing excellent frequency localization, but no time
information.

W(t) infinitely short: W (t ) (t )

gives the time signal

back, with a phase factor, providing excellent time localization but


no frequency information.

STFT fu (t , u ) f (t ) (t t ) e j 2 ut dt f (t ) e jut
t

STFT Window Size (contd)

Wide window good frequency resolution, poor time


resolution.

Narrow window good time resolution, poor frequency


resolution.

In next lectures: We will study different windowing


types/shapes.

Example
Use this link for an Excellent work of Polikar on STFT and wavelets
http://users.rowan.edu/~polikar/WAVELETS/WTpart2.html

different size windows

(four frequencies, non-stationary)

Example

Example

Example: Effect of FFT window


Consider following scenarioTwo sin waves have frequencies
of 100 Hz and 110 Hz, and the sampling rate is 1 kHz. Apply a
FFT with window length 64 samples and 1024 samples.
Solution: We experiment with two time windows of length
N1=1024 with a theoretical frequency resolution of
f=1000/1024=0.98 Hz,
and N2=64 with a theoretical frequency resolution
f=1000/64=15.7 Hz.

Heisenberg (or Uncertainty)


Principle
1
t f
4
Time resolution: How well
two spikes in time can be
separated from each other in
the transform domain.

Frequency resolution: How


well two spectral components
can be separated from each
other in the transform domain

t and f cannot be made arbitrarily small !

Heisenberg (or Uncertainty)


Principle
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.

The Effect of Finite Length Data


(Windowing)
We already know that In practical situation we have either with
a short length signal, or with a long signal. Having a short
segment of N samples of a signal or taking a slice of N samples
from a signal is equivalent to multiplying the signal by a window
(We have considered Gaussian shape in example) of N samples.
Multiplying two signals in time is equivalent to the convolution
of their frequency spectra. Thus the spectrum of a short
segment of a signal is convolved with the spectrum of a
rectangular pulse, the result of this convolution is some
spreading of the signal energy.

Assignment
Take the FFT of complete single trial signal. Already provided
to you.
Remember that FFT has both Real and Imagery Parts. So take
real part only, you can also use abs function.
Length of FFT window should also be the part of your concept.
Vary the fft length and look into its influence on the signal.

Fs = 150; % Sampling frequency


t = 0:1/Fs:1; % Time vector of 1 second
f = 5; % Create a sine wave of f Hz.
x = sin(2* pi*t*f);
% x = cos(2* pi*t*f);
%x = square(2* pi*t*f);
nfft = 1024; % Length of FFT
% Take fft, padding with zeros so that length(X)
X = fft(x,nfft);
% second 0 0.2 0.4 0.6 0.8 1
%Power Spectrum of a Sine Wave FFT is symmetric, throw away half
X = X(1:nfft/2);
% Take the magnitude of fft of x
mx = abs(X);
% Frequency vector
f = (0:nfft/2-1)*Fs/nfft;
% Generate the plot, title and labels.
subplot (2,1,1)
plot(t,x);
title('Sine Wave Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2)
plot(f,mx);
title('Power Spectrum of a Sine Wave');
xlabel('Frequency (Hz)');
ylabel('Power');

Spectrum Types
Magnitude: Amplitude Spectrum
Squared magnitude: Power Spectrum
Squared magnitude per unit bandwidth: Power Spectral
Density
Squared magnitude block time length: Energy
Spectrum
Squared magnitude block length per unit bandwidth:
Energy Spectral Density

Spectrum Types: When to use


Periodic signals (discrete frequencies): Amplitude or Power
Spectrum
Broadband random signals: Power Spectral Density
Transient Signals: Energy Spectral Density

Averaging in Spectrum
Combine multiple time blocks together to form one spectral
estimate
Random data: higher average number, better estimate of
random characteristics

Flow diagram

You might also like