1 announcements l take textbook to lab. »be sure to read chapter 13 before lab –matlab tutorial...

30
Announcements Take textbook to lab. » Be sure to read Chapter 13 before lab – MATLAB tutorial – Can skip Section 13.4 Bring your transmitter and receiver to lab. » 8 AA batteries » 2 9V batteries » Earphones First Professional Memo Due TODAY!

Upload: aldous-mitchell

Post on 11-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

1

Announcements Take textbook to lab.

» Be sure to read Chapter 13 before lab– MATLAB tutorial

– Can skip Section 13.4

Bring your transmitter and receiver to lab.» 8 AA batteries» 2 9V batteries» Earphones

First Professional Memo Due TODAY!

Page 2: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

2

Today’s Topics

Digital signals

Introduction to MATLAB

Generating audio signals with MATLAB

Page 3: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

3

Digital Music - Recording

Sampler

-0.0364-0.1884-0.6928-1.7398-2.7642-2.2378 0.1711 1.8333 …

10110101010

byteCD

Analog signal Digital signal

Page 4: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

4

Digital Music - Playback

D/AConverter

-0.0364-0.1884-0.6928-1.7398-2.7642-2.2378 0.1711 1.8333 …

CD

Analog signalDigital signal

AudioAmplifier

Page 5: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

5

Computer-Generated Signals

MATLAB Sound Card

D/AConverter

AudioAmplifier

0.0000 0.5878 0.9511 0.9511 0.5878 0.0000-0.5878 …

Page 6: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

6

Audio Signal

Sound generated by a PC originates as a sequence of numbers (a discrete signal).

0 10 20 30 40 50 60-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

0 10 20 30 40 50 60-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

What we want What we can generate

Page 7: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

7

MATLAB

MATLAB® allows us to generate sequences easily.» The basic data structure in MATLAB is a

vector.» A vector is a convenient way to store a

sequence. We can also play sounds from within

MATLAB.

Page 8: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

8

MATLAB Basics

Assign a value to a variable>> a=3

a =

3

>> a=3;>> a

a =

3>>

Semicolon suppresses echo

Typing a variable name displays the value

Be careful!!

Page 9: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

9

MATLAB Basics Vectors

>> v=[1,3]v = 1 3

>> v=[1;3]v = 1 3

>> v'ans = 1 3

>> v=1:0.5:3v = 1.0000 1.5000 2.0000 2.5000 3.0000

Comma delimits columns

Semicolon delimits rows

Apostrophe means transpose(turn rows into columns andvice versa)

start value : increment : end value

Page 10: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

10

We have been considering sine waves:

is the frequency of the sine wave. Sample the waveform every T seconds.

» Let » We get a sequence » Let n=0,…,N to get sequence corresponding to a

duration of NT seconds.

Generating Sine Waves

tftx 02sin)( 0f

nTt Tnfnx 02sin)(

Page 11: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

11

Continuous Sine Wave

0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Time in seconds

Page 12: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

12

Sampling Operation

0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Time in seconds

Page 13: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

13

Sampled Signal

0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Time in seconds

Page 14: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

14

Discrete Array

10 20 30 40 50 60-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Index (n)

Page 15: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

15

MATLAB

>> f0=100;>> T=.0008;>> n=0:62;>> x=sin(2*pi*f0*T*n);>> stem(n,x)

Tnfnx 02sin)(

start value : end value (assumes increment of 1)

10 20 30 40 50 60-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

stem(n,x) plot(n,x)

Page 16: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

16

Good Programming Habits

>> f0=100;>> T=.0008;>> n=0:62;>> x=sin(2*pi*f0*T*n);>> stem(n,x)

>> x=sin(2*pi*100*.0008*(0:62));>> stem(n,x)

GOOD

BAD!

Do not Repeat Yourself!!

Page 17: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

17

MATLAB vs. C C code to create a sine wave:#include <stdio.h>

#include <math.h>

main(argc,argv)

int argc;

char *argv[];

{

int i,n;

double *sv, f0;

n=5000;

f0=100;

sv = (char *) calloc(n, double);

for (i = 0; i < 50000; i++) {

sv(i) = sin(2*3.1415927*f0*I/44100);

}

}

Page 18: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

18

Other MATLAB Abilities

Many built-in functions Can easily add your own functions Immediate results without compiling Can solve systems of equations easily All kinds of plotting methods Simulink Maple Symbolic Math Toolbox

Page 19: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

19

Sampling Period

If we sample too slowly (T too large), we can get a misleading sequence.

Page 20: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

20

Sampled Signal

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 21: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

21

Is this the true signal?

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 22: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

22

Or, is this the true signal?

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 23: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

23

Aliasing

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 24: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

24

Sampling Rate Too Low

0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 25: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

25

“Wagon Wheel Effect”

Correct Sampling

Aliasing

Page 26: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

26

Avoiding Aliasing

To avoid aliasing, sample at least twice as fast as the highest frequency in the signal.» Minimum of two samples per period» Shannon’s Sampling Theorem

Example:» A 40 Hz sine wave should be sampled at 80 Hz

or more

Page 27: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

27

Playing Sounds in MATLAB

Can play sounds directly from MATLAB:» sound(x,44100)

– x is the sequence of values in a vector

– 44100 is the output sampling rate

» soundsc(x,44100)– Same as sound() but auto-levels before playing

– Each sound played at the same level

Page 28: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

28

Playing Sounds in MATLAB

Can read or write WAV files:» y = wavread(‘fast.wav’);

– y is the sound sequence read in as a vector

– fast.wav is the name of the file to be read.

» wavwrite(y,44100,’fast.wav’)

Page 29: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

29

Stereo in MATLAB

If x is an Nx2 vector, the left column will be played as the left channel, and the right column will be played as the right channel.» fl=200;» fr=300;» t=[0:1/44100:8];» xl = sin(2*pi*fl*t);» xr = sin(2*pi*fr*t);

sound([xl’ xr’],44100)

Page 30: 1 Announcements l Take textbook to lab. »Be sure to read Chapter 13 before lab –MATLAB tutorial –Can skip Section 13.4 l Bring your transmitter and receiver

30

Quiz 8

1. Long calculations or detailed specifications should be included in the main text of the a report. (True or False)

2. Contractions are acceptable in an engineering report. (True or False)