Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
62 views
%md # Waveform Homework

Waveform Homework

%md ## Preliminaries

Preliminaries

var('t')
t
%md ## Basic information

Basic information

%md This document is a Sage Worksheet. It uses the Sage mathematical language to execute code to do a variety of mathematical tasks. Each section of the worksheet is called a "cell". Each cell starts with a light gray bar and some input. For example, this cell's input starts with a command "%md" that tells Sage to treat this cell as a "markdown" cell, meaning that you can type and format text in cells like this. The output of the cell—marked with a green bar along the left margin—will be the result of "evaluating" the cell. For a markdown cell, the output will be nicely formatted text. (Markdown is like a simpler version of HTML. Notice for example the dashes in the previous line; they are nicely formatted in the output, but use cryptic HTML codes in the input.) For a Sage cell, the output will be the result of a calculation or a plot. You can show/hide the input/output by clicking the arrows in the left margin next to the line numbers. ***** The next cell is a Sage cell. Put your cursor somewhere in there with the "2+2" and hit Shift-Enter to evaluate the cell.

This document is a Sage Worksheet. It uses the Sage mathematical language to execute code to do a variety of mathematical tasks. Each section of the worksheet is called a "cell". Each cell starts with a light gray bar and some input. For example, this cell's input starts with a command "%md" that tells Sage to treat this cell as a "markdown" cell, meaning that you can type and format text in cells like this. The output of the cell—marked with a green bar along the left margin—will be the result of "evaluating" the cell. For a markdown cell, the output will be nicely formatted text. (Markdown is like a simpler version of HTML. Notice for example the dashes in the previous line; they are nicely formatted in the output, but use cryptic HTML codes in the input.) For a Sage cell, the output will be the result of a calculation or a plot.

You can show/hide the input/output by clicking the arrows in the left margin next to the line numbers.


The next cell is a Sage cell. Put your cursor somewhere in there with the "2+2" and hit Shift-Enter to evaluate the cell.

2+2
%md For a Sage cell (unlike a markdown cell) the input is preceeded by a light gray bar with a section that turns blue once the cell is evaluated. The output is just the answer to the calculation. Try evaluating the next cell:

For a Sage cell (unlike a markdown cell) the input is preceeded by a light gray bar with a section that turns blue once the cell is evaluated. The output is just the answer to the calculation. Try evaluating the next cell:

plot(x^2)
%md ## Homework questions

Homework questions

%md Answer the questions below by filling in the cells you are instructed to complete. (Some of those cells will involve Sage code and other will involve typing full sentence responses.) Your document will be auto-saved as you go along, but if you want to be safe, hit the green "Save" button in the toolbar before you close the document. There is nothing to submit; when the due date arrives, CoCalc will automatically "collect" this file and send it back to me for grading."

Answer the questions below by filling in the cells you are instructed to complete. (Some of those cells will involve Sage code and other will involve typing full sentence responses.) Your document will be auto-saved as you go along, but if you want to be safe, hit the green "Save" button in the toolbar before you close the document. There is nothing to submit; when the due date arrives, CoCalc will automatically "collect" this file and send it back to me for grading."

%md ### Question 1

Question 1

%md #### Recall that a square wave is a sum of sine waves with odd freqencies and amplitudes that are the reciprocals of those frequencies. Plot a sum of sine waves with *all* whole number frequencies (up to 7 Hz) with amplitudes that are the reciprocals of those frequencies. (You don't need to make the plot as fancy as it was in the earlier worksheet. For example, you don't need to plot all the component sine waves in the same plot. Just plot the sum.)

Recall that a square wave is a sum of sine waves with odd freqencies and amplitudes that are the reciprocals of those frequencies. Plot a sum of sine waves with all whole number frequencies (up to 7 Hz) with amplitudes that are the reciprocals of those frequencies. (You don't need to make the plot as fancy as it was in the earlier worksheet. For example, you don't need to plot all the component sine waves in the same plot. Just plot the sum.)

# Type up answer here and evaluate the cell:
%md ### Question 2

Question 2

%md #### We've seen this waveform before. What did we call it?

We've seen this waveform before. What did we call it?

%md **Type your answer here (in between the double asterisks).**

Type your answer here (in between the double asterisks).

%md ### Question 3

Question 3

%md #### Here's one period of an idealized version of the waveform you approximated in the question above:

Here's one period of an idealized version of the waveform you approximated in the question above:

f3(t) = 1-2*t plot(f3, (t, 0, 1))
%md #### In other words, this is only one piece of a periodic function that looks like this:

In other words, this is only one piece of a periodic function that looks like this:

plot(1 - 2*t + 2 * floor(t), (t, -2, 2))
%md #### Below is the code to run a Fourier analysis on the above waveform. Be sure to evaluate all the cells below *exactly once*. If, for some reason, you need to evaluate the cells again, be sure to start with the first cell below and evaluate all of them in order.

Below is the code to run a Fourier analysis on the above waveform. Be sure to evaluate all the cells below exactly once. If, for some reason, you need to evaluate the cells again, be sure to start with the first cell below and evaluate all of them in order.

# Choose number of samples size3 = 100 # Create an empty Fast Fourier Transform object fft_data3 = FFT(size3) # Populate it with data sampled from f3. for t in range(size3): fft_data3[t] = f3(t/size3) # Plot results plot(fft_data3)
# Fourier transform to convert to frequency domain # (Modifies fft_data3 in place.) fft_data3.forward_transform()
# Create empty array for amplitudes fft_freq3 = [0 for j in range(size3/2)] # Populate it with the computed amplitudes # (For technical reasons, we only have to compute this for half of the sampled frequencies) for f in range(size3/2): fft_freq3[f] = N(pi) * abs(vector(fft_data3[f]))/(size3) # Not sure why the extra factor of pi is necessary. # Plot results bar_chart(fft_freq3[0:14])
%md #### Ignoring the small little bar above zero, explain the pattern of bars you see above. In other words, explain the frequencies and amplitudes. Are these what you expected to see?

Ignoring the small little bar above zero, explain the pattern of bars you see above. In other words, explain the frequencies and amplitudes. Are these what you expected to see?

%md **Type your answer here (in between the double asterisks).**

Type your answer here (in between the double asterisks).

%md ### Question 4

Question 4

%md #### Plot the sum of two sine waves, one with a frequency of 50 Hz and the other with a frequency of 54 Hz. (You can leave the domain blank and Sage will figure out an appropriate domain for you. If you do choose to include code that specifies the domain, be sure to choose one that shows the revelent features of the graph.)

Plot the sum of two sine waves, one with a frequency of 50 Hz and the other with a frequency of 54 Hz.

# Type up answer here and evaluate the cell:
%md ### Question 5

Question 5

%md #### If we listened to this tone, what fundamental frequency would we hear?

If we listened to this tone, what fundamental frequency would we hear?

%md **Type your answer here (in between the double asterisks).**

Type your answer here (in between the double asterisks).

%md ### Question 6

Question 6

%md #### If we listened to this tone, what beat frequency would we hear?

If we listened to this tone, what beat frequency would we hear?

%md **Type your answer here (in between the double asterisks).**

Type your answer here (in between the double asterisks).