Class blog 2/13

ECE 3340 - Han Q. Le (r)

ECE Generic - University of Houston

Han Q Le (c) -copyrighted 

1. Make a Fourier-series coefficient function

We did this in class. To avoid error, we USE variable name Λ for period instead of 2. Why? Even an experienced programmer will MAKE mistakes when having to change numerical values from one problem to the next.

In[35]:=

Class_blog_1.png

Out[35]=

Class_blog_2.png

Substitute

In[36]:=

Class_blog_3.png

Substitute again:

In[37]:=

Class_blog_4.png

Out[37]=

Class_blog_5.png

We still have to solve the problem of m=0:

In[38]:=

Class_blog_6.png

Out[38]=

Class_blog_7.png

We know that it should be zero as expected for an odd function.

Npw, we define this function in class (but here we include period Λ

In[41]:=

Class_blog_8.png

But to get an array we have to do this:

In[42]:=

Class_blog_9.gif

Out[43]=

Class_blog_10.png

What we have done here is that we allow Λ to be an unknown variable. The expression:
                            coefcube[#,Λ] &

is known as an anonymous function, a most seminal concept in the history of computer programming development. Read about it in wikipedia here. Anonymous function.

If you are not ready to learn it, it is OK for now, don’t worry. If you alreaydy know about lambda function in Python, then this is the syntax in Mathematica. For those using MATLAB, look it up.
Class_blog_11.gif

You will see that I use anonymous function every in my codes. Example, see the highlight below:

In[1]:=

Class_blog_12.png

Programmers can’t live without it.

For now, if you don’t understand, just skip and don’t worry about it. Just treat the whole expression
             (coefcube[#,Λ] &)  → a blackbox function”

One student in the class wanted to know how to put a whole array in coefcube function. We can redesign the function:

In[44]:=

Class_blog_13.png

It is a more versatile function, because we can put in just a number or a list of number, it will be OK:

Class_blog_14.png

Out[46]=

Class_blog_15.png

Or:

In[49]:=

Class_blog_16.gif

Out[50]=

Class_blog_17.png

See the above? input an array, you get an array, input a number, you get a number. Kind for kind.

By now, hope you appreciate the capability of Mathematica to handle symbolic manipulation. We don’t have a value for Λ, but it works just fine. We can’t do that in most other languages.

2. Use Mathematica built-in function

In[51]:=

Class_blog_18.png

Out[51]=

0 n==0
Class_blog_19.png True

The problem? you have to be aware that the period is -π to π. Look it up:

The nClass_blog_20.png coefficient in the Fourier series expansion of f(t) is by default given by Class_blog_21.png.

Too often, people forget to scale their function period to {-π to π}. Just like I forgot to scale our period to 2 in the class. Why, because I had chosen period = 1 (-0.5 to 0.5) for so many examples that when we change to [-1, 1], I forgot to insert the period. This is the reason to always use a variable name, not a numerical value of that variable. I forgot to change from 1 -> 2, it cost some time to find out. If we use Λ from the  beginning, the mistake would not have happened.

3. Try your hand at it

Below are the 4 codes of 4 common waveforms, taken from one of my tutorial files in Fourier “Lect_3340_LTI_FFT_utilities.nb

Take a shot and create your own function, see if you can modify the code below (just substitute your function Fourier coefficient in function xFcoeff below). and obtain a demo that you enjoy.
In section 4, I show some results with half-moon bridge.

Class_blog_22.png

5.1.2 For computation - Square wave

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Class_blog_23.png

Out[2                      8]= 

5.1.2 For computation - Sawtooth

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Code

Out[29]=               

5.1.2 For computation - Triangle ramp (symmetric ramp)

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Code

Out[71]=                 

5.1.2 For computation - Exponential

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Code

Out[72]=                  

4. Half-moon bridge

Class_blog_28.gif

Class_blog_29.png

Out[52]=

Class_blog_30.gif

In[67]:=

Class_blog_31.png

In[69]:=

Class_blog_32.png

Out[69]=

Class_blog_33.png

In[70]:=

Class_blog_34.png

Out[70]=

Class_blog_35.png

It’s nice to learn about BesselJ function. The two coefficients are:

Class_blog_36.png

In[71]:=

Class_blog_37.png

Out[71]=

Class_blog_38.png

In[80]:=

Class_blog_39.png

In[89]:=

Class_blog_40.gif

Out[96]=

Class_blog_41.gif

Code

Out[98]=



Created with the Wolfram Language