Docsity

CS 1371 Fall 2006 Practice Test 3: Sounds, Images, File I/O, Numerical Methods and Sorting, Exams of Computer Science

Toggle sidebar
bg1
CS 1371 – Fall 2006
Practice Test 3
Sounds
1. Write a function called test3sound that takes in a single note file and the number of
half-steps to raise the note by. Have the function adjust the sound by the specified
number of half-steps, and play the sound.
2. Write a function to that takes in a file name of a .wav file and a number n. The function
should read in the sound file and stretch the sound data by n (if n is > 1) and shrink it by
n (if n is < 1). The function should then save this data as a sound file with “new” before
the original file name.
3. You have a file called 'music.wav':
- Write code to find the total duration that the sound will be played
- Write code to play the note 'C' (Freq = 261.6) at Fs = 44100
Also discuss the implication of the pitch of a sound when its sampling frequency is
changed, or the number of samples in a sound file is changed.
Images
1. Write a function called GreenUpsideDown that takes in an image and returns that
image with the green values changed to be the average of the red and blue values at each
pixel. The image should also be flipped upside down.
2. You are given a color image, but want to make it grayscale to save your printer ink. To
make an image grayscale, a pixel’s color values are all set to a certain intensity, which is
the average of its red, green, and blue values. Write a function, ans = grayscale(im), that
takes in the string name of an image and returns the new image matrix as well as showing
the new grayscale image. (Hint: You might want to convert the color values to doubles
before performing operations on them)
pf3
pf4

Partial preview of the text

Download CS 1371 Fall 2006 Practice Test 3: Sounds, Images, File I/O, Numerical Methods and Sorting and more Exams Computer Science in PDF only on Docsity!

CS 1371 – Fall 2006

Practice Test 3

Sounds

  1. Write a function called test3sound that takes in a single note file and the number of half-steps to raise the note by. Have the function adjust the sound by the specified number of half-steps, and play the sound.
  2. Write a function to that takes in a file name of a .wav file and a number n. The function should read in the sound file and stretch the sound data by n (if n is > 1) and shrink it by n (if n is < 1). The function should then save this data as a sound file with “new” before the original file name.
  3. You have a file called 'music.wav':
    • Write code to find the total duration that the sound will be played
    • Write code to play the note 'C' (Freq = 261.6) at Fs = 44100 Also discuss the implication of the pitch of a sound when its sampling frequency is changed, or the number of samples in a sound file is changed.

Images

  1. Write a function called GreenUpsideDown that takes in an image and returns that image with the green values changed to be the average of the red and blue values at each pixel. The image should also be flipped upside down.
  2. You are given a color image, but want to make it grayscale to save your printer ink. To make an image grayscale, a pixel’s color values are all set to a certain intensity, which is the average of its red, green, and blue values. Write a function, ans = grayscale(im), that takes in the string name of an image and returns the new image matrix as well as showing the new grayscale image. (Hint: You might want to convert the color values to doubles before performing operations on them)

File I/O

  1. You are provided a file called ‘data.xls’. It contains 3 columns containing the roll number (stored as a number), the first name (stored as a string) and the final grade (stored as a number).

Create a script that does the following:

  • Read the first column ‘Roll’ values into a vector called ‘firstData’.
  • Read the third column ‘Grade’ values into a vector called ‘thirdData’
  • Make a plot of the two vectors and make sure you label it.
  • Assign a letter grade to each name based on the following final grade: 90-100% = A 80-90% = B 70-80% = C 60-70% = D below 60% = E

Save this as a new column in a new excel file ‘finalData.xls’ under the heading ‘Letter Grade’ along with all the columns and rows of the previous file.

  1. A sports writer has been keeping track of Georgia Tech’s football team playing against U(sic)GA in a Microsoft Excel spreadsheet called ‘rivalry.xls’. For each game he recorded GT’s score in the 1st^ column under the heading “GT” and the opposing teams score in the 2nd^ column under the heading “U(sic)GA”. You are to write a script that reads in this excel file and stores the amount of GT wins in the variable called Wins , the amount of GT losses in a variable called Losses , and the amount of ties in a variable called Ties. The number of games played is unknown.

Example Excel File Format

GT U(sic)GA 28 6 0 0 48 6 7 14

Would give Wins = 2 Losses = 1 Ties = 1

b. After plotting the data, you think it follows a parabolic shape. Find a quadratic approximation of the data and use it to estimate the concentration at 40 seconds. Store it in B.

c. Now you want to analyze the rate of change in concentration. Plot the derivative dC/dt using the original data (not the quadratic approximation).

Sorting

  1. What is the Big O of the following sorting algorithms?
  • Quick Sort
  • Bubble Sort
  • Insertion Sort
  • Merge Sort
  1. Sort the following vector using all the 4 sorting algorithms: [36 25 89 41 20 69 6 99]