final project part ii matlab session es 156 signals and systems 2007 seas prepared by frank tompkins

34
Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Upload: chris-fenney

Post on 16-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Final Project Part IIMATLAB Session

ES 156 Signals and Systems 2007

SEAS

Prepared by Frank Tompkins

Page 2: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Outline

• freqz() command• Step by step through the communication

system– Explanation of new concepts and new

MATLAB functions– High-level view of flow through the system– Next week we talk in more detail about

implementation

• Eye diagrams

Page 3: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Start Early!

• Project is complex

• Not something you can do in one day

• Less hand-holding than MATLAB exercises in homework– More like real-life projects

• Extra office hours possible– Email us if you have questions/problems

Page 4: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

freqz()

• Same inputs as filter()• Plots frequency response

• Outputs frequency response

channelFilterTaps = [1 0 -1/2 3/8 zeros(1,28)];

freqz(channelFilterTaps, 1);

channelFilterTaps = [1 0 -1/2 3/8 zeros(1,28)];

H = freqz(channelFilterTaps, 1, 256); % evaluate H(ej) at 256 points

Page 5: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Overall Idea

• Want to transmit a digital image from point A to point B using radio waves, etc.

• We won’t actually build antennas/wires– Simulate the whole thing in MATLAB

• Have to convert digital image to a wave that can travel through the air, a wire, etc. at point A

• Then convert wave back to a digital image at point B

• We’ll transmit DCTs instead of actual image pixels, as is often done in real life applications

Page 6: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Image Pre-Processing– Break image into 8 pixel by 8 pixel blocks and

take DCT of each block– Quantize DCT coefficients into 256 levels by

representing them as 8-bit unsigned numbers

Page 7: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

blkproc()

• MATLAB command for applying a function in blocks to a matrix

• Example: apply DCT in 8 by 8 blocks

I = imread(‘myimage.tif');

fun = @dct2;

J = blkproc(I, [8 8], fun);

Page 8: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Quantization

• Approximate a continuous range of values by a set of discrete values

Page 9: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Quantization

• In MATLAB uint8()

• For images, we have to scale to [0,1] before quantizing with im2uint8()

x = 5.7; % x is double precision (32-bit floating point)

xq = uint8(x); % xq is an 8-bit unsigned integer

xscaled = (1.4 - x) / (1.4 - 6.3); % x is an image matrix

xq = im2uint8(xscaled);

Page 10: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Conversion to a bit stream– Using reshape()and permute()

• Arrange 8 x 8 DCT blocks into groups of N blocks each

• Reshape each block into a vector (length 8*8*N) to be transmitted later

• Convert each pixel in vector to a binary number

Page 11: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Conversion

Page 12: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

reshape()

>> x = [1 2 3; 4 5 6; 7 8 9]'

x =

1 4 7

2 5 8

3 6 9

>> reshape(x,1,9)

ans =

1 2 3 4 5 6 7 8 9

• Takes elements columnwise

Page 13: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

permute()>> x = rand(1,2,2)

x(:,:,1) =

0.4565 0.0185

x(:,:,2) =

0.8214 0.4447

>> permute(x,[2 1 3])

ans(:,:,1) =

0.4565

0.0185

ans(:,:,2) =

0.8214

0.4447

Page 14: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

de2bi()>> x = [4; 212; 19]

x =

4

212

19

>> de2bi(x)

ans =

0 0 1 0 0 0 0 0

0 0 1 0 1 0 1 1

1 1 0 0 1 0 0 0

Page 15: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Modulation– Modulate each bit by a sine wave and put into the channel– Implementation details are up to you

• What is written in the PDF file is a suggestion– We will however take off points if you use more than one for

loop in your code• That one should loop over the N-sized block groups to send

each one through the channel in turn

Page 16: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Pulse Amplitude Modulation

• PAM for short

• We will use a specific simple type:half-sine pulse

• To send a bit– For a 1 send sin(t)– For a 0 send –sin(t)

0 5 10 15 20 25 30-1

-0.5

0

0.5

1

t

0 5 10 15 20 25 30-1

-0.5

0

0.5

1

t

Page 17: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Modulated [1 0 0 1]

0 20 40 60 80 100 120 140-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 18: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Channel– Atmosphere, telephone wire, coaxial cable– We model it as an LTI system

• Impulse response h(t)

– In using MATLAB, must approximate by discrete time system h[n]

Page 19: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Noise– We will use zero mean AWGN

• Additive White Gaussian Noise

– Add an independent Gaussian random variable to each sample passed through the channel

Page 20: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

AWGN

noisePower = 2; % variance of Gaussian random variable

result = signalFromChannel + sqrt(noisePower) * randn(rows, cols);

>> randn(2,3)

ans =

-0.4326 0.1253 -1.1465

-1.6656 0.2877 1.1909

y[n] = h[n] * x[n] + noise[n]

Page 21: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

[1 0 0 1] After Channel and Noise

0 20 40 60 80 100 120 140-3

-2

-1

0

1

2

3

Page 22: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Receiver Equalization– Attempt to undo distortion of modulated signal

(sine wave) due to channel and noise– We will try two equalizing filters

• Zero Forcing (ZF)• Minimum Mean Square Error (MMSE)

Page 23: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Zero Forcing (ZF) Filter

• Just the inverse of the channel response• If H(ej) is the response of the channel, then the

ZF filter has response 1 / H(ej)• Clearly if there were no noise, ZF filter would

perfectly recover modulated signal• But since ZF doesn’t take noise into account at

all, it will perform very badly if noise is strong

Page 24: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

MMSE Filter

• Takes noise into account

• Derived by minimizing the average error– We’ll just take it on faith

• If H(ej) is the response of the channel, then the MMSE filter has response

Page 25: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Detection– Examine equalized signal to determine

whether a 1 or a 0 was sent over channel– Optimal detector is a thresholder

Page 26: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Threshold Detector

• Integrate (sum) the transmitted and equalized half-sine pulse

• If integral (sum) < 0, decide a 0 was sent

• Else decide a 1 was sent

Page 27: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Conversion to an Image– After receiving all block groups, use reshape()and permute() to rebuild the block DCT image

Page 28: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Conversion to an Image

Page 29: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

• Image Post-Processing– Use blkproc() to compute inverse block

DCT– That’s it!

Page 30: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Things To Play With

• Noise Power– Increasing noise power will cause more distortion in

received image

• ZF/MMSE Equalizers– Since MMSE handles noise, it should perform better

than ZF

• Eye Diagrams– Coming up next

• Different Channels– Optional

Page 31: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Eye Diagrams

• Used to visualize how waveforms used to send (modulate) multiple bits of data can lead to detection errors

• The more “open” the eye, the lower the probability of error

• Consider modulated half-sine pulses for four subsequent transmitted bits

Page 32: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

Modulated [1 0 0 1]

0 20 40 60 80 100 120 140-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 33: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

[1 0 0 1] After Channel and Noise

0 20 40 60 80 100 120 140-3

-2

-1

0

1

2

3

Page 34: Final Project Part II MATLAB Session ES 156 Signals and Systems 2007 SEAS Prepared by Frank Tompkins

[1 0 0 1] Eye Diagrams

Before Channel After Channel