1 / 10

Lab 3

Lab 3. Signals in Matlab. Signals in Matlab. Lab objectives Generate a signal which is the sum of two sinusoids of different frequencies, of a level and sample rate suitable to send to the soundcard. Plot it. Add noise to the above signal, and plot the result.

asabi
Télécharger la présentation

Lab 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 3 Signals in Matlab

  2. Signals in Matlab Lab objectives • Generate a signal which is the sum of two sinusoids of different frequencies, of a level and sample rate suitable to send to the soundcard. Plot it. • Add noise to the above signal, and plot the result. • Write it to a .wav file for playback

  3. Signals in Matlab Let’s pick some parameters. We want to keep the .wav file reasonably compact, so let’s use monaural 8-bit format, and a sampling rate of fs = 8 kHz. The file will be slightly more than 8 kB for each second of signal. The maximum signal amplitude we can write to a .wav file is 1, so we’ll make our sinusoids have an amplitude of 0.2, or an RMS level of 0.141.

  4. Signals in Matlab We’ll pick a noise level that’s audible, but below the signal value. The noise variance will be 0.1. We’re sampling at fs = 8000 samples/sec, so the sinusoids must each be less than half that frequency. We’ll pick 1,000 Hz. And 1500 Hz. You’ll be handing in an m-file which generates and plots these signals, and writes a .wav file. You’ll turn in a second m-file that reads the .wav file.

  5. Signals in Matlab Let’s generate 5 seconds worth of signal, so the first step is to generate a time vector representing 5 seconds at 8000 samples/second. The vector’s length will be: t = linspace(0, 5, 40000);

  6. Signals in Matlab Next, generate the 1000 Hz sinusoid: s1 = A1 * sin(2 * pi * 1000 * t) Where A1 is a constant that sets the amplitude of the sinusoid Generate s2, the 1500 Hz sinusoid similarly

  7. Signals in Matlab Next, sum the sinusoids together. Call the resultant “s”, and plot 128 samples of it. Label the axes (see how this was done in Lab 1). Now, generate the noise. n = randn(size(t)) Will generate a vector of 0-mean, unit variance, normally distributed gaussian noise, the same size as the vector t. In other words, 5 seconds of Gaussian noise!

  8. Signals in Matlab We want the noise variance to be half of the signal power (3 dB below the signal), so n = .1 * randn(size(t)); Will do the job. Add this to the sum of the two sinusoids, and plot it.

  9. Signals in Matlab Next, we’ll write it to a .wav file. In Matlab, use wavwrite(sn, 8000, 8, ‘test.wav’) Where sn is the vector you’ve created by summing the two sinusoids with the noise.

  10. Signals in Matlab In octave, ausave(‘test.wav’, sn’, 8000, ‘short’) Will do the same thing. You’ll have to download ausave.m (link on the website) and place it in the “site/m” folder.

More Related