Write a function in the form double f(double t)
to compute and return the sum of two sine waves with periods
T1
and T2
at a point t
:
y = sin(2πt/T1) + sin(2πt/T2)with
T1
= 20/3 and T2
= 8.
In the main program, call the function in a loop for values of
t
from 0 to 100 in steps of 1.
Define preprocessor symbolic constants for π, T1
,
T2
, and 100 (the final t
value).
(notes)
The output must be suitable for plotting, i.e. just one column of
numbers (the y values), with no headings.
Plot the program output using the VECR 2D plot button:
Your plot should look similar to the one
in the class notes for sum of two sine waves.
Optional: if you change the addition to multiplication in the formula
for y
,
your plot should look similar to the one
in the class notes for product of two sine waves.
You can also plot the frequency content of the sum or product output
using the Discrete Fourier Transform (DFT) by piping to the VECR dft
program using args: | dft
Optional: if you change the number of points from 101 to 50000 then the output can be played as audio using the VECR audio/speaker button.
Write a program to produce 101 samples of a noisy sine wave based on the formula:
y = A*sin( w*t + p) + nfor t = 0, 1, 2, ..., 100 where the amplitude A, radian frequency w = 2*pi/T, phase shift p, and additive noise n are randomly generated in the following ranges:
1.0 <= A <= 2.0 20.0 <= T <= 40.0 0.0 <= p <= 2*pi -0.3*A <= n <= 0.3*AProgram output must be suitable for plotting.
A, T, w, and p must be randomly generated just once at the beginning of the program, then they remain constant for the rest of the program. For each value of t from 0 to 100, generate a new value for the noise n to be added to the sine wave.
#include <time.h> and at the beginning of main
use srand(time(0))
to initialize rand with the current time.
You can use the rand_float function from the end of chapter4_7.c
Save the output of one run of your program in a file for use as input to problem #3, i.e. Run with args: > p2.out
For the
three-point sliding window
use three doubles, say y1,
y2, and y3, all initialized to zero, and every time the
program reads a new input value, say d, slide the window by doing:
y1 = y2; y2 = y3; y3 = d;
so y1, y2, y3 will always
hold three consecutive input values. The average to print is just
(y1+y2+y3)/3
.
Write a program to generate 30 random birthdays, i.e. random integers in the range 1 to 365, one per line.
Test using the VECR test link above the Run button, which will run your program and sort/count the output, making it easy to see collisions. Sample output and test.