Basic Signal Processing

agerasiaetherealΤεχνίτη Νοημοσύνη και Ρομποτική

24 Νοε 2013 (πριν από 3 χρόνια και 8 μήνες)

68 εμφανίσεις


-

1

-


Basic Signal Processing


Signal Types

Static

signals do not vary with time. In cases in which the physical quantity to be measured is
static, measurement noise can make the measured data vary somewhat with time, so the signal
may be dynamic even if the measured quantity is not.

Dynamic

signals (or p
ortions of signals) can be classified as:


Transient


Steady
-
state periodic


Continuous nonperiodic

A particular measured signal may have components of each type, i.e., there may be an initial
transient followed by periodic motion.

Transient Signals


Simpl
e transient signals: step function, ramp, impulse


Short
-
duration oscillatory signals: tone burst, chirp

More complicated signals: includes response to initial conditions or transient inputs

Transient responses often are characterized by exponential growth

or decay

Steady
-
state periodic signals


Single
-
frequency sinusoids


Square wave, sawtooth, etc. (multiple frequency components in particular ratios)


More complicated superposition of multiple sinusoids of various frequencies


Any periodic signal can be
represented by a sum of sinusoids (Fourier Series)

Continuous nonperiodic signals


Noise or other random signals


Quasiperiodic signals (multiple frequencies that are incommensurable: ratio is irrational)


Chaotic signals (apparently random but actually de
terministic)


The rate at which a transient signal evolves (slope of a ramp, exponential decay rate, etc.) can be
observed in
time domain
. Certain other characteristics of signals (either transient or continuous)
can be calculated from time domain data. S
ignals that involve
oscillations (periodic or not)
are
often
better analyzed in
frequency domain
.



Basic Time Domain Processing


The
mean

of a signal gives the component of the signal that remains c
onstant. It is sometimes
called the
temporal mean

to emp
hasize that it is the average
over time

of a single quantity (as
opposed to the average value of multiple quantities). It
also called the
offset

or
DC component
,
(
from electronics where constant Direct Current is distinguished from oscillating Alternating
Current).

The
AC component

