Since this was accomplished by multiplying the time domain representation of the signal by , we should be able to reverse the spectrum of a signal by multiplying it by the same sequence. This is indeed the case and the process is called (unimaginatively enough) spectral reverse. For reasons which you will soon see, it has been used as a technique for scrambling speech to prevent eavesdroppers, wiretapers, spies, and other undesirable characters from being able to understand it.
| ||
Step 1: |
First we need our sequence
:
>> flip = cos(pi*[1:40000]');
(Be sure to include the "'".)
| |
Step 2: |
Now we multiply our top secret message by the encoding sequence:
>> out1 = sig1 .* flip; | |
Step 3: |
Look at the spectrogram of the output signal and verify that
the spectrum of the original signal has indeed been flipped.
| |
Step 4: |
Listen to the signal. Can you understand it?
| |
Step 5: |
As a test of the security of this system, have a member of another
lab group listen to your reversed signal
and try to understand it.
| |
Step 6: |
So how do we unscramble the signal?
Simple, since the reflection of a reflection is the original,
simply rereflect the scrambled signal:
>> out2 = out1 .* flip; | |
Step 7: |
Listen to the rereflected signal and verify that it is unscrambled.
| |
Question 4: |
Draw a block diagram of the scrambler system be have built. Show the spectrum of the signal at each point in the system. |
Bonus Trivia Question: Explain the significance of the song that HAL sang in the movie 2001 as he was being disconnected.
Let's see if we can build up a simple tune.
| ||
Step 1: |
First we define the tempo to be 4/4 at 150 beats/minute.
>> quarter = [1:4000]; | |
Step 2: |
Now let's make a note.
>> n1 = sin(.2463 * quarter); | |
Step 3: |
Add a few more notes to our collection:
>> n2 = sin(.2765 * quarter); | |
Step 4: |
Now we can build up a phrase:
>> phrase = [n1 n2 n3 n1]; | |
Step 5: |
Add a repeat ...
>> tune = [phrase phrase];
and
voila,
our tune (or at least the beginning of it)
is ready to go.
| |
Step 6: |
Let's check the result of our labors:
>> sound(tune, Fs)
Can you recognize our "mystery tune"
from this fragment?
| |
Step 7: |
If you would like to try to complete this tune (or make up a tune of your own) here is a table of note frequencies. |
Music made up of just a sequence of sine waves is pretty boring. The musical notes we've seen in previous labs had more harmonics. Although they have a strong fundamental and few harmonics, whistled notes and notes from a flute are not pure tones. Other instruments (e.g. violins, trumpets, the voice) have an even richer set of harmonics. In each case this harmonic structure is one of the characteristics that gives the instrument its individual sound.
Another is the variation in amplitude of a note with time, called the envelope. A note from a piano begins abruptly when the hammer strikes the string, then gradually decays away. A note from a trumpet can begin very softly, build to a loud forte, and sustain until the trumpeter runs out of breath.
In some cases the harmonic structure as well as the amplitude change with time. The various harmonics in a piano note decay at different rates. In a bell, not only do the different frequencies that make up the note decay at different rates, but they are not harmonically related (and so are called partials rather than harmonics). Nevertheless, the ear perceives a pitch, based on relationships between these partials.
The ear can also perceive pitch even when no discrete frequencies are present (i.e. in a signal which is random).
But not all musical sounds have to be periodic. Just like speech contains voiced and unvoiced sounds, music and have "voiced" and "unvoiced" notes.
| ||
Step 1: |
As an example of how the shape of the envelope
shapes the character of the note,
let's make make our fake flute
into a fake piano
by adding an envelope with a sharp attack and gradual decay.
>> p1 = n1 .* (0.9995 .^ quarter); | |
Step 2: |
Let's try a
complete tune with our new "instrument"
>> p2 = n2 .* 0.9995 .^ quarter | |
Step 3: |
Plot the time function and the spectrogram of this tune.
Can you identify the notes?
| |
Step 4: |
As mentioned above, we can also create notes that are not
periodic.
First we need our FIR lowpass filter back.
>> b=fir1(50,200/5000); | |
Step 5: |
Now we turn it into a bandpass filter centered about our desired
note, put white noise into it, and get out narrowband noise which
is our note.
>> r1=filter(b.*cos([0:50]*0.2463*4),1,randn(size(n1))); | |
Step 6: |
Add a few more notes to make a complete set, and we can get
another version of our tune.
>> r2=filter(b.*cos([0:50]*0.2764*4),1,randn(size(n1))); | |
Step 7: |
Plot the time function of this tune.
>> plot(tune3)
Can you find the individual notes?
Now plot the spectrogram.
Can you find them now?
| |
Step 8: |
We can make an "orchestra" by adding together the sounds
of several instruments.
>> sound(tune2+tune3, Fs) | |
Step 9: |
However, as you probably know, this tune is a
round.
I.e. it is intended to be added to a time-shifted version of itself.
To make this work, we will need the entire tune.
If you have not completed the tune yet, here are the notes.
The notation is
name(frequency)/duration,
i.e. G(.2463)/4 is a quarter note G with
=.2463,
which is generated by
G4 = sin(.2463 * quarter);
(Giving the notes more mnemonic names (G4 for a G quarter note,
D2 for a D half note, etc.) should make it easier to build the
tune without making errors.)
"Repeat" means to repeat all the notes from the
beginning of the phrase (once, not recursively).
Phrase1: G(.2463)/4, A(.2765)/4, B(.3103)/4, G(.2463)/4; Repeat. Phrase2: B(.3103)/4, C(.3288)/4, D(.3690)/2; Repeat. Phrase3: D(.3690)/8, E(.4142)/8, D(.3690)/8, C(.3288)/8 B(.3103)/4 G(.2463)/4; Repeat. Phrase4: G(.2463)/4, D(.1845)/4, G(.2463)/2; Repeat.
Once you have assembled the complete tune, play it to make sure
all the notes are correct.
| |
Step 10: |
To play the tune as a round, we need to add the tune to
a copy of itself shifted by the length of one phrase.
Since Matlab doesn't like adding vectors of different length,
we will have to pad the beginning (or end) of each voice
with zeros.
>> voice1=[Tune zeros(size(phrase1))]; | |
Step 11: |
A more interesting effect can be obtained by having the different voices played by different "instruments". If you feel up to it, make another version of the complete tune using one of the other sounds we've created (or if you don't like any of them, make up your own instrument). Then play these two voices as a round as in the previous step. |