ECE3340 Numerical Methods |
|
Class blog 2/19
ECE 3340 - Han Q. Le (c)
If you need look up how to do certain things for HW 3 and classwork, this is it! If you have questions, send in and this will be updated as needed.
1. How to record voice and extract audio data
There are two options. Option A is recommended. If you are stuck, use option B. Decide, then use ONLY ONE option throughout the homework to avoid possible errors.
In addition, it’s better to stick to a consistent
sample rate to avoid similar error.
- Use 22050 samples/sec to have less sampled points, smaller data
for computer to handle.
- Use 44100 samples/sec if you are a s[lower case]oprano or tenor.
It should be OK with a fast computer, as there are twice as much
data to handle.
- You can use mixed sample rates, as long as you specify correctly, and
embed in every instance of the HW, so that the grader
doesn’t have to guess and enter a value to run your things.
- It doesn’t matter you choose stereo or mono. The HW requires you use only one
channel, which is either 1 (left) or 2 (right) if stereo,
and a sum of both if you choose mono.
Option A: SystemDialogInput
Out[92]=
To obtain data for analysis, use this function below: (for this option A only)
In[27]:=
Example:
Out[94]=
Option B AudioCapture
Out[96]=
To obtain data for analysis, use this function below: (for this option B only)
In[2]:=
Example:
Out[100]=
2. How to import and extract audio data
Use this:
Example:
In[5]:=
To verify you import properly:
Out[7]=
you can also Import by inserting a file path:
3. Array handling: treat sound data just like the lists and arrays we have done previously
3.1 Speaking in reverse
Once you obtain sound data that can be ListPlayed:
Out[101]=
you can try running the sound in time-reversal:
Out[103]=
Do you recognize your own voice running in reverse? Next time, if your friend send you a message that sounds like a foreign tongue, yet s/he doesn’t speak any foreign language, try running reverse.
3.2 Cubing your voice
In[23]:=
Out[23]=
3.3 Square-rooting your voice
In[20]:=
Out[20]=
3.4 Negativing your voice
If you reverse the sign, would it make any difference? If you have some sound data, try this:
In[24]:=
Out[24]=
Do you know why it sounds exactly the same as the original? Yet, if you add them together:
we’ll hear nothing without bothering to test out. What application is this? (hint: look up noise cancellation technology)
3.5 Imposing amplitude modulation
In[42]:=
Out[42]=
In[69]:=
Example of high-rate modulation (gurgling voice, I have a bad cold)
In[49]:=
Out[49]=
Example of very-low-rate modulation (I seem to go back and forth between near and far)
In[71]:=
Out[71]=
3.6 Rotating your recording
In[75]:=
In[76]:=
Out[76]=
3.7 Chop up your recording and mix randomly
In[101]:=
Out[104]=
3.8 Histogram of your recording
In[117]:=
Out[118]=
The above is known as double-sided Laplace distribution (asymmetric)
In[119]:=
Out[119]=
This is more symmetric, looking only for the difference of one point to the next (like derivative).
You will see that Laplace distribution, like Gaussian, permeates all things in science and engineering, especially social science, business & finance, and economics.
4. How operate with two or more sounds together.
4.1 Add: linearity (karaoke style)
Suppose you have two data: x2dat and y2dat, you can
add them like this:
a*
x2dat +
(1-a)*y2dat or {a,
1-a} . {x2dat, y2dat}.
The two data must have the same
length of course, and a
can be any number to make the relative strength of the two signals
to your liking. There are many ways to make two arrays of the same
length, but ask yourself which one is more important? which one do
you want to keep intact. If x2dat
is what you want to be intact, then:
Or, if you don’t want y2dat to be repeated, just pad it with zeros:
Below is an example:
In[123]:=
Out[123]=
After combining:
A code you can use to mix them is the below. Vary a until you get the right mix.
Feel free to add you vocal to your favorite band and tell your friend that you performed with them. (Note, Deep Fake technology can even put your video into another video just like photoshop).
4.2 Mutiplying: nonlinearity
What does it mean when we multiply two sounds
together? It doesn’t happen often unless by design. Sometimes, we
have nonlinear effects in a circuit. Consider signals x[t], y[t].
In a linear circuit:
output
= a x[y]+b y[t]
If there are non-linear effects, for example second-order nonlinearity, the
output may include:
γ
x[t]*y[t]
Third-order NL may include ,
,
, and so on with higher-order NL.
What do you think will happen. Suppose you have:
and
and and
?
In[29]:=
Out[34]=
a*x | b*y | a x+ by +γ x*y |
![]() |
![]() |
![]() |
Go ahead and try with your two pieces of music or recordings with large γ and see what happens. This is called non-linear distortion.
In[44]:=
Out[44]=
Try it with and
(a signal can have non-linear
mixing with itself).
4.3 Fourier synthesis
Fourier synthesis is just adding like 4.1, but often more than just two sounds: it is to add all Fourier harmonics together, this is the essence of HW3. Just like previously, we add many harmonics together to make graphics arts:
Out[33]=
![]() |
![]() |
This time. we add the harmonics together to make music.
Out[59]=
Out[296]=
5. Make your own Fourier coefficients
5.1 Here is an example
You can select your personal secret number such as
the your birthdate prime number hidden in π or e. For HW, this would be the number:
1. 15 digits of your Student ID and birthdate for amplitude:
student ID birth year, date, month
Since most student ID has #1 in front, we rotate it into the back
of 7 digits to avoid boring duplication:
1234567 -> 2345671. Then join borth year 1997, birth date 19
birth month 02
In[1]:=
Out[1]=
2. 15 phase to match the amplitude.
Use your email:
the semicolons are removed from the code so that you can see what
happens each step:
In[6]:=
Out[6]=
Out[7]=
Out[8]=
Out[9]=
3. your Fourier coefficients
In[28]:=
Out[28]=
5.2 Plot your Fourier coefficients
This is how you plot it on the complex plane.
In[29]:=
Out[30]=
In[31]:=
Out[31]=
Power spectrum of the Fourier
components
5.3 Make music
The rest is up to you to create something like 4.3 above.
END
Please practice to keep up.