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

Class_blog_ 2_19_1.png

Out[92]=

Class_blog_ 2_19_2.gif

To obtain data for analysis, use this function below: (for this option A only)

In[27]:=

Class_blog_ 2_19_3.png

Example:

Class_blog_ 2_19_4.gif

Out[94]=

Class_blog_ 2_19_5.gif

Option B AudioCapture

Class_blog_ 2_19_6.gif

Out[96]=

Class_blog_ 2_19_7.png

To obtain data for analysis, use this function below: (for this option B only)

In[2]:=

Class_blog_ 2_19_8.png

Example:

Class_blog_ 2_19_9.gif

Out[100]=

Class_blog_ 2_19_10.gif

2. How to import and extract audio data

Use this:

Class_blog_ 2_19_11.png

Example:

In[5]:=

Class_blog_ 2_19_12.png

To verify you import properly:

Class_blog_ 2_19_13.gif

Out[7]=

Class_blog_ 2_19_14.gif

you can also Import by inserting a file path:

Class_blog_ 2_19_15.png

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:

Class_blog_ 2_19_16.png

Out[101]=

Class_blog_ 2_19_17.gif

you can try running the sound in time-reversal:

Class_blog_ 2_19_18.gif

Out[103]=

Class_blog_ 2_19_19.gif

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]:=

Class_blog_ 2_19_20.png

Out[23]=

Class_blog_ 2_19_21.gif

3.3 Square-rooting your voice

In[20]:=

Class_blog_ 2_19_22.png

Out[20]=

Class_blog_ 2_19_23.gif

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]:=

Class_blog_ 2_19_24.png

Out[24]=

Class_blog_ 2_19_25.gif

Do you know why it sounds exactly the same as the original? Yet, if you add them together:

Class_blog_ 2_19_26.png

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]:=

Class_blog_ 2_19_27.png

Out[42]=

Class_blog_ 2_19_28.gif

In[69]:=

Class_blog_ 2_19_29.gif

Example of high-rate modulation (gurgling voice, I have a bad cold)

In[49]:=

Class_blog_ 2_19_30.png

Out[49]=

Class_blog_ 2_19_31.gif

Example of very-low-rate modulation (I seem to go back and forth between near and far)

In[71]:=

Class_blog_ 2_19_32.png

Out[71]=

Class_blog_ 2_19_33.gif

3.6 Rotating your recording

In[75]:=

Class_blog_ 2_19_34.png

In[76]:=

Class_blog_ 2_19_35.png

Out[76]=

Class_blog_ 2_19_36.gif

3.7 Chop up your recording and mix randomly

In[101]:=

Class_blog_ 2_19_37.gif

Out[104]=

Class_blog_ 2_19_38.gif

3.8 Histogram of your recording

In[117]:=

Class_blog_ 2_19_39.gif

Out[118]=

Class_blog_ 2_19_40.gif

The above is known as double-sided Laplace distribution (asymmetric)

In[119]:=

Class_blog_ 2_19_41.png

Out[119]=

Class_blog_ 2_19_42.gif

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:

Class_blog_ 2_19_43.png

Or, if you don’t want y2dat to be repeated, just pad it with zeros:

Class_blog_ 2_19_44.png

Below is an example:

In[123]:=

Class_blog_ 2_19_45.png

Out[123]=

Class_blog_ 2_19_46.gif

After combining:

Class_blog_ 2_19_47.gif

A code you can use to mix them is the below. Vary a until you get the right mix.

Class_blog_ 2_19_48.png

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]   Class_blog_
            2_19_49.png     Class_blog_
            2_19_50.png

Third-order NL may include Class_blog_
            2_19_51.png, Class_blog_
            2_19_52.png    Class_blog_
            2_19_53.png , Class_blog_
            2_19_54.png, and so on with higher-order NL.

What do you think will happen. Suppose you have:
                          Class_blog_
            2_19_55.png  and        Class_blog_
            2_19_56.png  
and    Class_blog_
            2_19_57.png    and    Class_blog_
            2_19_58.png  ?

In[29]:=

Class_blog_ 2_19_59.gif

Out[34]=

a*x b*y a x+ by +γ x*y
Class_blog_ 2_19_60.gif Class_blog_ 2_19_61.gif Class_blog_ 2_19_62.gif

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]:=

Class_blog_ 2_19_63.png

Out[44]=

Class_blog_ 2_19_64.gif

Try it with Class_blog_
            2_19_65.png and Class_blog_
            2_19_66.png (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]=

Class_blog_ 2_19_67.gif Class_blog_ 2_19_68.gif

This time. we add the harmonics together to make music.

Class_blog_
          2_19_69.gif

Out[59]=

Class_blog_ 2_19_70.gif

Class_blog_
          2_19_71.gif

Out[296]=

Class_blog_ 2_19_72.gif

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]:=

Class_blog_ 2_19_73.png

Out[1]=

Class_blog_ 2_19_74.png

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]:=

Class_blog_ 2_19_75.gif

Out[6]=

Class_blog_ 2_19_76.png

Out[7]=

Class_blog_ 2_19_77.png

Out[8]=

Class_blog_ 2_19_78.png

Out[9]=

Class_blog_ 2_19_79.png

3. your Fourier coefficients

In[28]:=

Class_blog_ 2_19_80.gif

Out[28]=

Class_blog_ 2_19_81.png

5.2 Plot your Fourier coefficients

This is how you plot it on the complex plane.

In[29]:=

Class_blog_ 2_19_82.gif

Out[30]=

Class_blog_ 2_19_83.gif

In[31]:=

Class_blog_ 2_19_84.png

Out[31]=                        
                                        Power spectrum of the Fourier components

Class_blog_ 2_19_85.gif

5.3 Make music

The rest is up to you to create something like 4.3 above.

END

Please practice to keep up.

Created with the Wolfram Language