DCSP-12 Jianfeng Feng [email protected] feng/dsp.html.

45
DCSP-12 Jianfeng Feng [email protected] http://www.dcs.warwick.ac.uk/ ~feng/dsp.html

Transcript of DCSP-12 Jianfeng Feng [email protected] feng/dsp.html.

Page 1: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

DCSP-12

Jianfeng Feng

[email protected]

http://www.dcs.warwick.ac.uk/~feng/dsp.html

Page 2: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

For example, if a sequence is a sinusoid

x(n)=cos(0 n)

of infinite length, its DTFT yields two `delta' functions,

X()= (- 0)+ ( 0)

as in Fig. below where we assume all frequencies and 0 to be within the intervals [- , ).

Here x) is the Dirac delta function (not confused with the unit impulse defined before)

Page 3: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 4: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

This shows that the DTFT gives perfect frequency localization as an exact concentration of energy

at - 0 and 0 provided

Page 5: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

This shows that the DTFT gives perfect frequency localization as an exact concentration of energy at - 0 and 0 provided

(a) the sequence lasts from -infinity to infinity and we have an infinite amount of memory to actually collect all the data points, and

Page 6: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

This shows that the DTFT gives perfect frequency localization as an exact concentration of energy at - 0 and 0 provided

(a) the sequence lasts from -infinity to infinity and we have an infinite amount of memory to actually collect all the data points, and

(b) we compute X( ) for all possible frequencies in the interval [- , , again requiring an infinite amount of memory and an infinite computational time.

Page 7: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

In practice, we do not have infinite memory, we do not have infinite time, and also any signal we want to analyze does not have infinite duration.

Page 8: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

In practice, we do not have infinite memory, we do not have infinite time, and also any signal we want to analyze does not have infinite duration.

In addition, the spectrum of the signal changes with time, just as music is composed of different notes that change with time.

Page 9: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

In practice, we do not have infinite memory, we do not have infinite time, and also any signal we want to analyze does not have infinite duration.

In addition, the spectrum of the signal changes with time, just as music is composed of different notes that change with time.

Consequently, the DTFT generally is not computable unless we have an analytical expression for the signal we analyze, in which case we can compute it symbolically.

Page 10: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

But most of the time this is not the case, especially when we want to determine the frequency spectrum of a signal measured from an experiment.

Page 11: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

But most of the time this is not the case, especially when we want to determine the frequency spectrum of a signal measured from an experiment.

In this situation, we do not have an analytical expression for the signal, and we need to develop an algorithm that can be computed numerically in a finite number of steps, such as the discrete Fourier transform (DFT).

Page 12: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

DFT

Page 13: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 14: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

• clear all• close all• N=10; %sampling rate N Hz• T=20; % time• d1=1; % first period • d2=0 % second period• for i=1:T*N• t(i)=i/N;• x(i)=cos(d1*2*pi*i/N)+cos(d2*2*pi*i/N);• end• • figure(1)• plot(t,x)• figure(2)• plot(t*N/(T),abs(fft(x)))• xlim([0 N/2]);• xlabel('Hz')

Page 15: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

• clear all

• close all

• sampling_rate=100;%Hz

• omega=20; %signal frequecy Hz

• N=10000; %total number of samples

• for i=1:N

• x_sound(i)=cos(2*pi*omega*i/sampling_rate); %signal

• x(i)=cos(2*pi*omega*i/sampling_rate)+2*randn(1,1); %signal+noise

• axis(i)=sampling_rate*i/N; % for psd

• time(i)=i/sampling_rate; % for time trace

• end

• subplot(1,2,1)

• plot(time,x); %signal + noise, time trace

• subplot(1,2,2)

• plot(axis,abs(fft(x)),'r'); % magnitude of signal

• sound(x_sound); %true signal sound

Page 16: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 17: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

The relationship between DFT and DTFT

= 2 k /N

Page 18: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

In spite of their similarities, the DFT and DTFT are two quite different operations.

Whereas the DFT is a numerical operation, which computers a finite number of coefficients

X(0), … ,X(N-1) from a finite set of data x(0), … ,x(N-1),

Page 19: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

the DTFT is not computable numerically because it yields a continuous function, X(), based on an infinite sequence x(n).

In this section we address the problem of estimating

X()=DTFT{x(n)}

based on the DFT of a sample of finite length N.

Page 20: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Now the question is, will XN converges to X as N tends to infinity for each value of the frequency

variable ?.

If the answer is positive, the approximation makes sense and we can say that we can estimate the frequency spectrum of the whole signal based on a set of samples.

The more data(i.e. the larger N is), the better the approximation.

Page 21: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

The answer

Three cases

• absolutely summable

• finite energy

• general case

Page 22: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Absolutely summable signals.

These signals are such that

|x(n)| < infinity

For these signals the DTFT always exists, is finite, and converges for every as

lim ( ) ( )N NX X

Page 23: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

These are the best-behaved sequences, in terms of convergence.

This means that for every , we can approximated X ( ) infinitely closely by the finite sequence XN ( ), with N sufficiently large.

Typical examples in this class are signals decaying as 1/n2 for which

|x(n)| < C/ n2,

for n sufficiently large.

In particular, signals decaying exponentially fast.

Page 24: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 25: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 26: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 27: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 28: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

• Gibbs phenomena: cause a lot troubles in practice applications

Page 29: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Third case:

Example: cos (omega_0 n)

Page 30: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

DFT for spectral estimation

One of the uses of the DFT is to estimate the frequency spectrum of a signal.

The Fourier transform of a function produces a spectrum from which the original function can be reconstructed by an inverse transform.

So it is reversible. (signal processing: transforms, demo)

Page 31: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

In order to do that, it preserves not only the magnitude of each frequency component, but also its phase.

This information can be represented as a 2-dimensional vector or a complex number, or as magnitude and phase (polar coordinates).

In graphical representations, often only the magnitude (or squared magnitude) component is shown.

This is also referred to as a power spectrum .

Page 32: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

In particular, given a continuous time signal x(t), the goal is to determine its frequency components by taking a finite set of samples as a vector,

(x(0), x(1),…, x(N-1)),

and computing its DFT as in the previous section.

Page 33: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

The fact that we window the signal x(n) (i.e. we take a finite set of data) will have an effect on the frequency spectrum we

compute, and we have to be aware of that when we interpret the results of the DFT.

This can be seen by defining a window sequence

Page 34: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

and the DTFT of the windowed signal

Now notice that we can relate the right-hand side of the preceding expression to the DFT of the finite sequence

x(0), … ,x(N-1)

Page 35: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

To see the effect of the windowing operation on the frequency spectrum, let us examine

the case when the signal x(n) is a complex exponential, such as

x(n) = exp( j 0 n)

Page 36: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

N=10, = 0.5

Page 37: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Two effects of DFT

1.Lose of resolution

1.Leakage of energy from mainlobe to sidelobes

Page 38: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 39: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

As we have seen, the DFT is the basis of a number of applications, and is one of the most important tools in digital signal processing.

The problem with this algorithm is that a brute-force implementation would hardly be feasible in real time, even for a data set of modest length.

Page 40: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Fortunately, the DFT can be computed in a very efficient way, exploiting the very structure of the algorithm we have presented by using the fast Fourier transform (FFT), which is an efficient way of computing he DFT.

It is know that for a data set of length N, the complexity of the FFT grows as N log N, the complexity of the DFT computed by brute force grow as N2.

FFT is widely used in many applications.

Page 41: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Spectrogram

• A spectrogram is an image that shows how the power spectrum of a signal varies with time.

Page 42: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

0 500 1000 1500 2000 2500-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 43: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Time

Frequenc

y

Page 44: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Sampling and reconstruction

The question we consider here is under what conditions we can completely reconstruct the original signal

x(t)

from its discretely sampled signal

x(n).

Page 45: DCSP-12 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.