is the signal with the DC component removed (i.e.,


The
RMS value

(root
-
mean
-
squared) is a measure of how far the signal deviates from zero. By
squaring the signal before taking the mean, positive and negative portions do not a
verage out.


-

2

-


Continuous (Analog) signal


Discrete (Digitial) signal

mean
x

x
(
t
)
dt
t
1
t
2

t
2

t
1

mean
x

1
N
x
i
i

0
N

1


x
R
M
S

x
(
t
)


2
dt
t
1
t
2

t
2

t
1


x
R
M
S

1
N
x
2
i
i

0
N

1



If

the mean is zero (or has been subtracted from the signal) then th
e RMS value is a measure of
the amplitude of the oscillations.



Note also that, for a zero
-
mean signal (or a signal from which the mean has been subtracted), the
formula for RMS is the same as for standard deviation, although the latter term is typically
used
for describing the statistics of a population of values rather than a signal.



Consider a

simple sinusoid with an offset,


x
(
t
)

A
0

A
1
c
os
(

t
)



By inspection, the DC component is
A
0

and the AC componet is


A
1
c
os
(

t
)
.


Strictly
speaking, the formula for mean only gives the DC component if the duration of the
signal is an exact integer number of periods of the sinusoid (but it converges to the DC
component as the duration gets large compared to the sinusoid’s period):





x

(
A
0

A
1
c
os

t
)
dt
t
1
t
2
ò
t
2

t
1

A
0

A
1
s
i
n

t
2

s
i
n

t
1

(
t
2

t
1
)
æ
è
ç
ö
ø
÷
®
A
0
w
he
n

(
t
2

t
1
)
1


The RMS value of the entire signal is





x
R
M
S

A
0

A
1
c
os

t


2
dt
t
1
t
2
ò
t
2

t
1

A
0
2

A
0
A
1
c
os

t

A
1
2
c
os
2

t
dt
t
1
t
2
ò
t
2

t
1

A
0
2

A
0
A
1
c
os

t

1
2
A
1
2
(
1

c
os
2

t
)
dt
t
1
t
2
ò
t
2

t
1
®
A
0
2

1
2
A
1
2
w
he
n

(
t
2

t
1
)
1


The RMS value of the AC component is



-

3

-




(
x
A
C
)
R
M
S

A
1
2
c
os
2

t
dt
t
1
t
2
ò
t
2

t
1

1
2
A
1
2
(
1

c
os
2

t
)
dt
t
1
t
2
ò
t
2

t
1
®
1
2
A
1
2

A
1
2
w
he
n

(
t
2

t
1
)
1


Note that the

(RMS of the entire signal)
2

= (mean

of signal
)
2

+ (RMS of AC component)
2



Note that
this means that
subtracting the mean from the RMS value
does
not

give the same result
as subtracting the mean from the signal and calculating the RMS value of the remaining

AC

part.


For example, if


x
(
t
)

10

4
c
os
(

t
)
,



The mean is 10,



The RMS value

is



x
R
M
S

10
2

1
2
4
2

108

10.39
,



The RMS of the AC component 4cos
(
ω
t
) is

1
2
4
2

8

2.82



Conversion to Frequency Domain


For measured signals that involve oscillatory behavior, it is typical to analyse data in the
frequency domain rather than
the time domain.


A
Fourier series

can be used to convert a continuous, analytic function
of time that is periodic
into a (possibly

infinite
)

series (summation) of sinusoids
, which periods that are integer fractions
of the overal period
T
of the signal (i.
e., frequencies



n

nt
/
T

for
n

= 1, 2, 3, …).



Some functions may be represented by a finite series, others may require an infinite series
for perfect equivalence but can be app
roximated by a truncated series.



The

coefficients in front of the sinusoids comprise a
discrete

set of information in
frequency domain.



There is a “sine/cosine” formulation for the Fourier series, and a mathematically
equivalent “complex exponential” formulation, since
e

i

t

c
os
(

t
)

i
s
i
n(

t
)
.
Recall
that a
ny spe
cific sinusoid has one frequency and two additional numbers that can be
specified as:

o

magnitude and phase, as in


x
(
t
)

C
c
os
(

t


)

o

amplitude of the sine and cosine portions, as in


x
(
t
)

A
c
os

t

B
s
i
n

t

o

real and imaginary parts of the two complex
-
conjugate amplitudes of counter
-
rotating imagi
nary exponentials, as in


x
(
t
)

c
e
i

t

c
*
e

i

t

o

real and imaginary parts of a single complex amplitude, as in


x
(
t
)

Re
ˆ
Ce
i

t



While the sinusoidal formulations are more intuitive, the exponential formulations are
more useful mathematically
.




-

4

-

A
Fourier transform

can be used on
any

analytic function (needs not be periodic). It converts an
continous, analytic function of time into an continuous, analytic function of frequency.



A
n extension of the Fourier series to deal with functions whose period is infinite (never
repeats).



As

T
®
¥
, the spacing between frequencies

shrinks to zero, and the summation
over
contributions at various specific frequencies
becomes an integral

over
all

frequencies
.


The
Discrete Fourier Transform

converts a discrete series of sampled
values at various times into
a discrete series of coefficients at various frequencies.



Experimental work always deals with signals of finite duration, so there’s never a need to
assume infinite period: the
measurement period

sets an upper bound on the appa
rent
period of the signal.



Signal processing carried out digitally, such as on a computer, deals with
discrete

signals
in time (rather than continuous).



to convert

a continuous
function of time
x
(
t
)

a discrete series
x
0
,

x
1
,
x
2
,
x
3
,
x
4
,
etc.

into

a
discrete series
of frequency
coefficients

Fourier Series

Discrete Fourier
Transform

a continuous
function of
frequency,
X
(
f
)

Fourier
Transform


The DFT is the main tool for obtaining the frequen
cy content of measured signals.
The most
commonly used
algorithm

for computing a DFT

quickly is called the Fast Fourier Transform
(FFT). The FFT is so common that the terms DFT and FFT are
often
used interchangeably.

The DFT can be applied to periodic
and

nonperiodic signals: the mathematics assumes that the
entire measured signal repeats itself… thus the
measurement period

determines which
frequencies correspond to the various coefficients in the resulting set (as opposed to any period
of components of the signal itself).



If

the signal is a simple sinusoid wi
th an
integer

number of periods occurring within the
measurement period (of a superposition of multiple sinusoids
all of which

have an integer
number of periods within the measurement period) then the DFT coefficients are exact
representations of that (or
those) sinusoid amplitude
(s)
.



However, for
any other signal

(periodic but noninteger number of periods measured,
nonperiod continuous signals, or transient signals) the DFT can
still be used

but there is
some ambiguity in the meaning of the resulting coeff
icients.


-

5

-

t

x

T
meas


The figure shows three measurements of the same periodic signal (a sine wave at 10 Hz).

In the top and bottom, the measurement period is 3 and 4 times the signal period, respectively,
and the frequency spectrum resulting from a DFT shows peak a
mplitude 1 at a frequency 10 Hz
(frequency resolution is 3.33 Hz and 2.5 Hz respectively, the reciprocals of 0.3 and 0.4 seconds).

In the middle, the measurement period is 3.5 times the signal period (a non
-
integer). The
frequency resolution is 2.857 Hz
(reciprocal of 0.35 seconds). The coefficients for 8.571 and
11.429 Hz (those closest to 10 Hz) are both high, but neither is the correct sine amplitude of 1.
Also, other,
non
-
neighboring

frequencies have non
-
zero coefficients, due to
spectral leakage
.

Spectral leakage

comes from the broad frequency character of the discontinuities created at the
edges of the measurement period by the mathematical assumption that the measurement repeats
periodically:






It can be minimized by applying an appropriate
window

to the measured data (see below).


-

6

-


This figure shows a similar effect, except that the signal is
transient
, not periodic.

The signal is an exponentially decaying sinusoid with frequency 20 Hz. The DF
T relies on
mathematical assumption that the signal repeats (every 0.3, 0.35, or 0.4 seconds, depending on
measurement period).

Since the signal itself is not actually periodic, no measurement period can be an integer multiple
of the signal period. In a
ll cases, a variety of sinusoids
are

needed to construct the transient
signal, with the largest at and near 20 Hz (the frequency of the oscillatory component of the
signal).

Also, the overall height of the DFT result is scaled differently depending on the

length of the
measurement period.

The DFT can be used to determine the dominant frequency component(s) in a non
-
periodic
signal, and compare
relative

amplitude levels, but care must be taken in interpreting amplitude
levels in any absolute sense.

Loosely,

the amplitude of the 20 Hz frequency component in the DFT is the
average

amplitude
of the 20 Hz signal in time domain (the actual amplitude changes as the sinusoid decays).
Naturally, using a longer measurement period reduces the average level since ther
e are a greater
number of very low amplitude samples (from the later time steps) included in the average.


-

7

-

DFT Formulas


Forward DFT

Inverse DFT


X
k

(
1
)
x
n
e

i
2

k
n
N
n

0
N

1


 
x
n

(
1
N
)
X
k
e
i
2

kn
N
k

0
N

1






The time domain information is
x
0
,
x
1
,
x
2
,

...
x
N
-
1
, where each
x
n

is a
typically a
real

number.


The frequency domain data is
X
0
,
X
1
,
X
2
,... where each
X
k

represents the portion of the signal that
occurs at a certain frequency
f
k
.
Each
X
k

(except
X
0
) is typically a
complex

number, containing
two

pieces of information: the real part and the imaginary
part (or, alternatively, the magnitude
and phase).


Thus,
N

unique
x
n
’s will only lead to
N
/2 unique
X
k
’s.


Many FFT algorithms are
two
-
sided

algorithms, returning
N

complex numbers rather than
N
/2.



Often, we number the second half with negative indices

as an indication that they are the
complex conjugates of numbers from the first half.


Since the magnitude of a number is the same

as the magnitude of it
s complex conjugate, a plot of
the
magnitude

of a two
-
sided FFT is symmetric:


Likewise, since the phase of a number and the phase of its complex conjugate are the same
numbers but with opposite sign, a plot of the
phase

of a two
-
sided FFT has a second half that’s
the negative of the first half.

A
one
-
sided
FFT plot includes only
X
0

to
X
N
/2
, and all the
X
k
’s except
X
0

are
doubled

so that the
area under the curve remains the same as the two
-
sided case.

The product of these factors must be (1/N). Some DFT formulations
give them as (

and
) or (1/N and 1) rather than (1 and 1/N).

Arguments are identical except sign

or


-

8

-


Scaling of Frequency Domain Data

DFT data are usually
scaled

to be more physically meaningful:




Amplitude Spectrum (Peak)


The actua
l amplitude (from zero to peak) of the sinusoidal component at any given frequency
is found by dividing the magnitude of the DFT by
N

(for a two
-
sided FFT, assuming the
formulation given above


some DFT formulation include the 1/N in the forward transform
)




Amplitude Spectrum (RMS)

Multiplying the peak amplitude spectrum by
 
1
2

gives the root
-
mean
-
square (RMS)
amplitude spectrum.




Power Spectrum

The power in a sinusoidal signal is proportional to amplitude squared, so the two
-
sided
power spectrum is found from the two
-
sided DFT by

or
 
(
X
k
)(
X
k
*
)
N
2
. Note that the phase
information is
lost

when calculating power spectra.




Power Spectral
Density (PSD)

The PSD is the power spectrum divided by

f
, which tells how much power there is “per
Hertz” (
rather than per frequency bin of width

f
). If you’re measuring a broadband signal
such as noise, changing the number of samples or the sampling frequency will change the
power spectrum since it changes the bin width

f

, but will
not

change the PSD, which is a
measure that is independent of bi
n width.




Noise spectral density

To allow noise to be compared to the amplitude of an actual signal, it is common to take the
square root of the PSD, converting, for example,
 
V
2
Hz

into
 
V
Hz
.

In theory, a pure sinusoid
has
infinite

spectral density at the frequency of the sinusoid and zero
everywhere else (it is a dirac delta function in the frequency domain). However,

(1)

this would be evident only if one had infinitesmal frequency resolution (infinite
measurement period),

(2)

in reality, there is always some small variation in the frequency of any nominally pure
-
tone signal, resulting in a peak of finite width and height, and

(3)

spectral density if usually only used for discussion of noise and other broadband signals,
not for pur
e tones.


The power spectrum and power spectral density can be related to the statistics of random
processes (i.e., noise), which means that they can be determined in an alternate manner by
measuring the
autocorrelation

of a time signal.



-

9

-

Autocorrelation,

Cross
-
correlation, and Coherence

The autocorrelation of a function is a measure of the degree to which the value at one instant is
correlated with the value at a later instant. It is a function of time lag


for continuous signals
or, for discrete signa
ls, the number
j

of samples delayed:



11
(

)

l
i
m
T
®
¥
1
T
x
(
t
)
x
(
t


)
dt
0
T
ò

for a continuous function
x
(
t
)



11
(
j
)

1
N
x
n
x
n

j
n

0
N

1


for a discrete series
x
n

with
n

= 0 to
N
-
1.

that is, for discrete signals, it is the mean of the products of two samples separated by
j

time
steps.

(Here, we’re assuming
x

is always real
-
valued).


It is typical
ly

used for random processes, for which it is usually high for small


or
j

and then
mu
ch smaller for larger delays (the value of

the function
at one instant may tell you something
about
the
value at nearby instants but not much about the values at more distant instants).


Periodic

signals (which are non
-
random) correlate to themselves entir
ely when


or
j

represents
a delay of exactly an integer number of periods.

Thus, the autocorrelation function will also be
periodic.


Note that the autocorrelation at
j
=0 is simply the mean of the squared signal, that is,

11
(
0
)

x
R
M
S
, and
this is the maximum possible autocorrelation.


According to the
Wiener

Khinchin theorem
, the Fourier transform of the autocorrelation
function

11
(

)

(or the DFT of

11
(
j
)

when dealing with discrete signals) is equal to the power
spectral density of the signal. That is, the following two processing sequences are equivalent:


T
i
m
e
s
e
r
i
e
s

x
n
D
F
T
¾
®
¾
¾
F
our
i
e
r
c
oe
f
f
i
c
i
e
nt
s

X
k

x
n
e

i
2

k
n
N
n
å
c
al
c
ul
at
e

P
SD
¾
®
¾
¾
¾
¾
P
SD
(
k
)

X
k
2

f

N
2

and

T
i
m
e
s
e
r
i
e
s

x
n
c
al
c
ul
at
e

aut
oc
or
e
l
l
at
i
on
¾
®
¾
¾
¾
¾
¾
¾

11
(
j
)
D
F
T
¾
®
¾
¾
P
SD
(
k
)


11
(
j
)
e

i
2

k
j
N
j
å



-

10

-

The autocorrelation is a special case o
f the more general
cross
-
correlation
, which measures how
well two
different

signals are correlated at times separated by delay


(or index
j
):




12
(

)

l
i
m
T
®
¥
1
T
x
1
(
t
)
x
2
(
t


)
dt
0
T
ò

for two continuous functions
x
1
(
t
) and
x
2
(
t
)



12
(
j
)

1
N
x
1
n
x
2
n

j
n

0
N

1


for two discrete series
x
1

and
x
2




If the two signals have the same behavior in time (they are differently scaled versions of
the same signal), the cross
-
correlation is maximized at a zero delay (



0

or
j

= 0
).



If the
second signal
is a

time
-
shifted version of the first (or a time
-
shifted and rescaled
version), the cross
-
correlation is maximum when
τ

is equal to the amount of shift.



As with the autocorrelation, if both signals are periodic, the cross
-
correlation will al
so be
periodic (if they are correlated at one amount of delay, they will also be correlated by
other amounts of delay that differ from the initial amount by the mutual period).


The cross
-
correlation of two functions is equivalent to the
convolution

of one

function with a
time
-
reversed
(and shifted)
version of the other.




The Fourier transform (or discrete Fourier transform) of the cross
-
correlation is the
cross
-
spectral
density

(CSD).


The
coherence

of two signals can be calculated from their cross
-
spectral density and individual
power spectral density



Coherence
C
12

CSD
2
P
SD
1

P
SD
2

for two signals (1 and 2).


The coherence represents the extent to which one signal
may be predicted from the
other.


If one signal is the input to a linear system and the other is the output, the coherence is the
fraction of the output power that is caused by the input, as a function of frequency (the remainder
of the output is due to noise or other inputs).



Ma
tched Filtering


In idealized measurements made on an idealized linear system, the system output would be
completely coherent with the system input. In a
ny

situation where one signal is expected to
contain a portion coherent with another signal and a incoherent (noise) portion,
the cross
-
correlation can be used to
implement

a filter that removes as much noise as possible. A
matched
filter

is the best possibl
e linear filter for a signal corrupted by random additive noise (i.e., it
maximizes the signal
-
to
-
noise
-
ratio).




-

11

-



A matched filter can be implemented by creating a digital filter whose impulse response
in a time
-
reversed
and time
-
shifted
version of the
input signal

(see Digital Filtering,
below).


Matlab code:

b=inputvector(end:
-
1:1);




filteredoutput=filter(b,1,outputvector);



Alternatively, the cross
-
correlation of the input and output signals provides the same
result.


Matlab
code:



[filteredout
,tau]=xcorr
(inputvector,outputvector)