In lecture on 11/15 and 11/17 we discussed translating text into Morse Code, first in ASCII (as an application of the concept of Cell Arrays in MATLAB)—then taking it a step further, and translating this into digital audio (as 500Hz Sine Wave Tones of specific durations.)
This lab gives you an opportunity to work with those files to get a bit more insight into how they operate.
This lab is very basic, so it is only worth 50 points. Basically, you are going to take some existing MATLAB files that can translate Morse Code only for the letters A-F, and modify them so that they can produce Morse Code for the letters in your first and last name.
You'll also modify the regression test script so that it tests the files on words that can be formed with the letters of your first and last name.
There is a temptation to "go further" and produce the Morse Code translation for the entire alphabet.
DON'T DO THAT!
I'm requiring you to do only the letters of your first and last name for a reason—to discourage improper collaboration. Doing the entire alphabet increases the usefulness of your code to others in the class, and raises the temptation to share code. By doing only the letters of your first and last name, your submission is particular to YOU.
TAs and the professor will be on the lookout for code copying. Don't put yourself at risk—do ONLY the letters of your first and last name, and don't share code with others.
To ensure compliance with this requirement, a 10% deduction will be taken—up to 30%—will be made for each letter NOT in your first and last name. I don't mean to be harsh—but I do need to make sure each person is doing his/her own work.
Look over the lecture notes from 11/15 and 11/17. Ask your TA and/or your professor about things you don't understand.
Also, review Section 7.2 in the MATLAB textbook, and also review Professor Conrad's notes about Section 7.2
Instead of calling these "steps" as in previous labs, I'm calling them "parts" to avoid confusion with the four "steps" of the design recipe: (1) contract, (2) examples, (3) body, (4) testing. We'll use those four "steps" in Part 3 —and we'll add a "fifth step", namely (5) application.
Create a new subdirectory ~/cisc106/lab011, and make that your working directory.
If you are not sure how to do this, then review the instructions from lab03, steps 1a through 1d.
There are two ways to copy the files for this week's lab. Read over both methods before deciding which one to use.
/www/htdocs/CIS/106/pconrad/06F/labs/lab11
The work you do in part 2 of this lab is only for practice and learning. There is nothing to turn in from this part of the lab. But it is still important and required.
As we demonstrated in lecture, the file convertMorseAthruF.m can be used to convert text to Morse Code, provided that the text consists only of the capital letters A-F, and the space.
Try it out for yourself. Change directory into your lab11 directory (the one where you copied the files in Part 1b), and try executing the following commands. Make up your own words that can be made up only of the letters A-F.
>> cd ~/cisc106/lab11 >> !cp /www/htdocs/CIS/106/pconrad/06F/labs/lab11/* . >> ls A.wav convertMorseAthruF.m testConvertMorseAthruF.m A_BEAD.wav morseSinWavSamples.m testMorseSinWavSamples.m FEED_ABBA_BEEF.wav sineWavVector.m testSineWavVector.m approxEquals.m testApproxEquals.m >> convertMorseAthruF('DAD') ans = --- . . . --- --- . . >> convertMorseAthruF('A FAB BEAD') ans = . --- . . --- . . --- --- . . . --- . . . . . --- --- . . >> convertMorseAthruF('SAD DAD') ??? Error using ==> convertMorseAthruF Character "S" in position 1 is not permitted >>
We demonstrated working with some audio files in lecture that can create sine waves of various frequencies. Try these out for yourself:
>> cd ~/cisc106/lab11
>> makeA440
>> makeCsharp
>> makeDaboveA220
>>
After executing these M-files, you should have audio files (.wav files) on your web page that you can play, at the web page:
For information on playing audio files on the Sun Rays, see the following web page:
This part only makes sense to do if you have some musical background—otherwise you can just skip it.
As illustrated in lecture, given the frequency of a musical note:
Experiment with creating an audio file at a different pitch by changing the number of half steps in the example files makeCsharp.m and makeDaboveA220.m. Remember to modify the file names too.
Look at the contents of the file morseSinWavSamples.m. This file defines a function that consumes a string of ASCII characters (in the same format that is output by convertMorseAthruF.m) and produces the sound samples for the dits and dahs.
The file testMorseSinWavSamples.m is a script that tests this. Note that this test is a bit different—to see if the test is successful, we actually have to listen to the file and see if the dits and dahs "sound" right. The script writes the files out to the current directory, then copies them over to a web directory so that the sound files can be played through a web browser.
>> testMorseSinWavSamples
A.wav should now be a Morse Code file containing
the Morse Code for 'A'
A_BEAD.wav should now be a Morse Code file containing
the Morse Code for 'A BEAD'
FEED_ABBA_BEEF.wav should now be a Morse Code file containing
the Morse Code for 'FEED ABBA BEEF'
>>
You should try running this file so that you can get comfortable with playing audio either on the Sun Rays, or on your home PC—preferably both. You'll need to be comfortable with that to complete Part 3—the part you have to do for credit.
Your task is to write a new M-file defining a function based on the M-file convertMorseAthruF.m
, called something like convertMorseFREDSMITH.m
convertMorseLISASIMPSON.m
convertMorseWAYLONSMITHERS.m
convertMorseRALPHWIGGUMS.m
Inside the file, you'll build a Cell Array like the one in convertMorseAthruF.m
, but you'll only convert the letters that are in your name.
For example, if your name was Lisa Simpson, your Cell Array would have entries for the Morse Code for the letters LISAMPON, plus the space. If you like, you can rearrange these in alphabetical order, (e.g. AILMNOPS) but it is not necessary—that that is necessary is to have the order of the Morse Code values in your cell array correspond with the order of the letters in the variable letters
.
In the end, you should be able to convert all the letters of your name, plus any word, sentence or phrase made up only of those letters.
You'll also need to construct test file like testConvertMorseLISASIMPSON.m
that is used to test the file. That file should test the file on at least three strings (as described below.)
Finally, you'll modify the testMorseSinWavSamples.m
file to use those three tests, i.e. to create three sound files corresponding exactly to the three tests in your testConverMorseLISASIMPSON.m
type file.
As you modify these files, let the steps in the Design Recipe be your guide:
Start by copying the convertMorseAthruF.m
file to a file called convertMorseYOURFIRSTANDLASTNAMEHERE.m
convertMorseYOURFIRSTANDLASTNAMEHERE.m
, but rather it should contain your first and last name in all caps. Then, modify the contract part of the file. What is consumed and produced won't change much, but it will change slightly. The name of the function will change. Also, change the name, date, section number, etc.
At this stage, change the examples. You should have three, following this pattern:
The web site http://wordsmith.org/anagram/ may be helpful in coming up with words and phrases from your name.
Work out the Morse Code by hand. Resist the temptation to write the program first and then let the program do it for you—that defeats the entire purpose of making these examples.
Now, change the body of the function. You won't have to change much—but you do need to know what you are doing.
Now, create a test script testConvertMorseLISASIMPSON.m
based on the test script testConvertMorseAthruF.m
That file should test the file on at least three strings (the examples indicated at step 2 above.)
Finally, modify the testMorseSinWavSamples.m
file to use those three tests, i.e. to create three sound files corresponding exactly to the three tests in your testConverMorseLISASIMPSON.m
type file.
Your diary file should contain the following:
convertMorseLISASIMPSON.m
testConvertMorseLISASIMPSON.m
testMorseSinWavSamples.m
convertMorseLISASIMPSON.m
directly at the MATLAB >>
prompt (e.g. >> convertMorseLisaSimpson('LISA');
) testConvertMorseLISASIMPSON.m
and testMorseSinWavSamples.m
Be sure that the files created by your testMorseSinWavSamples.m
script are readable on the web.
Following the instructions from lab10 step 6, create a file lab11.zip
containing a subdirectory lab11, with the same three .m files you listed out in part 4 above.
Upload and submit the following files:
Penalties for late submissions
convertMorseLISASIMPSON.m
(10 pts) testConvertMorseLISASIMPSON.m
(10 pts) testMorseSinWavSamples.m
(10 pts)