Practice Question on "Digital Signal Processing"

Topic: Nyquist Theorem and Sampling


Question

Explain how one can use MATLAB to play an A 440. Discuss your choice of sampling rate. (Feel free to post a sound file of your output.)


Share your answers below

You will receive feedback from your instructor and TA directly on this page. Other students are welcome to comment/discuss/point out mistakes/ask questions too!


Answer 1

The signal we want is $ x(t) = cos(440 * 2\pi) $.

We can first create a vector of sample times. In this case, we'll let the sample frequency be 1320 Hz over a sample interval of [0,1]

t = 0:(1/1320):1;

Next, we can generate the sound samples vector from the sample times vector.

y = cos(440*2*pi*t);

Finally, we play the signal by using the "sound" command, which needs the user to specify the sound vector and the sample rate of that vector. Our sample was 1320.

sound(y, 1320);

The sample frequency was chosen so that it was more than twice the note frequency, so that the signal could be completely recovered from this sample.

Instructor's comments: Did you actually try it in MATLAB? Did it work? -pm

Answer 2

I chose the sample rate to be 1/1000.

n = 1:10000;

x = cos(2*pi*400*n/1000);

x = x';

sound(x)

Instructor's comments: Are you sure that this works? Please post your sound file so we can hear it. -pm

Answer 3

% The following script plays a pure note A-440.

% It provides an adjustable sampling rate.

sampling_rate = 1500;

% Sampling rate should be larger than Nyquist Rate, i.e. 880Hz in this case.

t = 1:(1/sampling_rate):3;

x = cos(2*pi*440*t);

sound(x,sampling_rate);

%Code had been verified on MATLAB R2010b

Instructor's comments: Can you post your sound file so we can hear it and compare with the others? -pm

Answer 4

rate=1/1000 t=0:rate:5; x=cos(440*2*pi*t); sound(x,1/rate)

the code works

Instructor's comments: Can you post your sound file so we can hear it and compare with the others? -pm

Answer 5

samplerate=1/44100;

t1=0:samplerate:5;

x=cos(440*2*pi*t1);

sound(x,1/samplerate);

I just picked the sampling rate

because it is most commonly used rate for digital audio such as MP3.

This sampling rate is sufficient for anything in the hearing range.

Answer 6

To play a pure tone of 440 Hz, a sampling rate of only at least 2*440 = 880 Hz is needed.

However for humans to pick up the entire contribution of the signal harmonics, a sampling rate of 44.1 kHz should be used. This types out in matlab to

freq = 44100;

t=0:(1/freq):3; %for a tone of 3 second duration

x = cos(2*pi*440*t);

sound(x,freq)

Answer 7

- The sampling rate should be atlease 880Hz (Nyquist Rate)

- let rate=5000

- Constructing sine wave

- t = 0:(1/rate):1;
- A=cos(440*2*pi*t);

- Playing the sound

- sound(A,rate)

Answer 8

Since the sampling rate should be more than 880Hz sample_rate = 48*1000; %sampling rate taken to be 48 KHz t = 0:sample_rate:2;  %time taken to be 2sec interval x=cos(440*2*pi*t); sound(x,1/sample_rate);

Answer 9

sampling_rate = 9500;

t = 1:(1/sampling_rate):3;

x = cos(2*pi*440*t);

sound(x,sampling_rate);

wavwrite(x,sampling_rate,'a9500');

This above is MATLAB code that will produce a two second tone of 440hz with a sample rate of 9500. Wavwrite will then write a wav of the sound file with name a9500.wav. While playing with the sampling rate, I noticed that rates above 880 produced the tone as described in other answers. However, the tones sounded dirty or distorted in MATLAB unless much higher rates were used. As pointed out by others, the higher rate allows contribution from the harmonics which make the tone sound more natural. As expected from the nyquist rate, sampling rates below 880 produced tones with lower frequencies or pitches than the others.

https://skydrive.live.com/redir.aspx?cid=e670e6d1511a52bd&resid=E670E6D1511A52BD!105

The above link contains four .wav files at sampling rates 9500, 5000, 880, and 700 as well as a .m file to generate the four tones. However, the .wav files produced with wavwrite lose the differences in harmonics above 880 and the .wav associated with the sampling rate 880 won't produce sound on the lab computers in MS189. Perhaps I need to look into the wavwrite function a little more. Does anyone have a better way to record the sound from MATLAB?

Answer 10

Sampling rate > Nyquist Rate == 880Hz

sample_rate = 1000;

t = 1:1/sample_rate:3;

x = cos(2pi440t);

sound(x,sample_rate);



Back to ECE438 Fall 2011 Prof. Boutin

Alumni Liaison

Ph.D. on Applied Mathematics in Aug 2007. Involved on applications of image super-resolution to electron microscopy

Francisco Blanco-Silva