Close

Matlab code to show end result

A project log for SquareTone

A hardware project that generates square waves frequencies and sums them together, Fourier style.

Adam GulyasAdam Gulyas 03/03/2015 at 08:560 Comments

Below is code you can run in matlab to see what this project will output when it's done. Change the values of a - f to generate different waveforms. (In general, keep the values between 0 and 1.)

t = 0:0.001:4*pi;
y1 = sign(sin(t));
y2 = sign(sin(2*t));
y3 = sign(sin(3*t));
y4 = sign(sin(4*t));
y5 = sign(sin(5*t));
y6 = sign(sin(6*t));
y7 = sign(sin(7*t));
y8 = sign(sin(8*t));

a = 1;
b = 0.2;
c = 0;
d = 0;
e = 0.5;
f = 0;
g = 0;
h = 0;

sum = a*y1 + b*y2 + c*y3 + d*y4 + e*y5 + f*y6 + g*y7 + h*y8;

plot(t,sum)
axis([0,15,-3,3])

Discussions