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

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

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

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

DCSP-13

Jianfeng Feng

[email protected]

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

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

Applications• Power spectrum estimate

• Compression

• Spectrogram

• Image

• Sampling theorem

• White noise FFT

Page 3: DCSP-13 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 4: DCSP-13 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 5: DCSP-13 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 6: DCSP-13 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 7: DCSP-13 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 8: DCSP-13 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 9: DCSP-13 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

N=10, = 0.5

Page 10: DCSP-13 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 11: DCSP-13 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 12: DCSP-13 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.

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

clear all

close all

sampling_rate=100; %Hz

omega=20; %signal frequecy Hz

N=50000; %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

xlabel('time (sec)');

ylabel('signal')

subplot(1,2,2)

plot(axis,abs(fft(x)).^2,'r'); % power of signal

xlabel('Frequency')

ylabel('Power')

sound(x_sound, sampling_rate); %true signal sound

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

• Singnal processing demo: transformation

• A few words on Matlab

periodogram (similar to fft)

pwelch (overlapped windows)

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

Algorithm

The periodogram for a sequence [x1, ... , xN] is given by the follo

wing formula:

where                is in units of radians/sample.

2

1

|)exp(|2

1)(

N

nn njx

NS

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

Algorithm

The periodogram for a sequence [x1, ... , xN] is given by the followi

ng formula:

where                is in units of radians/sample.

If you define the frequency variable in Hz, the periodogram is defined as:

where Fs is the sampling frequency.

2

1

|))/2(exp(|1

)(

N

nsn

s

nFfjxNF

fS

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

• Fs = 1000; t = 0:1/Fs:.296;• x = exp(i*2*pi*200*t)+randn(size(t)); • h = spectrum.periodogram; % Create a periodogram spectral estimator.

• psd(h,x,'Fs',Fs); % Calculates and plots the two-sided PSD.

0 100 200 300 400 500 600 700 800 900-60

-50

-40

-30

-20

-10

0

Frequency (Hz)

Pow

er/f

requ

ency

(dB

/Hz)

Periodogram Power Spectral Density Estimate

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

The periodogram is an estimate of the PSD of the signdefined by the sequence [x1, ... , xN].

If you weight your signal sequence by a window [w1, ... , wN], then the weighted or modified period

ogram is defined as:                                                                                                                                                                                                          

2

1

2

1

||1

|)exp(|21

)(

N

nn

N

nnn

wN

njwxN

S

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

• Fs = 1000; t = 0:1/Fs:.296;

• x = cos(2*pi*t*200)+randn(size(t));

• h = spectrum.welch; % Create a Welch spectral estimator.

• psd(h,x,'Fs',Fs); % Calculate and plot the PSD.

0 50 100 150 200 250 300 350 400 450 500-30

-28

-26

-24

-22

-20

-18

-16

Frequency (Hz)

Pow

er/

frequency (

dB

/Hz)

Welch Power Spectral Density Estimate

Page 20: DCSP-13 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 21: DCSP-13 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 22: DCSP-13 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Time

Frequenc

y

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

• t=0:0.001:20; % 2 secs @ 1kHz sample rate• y=chirp(t,100,1,200,'q'); % Start @ 100Hz, cross 200Hz at t=1sec• spectrogram(y,128,120,128,1E3); % Display the spectrogram• title('Quadratic Chirp: start at 100Hz and cross 200Hz at t=1sec');• sound(y)

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

Compression

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

The use in MP3 is designed to greatly reduce the amount of data required to represent the audio recording and still sound like a faithful reproduction of the original uncompressed audio for most listeners.

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

The use in MP3 is designed to greatly reduce the amount of data required to represent the audio recording and still sound like a faithful reproduction of the original uncompressed audio for most listeners.

An MP3 file could result in a file that is about 1/11th the size of the file created from the original audio source.

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

The compression works by reducing accuracy of certain parts of sound that are deemed beyond the auditory resolution ability of most people.

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

The compression works by reducing accuracy of certain parts of sound that are deemed beyond the auditory resolution ability of most people.

This method is commonly referred to as perceptual coding.

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

The compression works by reducing accuracy of certain parts of sound that are deemed beyond the auditory resolution ability of most people.

This method is commonly referred to as perceptual coding.

It internally provides a representation of sound within a short-term time/frequency analysis window, by using psychoacoustic models to discard or reduce precision of components less audible to human hearing, and recording the remaining information in an efficient manner.

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

This technique is often presented as relatively conceptually similar to the principles used by JPEG, an image compression format.

Page 32: DCSP-13 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 33: DCSP-13 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 34: DCSP-13 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.
Page 35: DCSP-13 Jianfeng Feng Jianfeng.feng@warwick.ac.uk feng/dsp.html.

Power spectrum for white noiseNoise is a stochastic process x(t), for time t

(discrete or continuous)

Most noisy noise should have no memory, which impliese that

E x(t)x(t+s) = 0 if s is not zero

E x(t)x(t) = 1

or in another words

E x(t)x(t+s) =(s)

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

Therefore the psd of the white noise is flat: it has constant power for all frequencies, as confirmed in the previous matlabe example

Different from all meaningful signals we encounter

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

Why white noise has a flat power spectrum?

Assume that x(n) is white noise which means

)()(2

)()(

12

)(

)arg(02

)(

2

ationautocorrelkN

knxnx

N

nx

numberseloflawN

nx

N

Nn

N

Nn

N

Nn

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

k

n k

n m

nn

n

kjk

kjknxnx

mnjmxnx

njnxnjnxx

njnxx

)exp()(

)exp()()(

))(exp()()(

)exp()()exp()(|)(|

)exp()()(

2