next Plotting
up Music 270a: Matlab Tutorial 2
previous Loops and Conditional Statements


Creating a sinusoid

Let's say we want to create a sinusoid of the form

$\displaystyle x(t) = A\cos(\omega t + \phi);$ (1)

Our first task is to discretize the continuous time variable $ t$ . To do this, we must first determine a sampling rate. Recall this sampling rate has to be twice the frequency of our signal frequency. So let's first set $ f_0 = 2$ . Therefore, our sampling rate must be at least 4, but let's make it a little higher, say $ f_s = 8$ . So this means that our sampling period $ T_s$ is the inverse and the time between samples is $ T_s = 1/f_s$ . Once we set a duration, say dur=1, we have everything we need to create a sinusoid.

fs = 44100;
dur = 1;
f0 = 2;

nT = 0:1/fs:dur-1/fs;
x = cos(2*pi*f0*nT);


next Plotting
up Music 270a: Matlab Tutorial 2
previous Loops and Conditional Statements

``Music 270a: Digital Audio Processing'' by Tamara Smyth, Department of Music, University of California, San Diego (UCSD).
Download PDF version (matlabtut2.pdf)
Download compressed PostScript version (matlabtut2.ps.gz)

Copyright © 2013-01-08 by Tamara Smyth.
Please email errata, comments, and suggestions to Tamara Smyth<trsmyth@ucsd.edu>