Download presentation
Presentation is loading. Please wait.
Published byAldous Mitchell Modified over 9 years ago
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 to lab. »8 AA batteries »2 9V batteries »Earphones l First Professional Memo Due TODAY!
2
2 Today’s Topics l Digital signals l Introduction to MATLAB l Generating audio signals with MATLAB
3
3 Digital Music - Recording Sampler -0.0364 -0.1884 -0.6928 -1.7398 -2.7642 -2.2378 0.1711 1.8333 … 10110101010 byte CD Analog signalDigital signal
4
4 Digital Music - Playback D/A Converter -0.0364 -0.1884 -0.6928 -1.7398 -2.7642 -2.2378 0.1711 1.8333 … CD Analog signalDigital signal Audio Amplifier
5
5 Computer-Generated Signals MATLABSound Card D/A Converter Audio Amplifier 0.0000 0.5878 0.9511 0.5878 0.0000 -0.5878 …
6
6 Audio Signal l Sound generated by a PC originates as a sequence of numbers (a discrete signal). What we wantWhat we can generate
7
7 MATLAB l 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. l We can also play sounds from within MATLAB.
8
8 MATLAB Basics l 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!!
9
9 MATLAB Basics l Vectors >> v=[1,3] v = 1 3 >> v=[1;3] v = 1 3 >> v' ans = 1 3 >> v=1:0.5:3 v = 1.0000 1.5000 2.0000 2.5000 3.0000 Comma delimits columns Semicolon delimits rows Apostrophe means transpose (turn rows into columns and vice versa) start value : increment : end value
10
10 l We have been considering sine waves: l is the frequency of the sine wave. l 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
11
11 Continuous Sine Wave Time in seconds
12
12 Sampling Operation Time in seconds
13
13 Sampled Signal Time in seconds
14
14 Discrete Array Index (n)
15
15 MATLAB >> f0=100; >> T=.0008; >> n=0:62; >> x=sin(2*pi*f0*T*n); >> stem(n,x) start value : end value (assumes increment of 1) stem(n,x) plot(n,x)
16
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!!
17
17 MATLAB vs. C l C code to create a sine wave: #include 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); }
18
18 Other MATLAB Abilities l Many built-in functions l Can easily add your own functions l Immediate results without compiling l Can solve systems of equations easily l All kinds of plotting methods l Simulink l Maple Symbolic Math Toolbox
19
19 Sampling Period l If we sample too slowly (T too large), we can get a misleading sequence.
20
20 Sampled Signal
21
21 Is this the true signal?
22
22 Or, is this the true signal?
23
23 Aliasing
24
24 Sampling Rate Too Low
25
25 “Wagon Wheel Effect” Correct Sampling Aliasing
26
26 Avoiding Aliasing l 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 l Example: »A 40 Hz sine wave should be sampled at 80 Hz or more
27
27 Playing Sounds in MATLAB l 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
28
28 Playing Sounds in MATLAB l 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’)
29
29 Stereo in MATLAB l 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); l sound([xl’ xr’],44100)
30
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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.