ECE3340 Numerical Methods

Class blog 2/21

ECE 3340 - Han Q. Le (c)

Help for HW 3 and classwork.

1. Linear regression of Fourier harmonics

Consider this:

Class_blog_
            2_21_1.gif  Class_blog_
            2_21_2.gif

Suppose we have measured various dominant frequencies from 1 to 20 and put into a paired list.
(to pair, use Transpose[{Range[Length[fList],fList}]

Out[27]=

{1,119.011} {2,238.022} {3,357.032} {4,475.043} {5,594.054}
{6,713.565} {7,831.45} {8,951.086} {9,1069.1} {10,1188.11}
{11,1305.62} {12,1431.13} {13,1549.14} {14,1660.15} {15,1787.16}
{16,1898.17} {17,2026.18} {18,2136.19} {19,2264.21} {20,2375.22}

What we can do to find the fundamental harmonic is to do a linear regression. First, let’s plot the data:

In[28]:=

Class_blog_ 2_21_3.png

Out[28]=

Class_blog_ 2_21_4.gif

We want to fit a straightline through them, this is how we can do it:

Class_blog_ 2_21_5.png

Out[39]=

Class_blog_ 2_21_6.png

In[40]:=

Class_blog_ 2_21_7.png

Out[40]=

Class_blog_ 2_21_8.png

Let’s check by plotting the fitting on top of the data:

In[41]:=

Class_blog_ 2_21_9.png

Out[41]=

Class_blog_ 2_21_10.gif

Quite a good fit, isn’t it? There is a parameter (that we will learn later on), called R-squared that indicates how good the fit is:

In[42]:=

Class_blog_ 2_21_11.png

Out[42]=

Class_blog_ 2_21_12.png

Well, 1 is perfect, so this is quite remarkable. Don’t expect to always get this. 0.999 is quite good and that's all expected from HW.

In[43]:=

Class_blog_ 2_21_13.png

Out[43]=

Class_blog_ 2_21_14.png

and we can plot:

In[38]:=

Class_blog_ 2_21_15.png

Out[38]=

Class_blog_ 2_21_16.gif

We can also plot the relative residuals:

In[45]:=

Class_blog_ 2_21_17.png

Out[45]=

Class_blog_ 2_21_18.gif

In other words, the deviation is <= 0.3%.

2. Find Fourier coefficients

There are a number of algorithms with increasing sophistication and accuracy, but here, we will use the simplest and quickest: nearest maximum.
Besides data and sampling rate, we need a list of the number of dominant harmonics, such as {2, 3, 6, 11, 8, 9, 7...}. It doesn’t have to contain every integer in a range. For example, a signal with a very weak 5th harmonic may not need the coefficient for m=5. However, if it is too bothersome having to select which one to include, which one to exclude, one can include the entire range if the added extra noises or interference are insignificant. Hence, one can just stipulate a range in low noise signals. Also, numeric order is not important. In fact, it can go from the highest to the lowest power harmonic in descending order, for example.

Go to Section 4 below to see utility  function findFourier0

Below to an example:

In[102]:=

Class_blog_ 2_21_19.gif

Proof-in-the-pudding how good the harmonic linear regression is evident in the graph below.

In[95]:=

Class_blog_ 2_21_20.png

Out[95]=

Class_blog_ 2_21_21.gif

We can see on dB scale:

In[111]:=

Class_blog_ 2_21_22.png

Out[111]=

Class_blog_ 2_21_23.gif

See the updated version of this note in the .nb file that shows how to plot your selected harmonics.

3. How to generate and obtain a clean spectrum

Will be discussed in class. Examples will also be shown.

4. General utility functions

4.1 Utility software for HW 3 - problem 1

In[10]:=

Class_blog_ 2_21_24.gif

4.2 Generate music

Example

Class_blog_ 2_21_25.gif







Created with the Wolfram Language