1. Write a for loop that will generate 32 equally-spaced samples of the following periodic waveform (only one period is shown).

for (n = 0; n < N; n++)
{
if (n < N/4) x1[n] = 4*float(n)/N;
else if (n < 3*N/4) x1[n] = 2 - 4*float(n)/N;
else x1[n] = 4*float(n)/N - 4;
}
2. Use the dft.cpp program to compute the frequency spectrum for the periodic sound wave above. Draw or plot this spectrum on a frequency vs. amplitude graph.
[ 0] x1 = +0.000, X = (+0.000,+0.000), A = +0.000 x2 = +0.000 [ 1] x1 = +0.125, X = (+0.000,-0.407), A = +0.407 P = -90.000 x2 = +0.125 [ 2] x1 = +0.250, X = (+0.000,+0.000), A = +0.000 x2 = +0.250 [ 3] x1 = +0.375, X = (+0.000,+0.046), A = +0.046 P = +90.000 x2 = +0.375 [ 4] x1 = +0.500, X = (+0.000,+0.000), A = +0.000 x2 = +0.500 [ 5] x1 = +0.625, X = (+0.000,-0.018), A = +0.018 P = -90.000 x2 = +0.625 [ 6] x1 = +0.750, X = (+0.000,+0.000), A = +0.000 x2 = +0.750 [ 7] x1 = +0.875, X = (+0.000,+0.010), A = +0.010 P = +90.000 x2 = +0.875 [ 8] x1 = +1.000, X = (+0.000,+0.000), A = +0.000 x2 = +1.000 [ 9] x1 = +0.875, X = (+0.000,-0.007), A = +0.007 P = -90.000 x2 = +0.875 [10] x1 = +0.750, X = (+0.000,+0.000), A = +0.000 x2 = +0.750 [11] x1 = +0.625, X = (+0.000,+0.005), A = +0.005 P = +90.000 x2 = +0.625 [12] x1 = +0.500, X = (+0.000,+0.000), A = +0.000 x2 = +0.500 [13] x1 = +0.375, X = (+0.000,-0.004), A = +0.004 P = -90.000 x2 = +0.375 [14] x1 = +0.250, X = (+0.000,+0.000), A = +0.000 x2 = +0.250 [15] x1 = +0.125, X = (+0.000,+0.004), A = +0.004 P = +90.000 x2 = +0.125 [16] x1 = +0.000, X = (+0.000,+0.000), A = +0.000 x2 = -0.000 [17] x1 = -0.125, X = (+0.000,-0.004), A = +0.004 P = -90.000 x2 = -0.125 [18] x1 = -0.250, X = (+0.000,+0.000), A = +0.000 x2 = -0.250 [19] x1 = -0.375, X = (+0.000,+0.004), A = +0.004 P = +90.000 x2 = -0.375 [20] x1 = -0.500, X = (+0.000,+0.000), A = +0.000 x2 = -0.500 [21] x1 = -0.625, X = (+0.000,-0.005), A = +0.005 P = -90.000 x2 = -0.625 [22] x1 = -0.750, X = (+0.000,+0.000), A = +0.000 x2 = -0.750 [23] x1 = -0.875, X = (+0.000,+0.007), A = +0.007 P = +90.000 x2 = -0.875 [24] x1 = -1.000, X = (+0.000,+0.000), A = +0.000 x2 = -1.000 [25] x1 = -0.875, X = (+0.000,-0.010), A = +0.010 P = -90.000 x2 = -0.875 [26] x1 = -0.750, X = (+0.000,+0.000), A = +0.000 x2 = -0.750 [27] x1 = -0.625, X = (+0.000,+0.018), A = +0.018 P = +90.000 x2 = -0.625 [28] x1 = -0.500, X = (+0.000,+0.000), A = +0.000 x2 = -0.500 [29] x1 = -0.375, X = (+0.000,-0.046), A = +0.046 P = -90.000 x2 = -0.375 [30] x1 = -0.250, X = (+0.000,+0.000), A = +0.000 x2 = -0.250 [31] x1 = -0.125, X = (+0.000,+0.407), A = +0.407 P = +90.000 x2 = -0.125
3. Has aliasing occurred? Why or why not?
If the DFT program is run with 64 samples instead of 32, the amplitudes of the harmonics shown above change. This implies that the 32 samples were not sufficient to collect all the information of the sound wave, and some higher frequencies "folded over" or aliased to lower frequencies, changing their values.
4. If the full sound wave is sampled at a rate of 44000 samples/sec, what are the frequencies of the first five harmonics?
f, 2f, 3f, 4f, and 5f, where f = R/N = 44000/32 = 1375 Hz
5. Given the sampling rate above, how many bytes of computer memory would be needed to store 50 seconds of this monophonic sound if each sample is stored using 2 bytes (16 bits)?
50 sec * 44000 samples/sec * 2 bytes/sample = 4400000 bytes (slightly greater than 4 MB)
COURSE INFORMATION | HOMEWORK ASSIGNMENTS
COURSE PROJECT | CS240 HELP DESK