Kurt's Assignment: Difference between revisions

From Class Wiki
Jump to navigation Jump to search
Kurt (talk | contribs)
No edit summary
Kurt (talk | contribs)
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Common Synthesizer Waveforms=
=Common Synthesizer Waveforms=
Many synthesizers employ a variety of waveforms to produce varied sounds. The most common waveform is the sine wave. However, in additive synthesis, multiple waveforms can be added together to create a different waveform with different characteristics. The basis for this form of synthesis is the Fourier series:
<math>\begin{align}
<math>\begin{align}
         x(t) &= x(t+T) = a_0 + \sum_{n=1}^\infty a_n \cos(n\omega_0t) + b_n \sin(n\omega_0t)\\
         x(t) &= x(t+T) = a_0 + \sum_{n=1}^\infty a_n \cos(n\omega_0t) + b_n \sin(n\omega_0t)\\
         a_0 &= \frac{1}{T}\int_0^T f(t) dt\\
         a_0 &= \frac{1}{T}\int_0^T f(t)\, dt\\
         a_n &= \frac{2}{T}\int_0^T f(t)\cos(n\omega_0t) dt\\
         a_n &= \frac{2}{T}\int_0^T f(t)\cos(n\omega_0t)\, dt\\
         b_n &= \frac{2}{T}\int_0^T f(t)\sin(n\omega_0t) dt\\
         b_n &= \frac{2}{T}\int_0^T f(t)\sin(n\omega_0t)\, dt\\
       \end{align}
       \end{align}
</math>
</math>


==Square Wave==


The four basic waveforms are Sine Waves, Square Waves, Triangle Waves, and Sawtooth Waves.


===Square Wave===
By inspection of the waveform, the DC component of the wave will be 0. Also, since the waveform is odd, a<sub>n</sub> will be 0. Here is the proof:


<math>\begin{align}
<math>\begin{align}
         a_0 &= \frac{1}{T}\int_0^{\frac{1}{2}T} H dt + \frac{1}{T}\int_{\frac{1}{2}T}^T -H dt\\
         a_0 &= \frac{1}{T}\int_0^{\frac{1}{2}T} H\, dt + \frac{1}{T}\int_{\frac{1}{2}T}^T -H\, dt\\
         &=\frac{1}{T}\left[Ht\right]\bigg|_{t=0}^{\frac{1}{2}T} - \frac{1}{T}\left[Ht\right]\bigg|_{t={\frac{1}{2}T}}^T\\
         &=\frac{1}{T}\left[Ht\right]\bigg|_{t=0}^{\frac{1}{2}T} - \frac{1}{T}\left[Ht\right]\bigg|_{t={\frac{1}{2}T}}^T\\
         &=\frac{1}{T}H\frac{1}{2}T-0 - \left[\frac{1}{T}HT - \frac{1}{T}H\frac{1}{2}T\right]\\
         &=\frac{1}{T}H\frac{1}{2}T-0 - \left[\frac{1}{T}HT - \frac{1}{T}H\frac{1}{2}T\right]\\
Line 21: Line 25:
\end{align}</math>
\end{align}</math>


TODO: finish
 
<math>\begin{align}
        a_n &= \frac{2}{T}\int_0^{\frac{1}{2}T} H\cos(n\omega_0t)\, dt + \frac{2}{T}\int_{\frac{1}{2}T}^T -H\cos(n\omega_0t)\, dt\\
        &=\frac{2}{T}\left[\frac{H}{n\omega_0}\sin(n\omega_0t)\right]_0^{\frac{1}{2}T} + \frac{2}{T}\left[\frac{-H}{n\omega_0}\sin\left(n\omega_0t\right)\right]_{\frac{1}{2}T}^T\\
        &=\frac{2}{T}\left[\frac{H}{n\frac{2\pi}{T}}\sin\left(n\frac{2\pi}{T}\frac{1}{2}T\right)-0\right] + \frac{2}{T}\left[-0+\frac{H}{n\frac{2\pi}{T}}\sin\left(n\frac{2pi}{T}\frac{1}{2}T\right)\right]\\
        &=\frac{2}{T}\left[\frac{TH}{2\pi n}\underbrace{\sin(n\pi)}_\text{0}\right] + \frac{2}{T}\left[\frac{TH}{2\pi n}\underbrace{\sin(n\pi)}_\text{0}\right]\\
        &=0
\end{align}</math>
 
 
This just leaves the sine component of the waveform found below.
 
<math>\begin{align}
        b_n &= \frac{2}{T}\int_0^{\frac{1}{2}T} H\sin(n\omega_0t)\, dt + \frac{2}{T}\int_{\frac{1}{2}T}^T -H\sin(n\omega_0t)\, dt\\
        &=\frac{2}{T}\left[\frac{-H}{n\omega_0}\cos(n\omega_0t)\right]_0^{\frac{1}{2}T} + \frac{2}{T}\left[\frac{H}{n\omega_0}\cos(n\omega_0t)\right]_{\frac{1}{2}T}^T\\
        &=\frac{2}{T}\left[-\frac{H}{n\frac{2\pi}{T}}\cos(n\frac{2\pi}{T}\frac{1}{2}T)+\frac{H}{n\frac{2\pi}{T}}\right] + \frac{2}{T}\left[\frac{H}{n\frac{2\pi}{T}}\cos(n\frac{2\pi}{T}T)-\frac{H}{n\frac{2\pi}{T}}\cos(n\frac{2\pi}{T}\frac{1}{2}T)\right]\\
        &=\frac{2}{T}\left[-\frac{TH}{2\pi n}\cos(n\pi)+\frac{TH}{2\pi n}\right] + \frac{2}{T}\left[\frac{TH}{2\pi n}\underbrace{\cos(2 \pi n)}_\text{1}-\frac{TH}{2\pi n}\cos(n\pi)\right]\\
        &=-\frac{H}{\pi n}\cos(n\pi)+\frac{H}{\pi n} + \frac{H}{\pi n}-\frac{H}{\pi n}\cos(n\pi)\\
        &=\frac{2H}{\pi n}-\frac{2H}{\pi n}\cos(n\pi)\\
\end{align}</math>
 
 
Finally, resulting in the Fourier series for a Square Wave.
 
<math>\text{Square Wave Fourier Series: }x(t) = x(t+T) = \sum_{n=1}^\infty \left(\frac{2H}{\pi n}-\frac{2H}{\pi n}\cos(n\pi)\right) \sin(n\omega_0t)  </math>
 
===Triangle Wave===
Like the Square wave, the DC component of the Triangle Wave is 0 by inspection. Also, since the triangle wave is odd, it is made up only by sine components.
 
<math>\begin{align}
        a_0 &= \frac{1}{T}\int_{-\frac{1}{4}T}^{\frac{1}{4}T}\left(\frac{4H}{T}t \right)\,dt + \frac{1}{T}\int_{\frac{1}{4}T}^{\frac{3}{4}T}\left(-\frac{4H}{T}t+2H\right) \,dt\\
        &= \frac{1}{T}\left[\frac{1}{2}\frac{4H}{T}t^2\right]_{-\frac{1}{4}T}^{\frac{1}{4}T} + \frac{1}{T}\left[-\frac{1}{2}\frac{4H}{T}t^2+2Ht\right]_{\frac{1}{4}T}^{\frac{3}{4}T}\\
        &= \frac{1}{T}\left[\frac{2H}{T}\left(\frac{1}{4}T\right)^2-\frac{2H}{T}\left(-\frac{1}{4}T\right)^2\right] + \frac{1}{T}\left[-\frac{2H}{T}\left(\frac{3}{4}T\right)^2+2H\left(\frac{3}{4}T\right)-\left(-\frac{2H}{T}\left(\frac{1}{4}T\right)^2+2H\left(\frac{1}{4}T\right)\right)\right]\\
        &= \frac{1}{T}\left[\underbrace{\frac{2H}{T}\frac{1}{16}T^2-\frac{2H}{T}\frac{1}{16}T^2}_\text{0}\right] + \frac{1}{T}\left[-\frac{2H}{T}\frac{9}{16}T^2+\frac{3}{2}HT+\frac{2H}{T}\frac{1}{16}T^2-\frac{1}{2}HT\right]\\
        &= 0 + \frac{1}{T}\left[-\frac{18H}{16T}T^2+\frac{3}{2}HT+\frac{2H}{16T}T^2-\frac{1}{2}HT\right]\\
        &= \frac{1}{T}\left[\underbrace{-\frac{18}{16}HT+\frac{24}{16}HT+\frac{2}{16}HT-\frac{8}{16}HT}_\text{0}\right]\\
        &= 0
\end{align}</math>
 
 
 
<math>\begin{align}
        a_n &= \frac{2}{T}\int_{-\frac{1}{4}T}^{\frac{1}{4}T}\left(\frac{4H}{T}t\right)\cos\left(n\omega_0t\right) \,dt + \frac{2}{T}\int_{\frac{1}{4}T}^{\frac{3}{4}T}\left(-\frac{4H}{T}t+2H\right)\cos\left(n\omega_0t\right)\,dt\\
        &= \frac{8H}{T^2}\int_{-\frac{1}{4}T}^{\frac{1}{4}T}t\,\cos\left(n\omega_0t\right) \,dt + \frac{4H}{T}\int_{\frac{1}{4}T}^{\frac{3}{4}T}\left(-\frac{2}{T}t+1\right)\cos\left(n\omega_0t\right)\,dt\\
        &= \frac{8H}{T^2}\left[\frac{t}{n\omega_0}\sin(n\omega_0 t)+\frac{1}{n^2\omega_0 ^2}\cos(n\omega_0 t)\right]_{-\frac{1}{4}T}^{\frac{1}{4}T} + \frac{4H}{T}\left[\frac{-\frac{2}{T}t+1}{n\omega_0} \sin(n\omega_0 t) - \frac{2}{Tn^2\omega_0^2} \cos(n\omega_0 t)\right]_{-\frac{1}{4}T}^{\frac{3}{4}T}\\
        &= \frac{8H}{T^2}\left[\left[\frac{\frac{1}{4}T}{n\frac{2\pi}{T}}\sin\left(n\frac{2\pi}{T}\frac{1}{4}T\right)+\frac{1}{n^2\frac{4\pi^2}{T^2}}\cos\left(n\frac{2\pi}{T}\frac{1}{4}T\right)\right] - \left[\frac{-\frac{1}{4}T}{n\frac{2\pi}{T}}\sin\left(n\frac{2\pi}{T}\left(-\frac{1}{4}T\right)\right)+\frac{1}{n^2\frac{4\pi^2}{T^2}}\cos\left(n\frac{2\pi}{T}\left(-\frac{1}{4}T\right)\right)\right]\right]    +    \frac{4H}{T}\left[\left[\frac{-\frac{2}{T}\left(\frac{3}{4}T\right)+1}{n\frac{2\pi}{T}} \sin\left(n\frac{2\pi}{T}\frac{3}{4}T\right) - \frac{2}{Tn^2\frac{4\pi^2}{T^2}}\cos\left(n\frac{2\pi}{T}\frac{3}{4}T\right)\right] - \left[\frac{-\frac{2}{T}\left(-\frac{1}{4}T\right)+1}{n\frac{2\pi}{T}} \sin\left(n\frac{2\pi}{T}\left(-\frac{1}{4}T\right)\right) - \frac{2}{Tn^2\frac{4\pi^2}{T^2}}\cos\left(n\frac{2\pi}{T}\left(-\frac{1}{4}T\right)\right)\right]\right]\\
        &= \frac{8H}{T^2}\left[\left[\frac{T^2}{8\pi n}\sin\left(\frac{1}{2}n\pi\right)+\frac{T^2}{n^2 4\pi^2}\cos\left(\frac{1}{2}n\pi\right)\right] - \left[-\frac{T^2}{8\pi n}\sin\left(-\frac{1}{2}n\pi\right)+\frac{T^2}{n^2 4 \pi^2}\cos\left(-\frac{1}{2}n\pi\right)\right]\right]    +  \frac{4H}{T} \left[\left[-\frac{T}{4\pi n}\sin\left(\frac{3}{2}n\pi\right)-\frac{T}{2\pi^2 n^2}\cos\left(\frac{3}{2}n\pi\right)\right] - \left[\frac{3T}{4\pi n}\sin\left(-\frac{1}{2}n \pi\right)-\frac{T}{2\pi^2 n^2}\cos\left(-\frac{1}{2}n\pi\right)\right]\right]\\
        &= \frac{8H}{T^2}\left[\frac{T^2}{8\pi n}\sin\left(\frac{1}{2}n\pi\right)-\frac{T^2}{8\pi n}\sin\left(-\frac{1}{2}n\pi\right)+\underbrace{\frac{T^2}{n^2 4\pi^2}\cos\left(\frac{1}{2}n\pi\right)-\frac{T^2}{n^2 4\pi^2}\cos\left(-\frac{1}{2}n\pi\right)}_\text{0}\right] + \frac{4H}{T}\left[-\frac{T}{4\pi n}\sin\left(\frac{3}{2}n\pi\right) - \frac{3T}{4\pi n}\sin\left(-\frac{1}{2}n\pi\right) - \underbrace{\frac{T}{2\pi^2 n^2} \cos\left(\frac{3}{2}n\pi\right) + \frac{T}{2\pi^2 n^2} \cos\left(-\frac{1}{2}n\pi\right)}_\text{0}\right]\\
        &= \frac{8H}{T^2}\left[\frac{2T^2}{8\pi n}\sin\left(\frac{1}{2}n\pi\right)\right] + \text{integrate other side}\\
        &= \frac{2H}{\pi n}\sin\left(\frac{1}{2}n\pi\right) + \text{integrate other side}
\end{align}</math>
 
<math>\begin{align}
test function &=
\end{align}</math>
 
 
===Sawtooth Wave===
 
==OCTAVE Scripts to Plot Fourier Series==
====Square Wave====
clf;            %Clear Figure
t=0:.01:10;    %Limits of the graph
T=2*pi          %Definition of the period
M=100          %Number of iterations to undergo
sum1=0;        %Initialize the sum to <br>
%----------FOURIER SERIES----------%
for m=1:1:M,    %For m=1, increment by 1 until you get to M
  if(m!=0)
    sum1 = sum1 + ((2/(pi*m))-(2/(pi*m))*cos(m*pi))*sin(m*2*pi/T*t);
  end
end<br>
%---------------PLOT---------------%
plot(t,real(sum1),'b-')
title('Fourier Series Representation of a Wave')
xlabel('time (seconds)')
ylabel('Function')
grid on;<br>
legend(num2str(M) ' terms');
print("squarewave.png","-dpng")  % Prints the plot to a png file called squarewave.png
 
 
TODO:
*finish the triangle wave derivation
*start sawtooth wave derivation
*put pictures in
*implement triangle wave Fourier Series in OCTAVE
*implement sawtooth wave Fourier Series in OCTAVE

Latest revision as of 00:11, 2 November 2010

Common Synthesizer Waveforms

Many synthesizers employ a variety of waveforms to produce varied sounds. The most common waveform is the sine wave. However, in additive synthesis, multiple waveforms can be added together to create a different waveform with different characteristics. The basis for this form of synthesis is the Fourier series:

x(t)=x(t+T)=a0+n=1ancos(nω0t)+bnsin(nω0t)a0=1T0Tf(t)dtan=2T0Tf(t)cos(nω0t)dtbn=2T0Tf(t)sin(nω0t)dt


The four basic waveforms are Sine Waves, Square Waves, Triangle Waves, and Sawtooth Waves.

Square Wave

By inspection of the waveform, the DC component of the wave will be 0. Also, since the waveform is odd, an will be 0. Here is the proof:

a0=1T012THdt+1T12TTHdt=1T[Ht]|t=012T1T[Ht]|t=12TT=1TH12T0[1THT1TH12T]=H2[H12H]=H2H2=0


an=2T012THcos(nω0t)dt+2T12TTHcos(nω0t)dt=2T[Hnω0sin(nω0t)]012T+2T[Hnω0sin(nω0t)]12TT=2T[Hn2πTsin(n2πT12T)0]+2T[0+Hn2πTsin(n2piT12T)]=2T[TH2πnsin(nπ)0]+2T[TH2πnsin(nπ)0]=0


This just leaves the sine component of the waveform found below.

bn=2T012THsin(nω0t)dt+2T12TTHsin(nω0t)dt=2T[Hnω0cos(nω0t)]012T+2T[Hnω0cos(nω0t)]12TT=2T[Hn2πTcos(n2πT12T)+Hn2πT]+2T[Hn2πTcos(n2πTT)Hn2πTcos(n2πT12T)]=2T[TH2πncos(nπ)+TH2πn]+2T[TH2πncos(2πn)1TH2πncos(nπ)]=Hπncos(nπ)+Hπn+HπnHπncos(nπ)=2Hπn2Hπncos(nπ)


Finally, resulting in the Fourier series for a Square Wave.

Square Wave Fourier Series: x(t)=x(t+T)=n=1(2Hπn2Hπncos(nπ))sin(nω0t)

Triangle Wave

Like the Square wave, the DC component of the Triangle Wave is 0 by inspection. Also, since the triangle wave is odd, it is made up only by sine components.

a0=1T14T14T(4HTt)dt+1T14T34T(4HTt+2H)dt=1T[124HTt2]14T14T+1T[124HTt2+2Ht]14T34T=1T[2HT(14T)22HT(14T)2]+1T[2HT(34T)2+2H(34T)(2HT(14T)2+2H(14T))]=1T[2HT116T22HT116T20]+1T[2HT916T2+32HT+2HT116T212HT]=0+1T[18H16TT2+32HT+2H16TT212HT]=1T[1816HT+2416HT+216HT816HT0]=0


an=2T14T14T(4HTt)cos(nω0t)dt+2T14T34T(4HTt+2H)cos(nω0t)dt=8HT214T14Ttcos(nω0t)dt+4HT14T34T(2Tt+1)cos(nω0t)dt=8HT2[tnω0sin(nω0t)+1n2ω02cos(nω0t)]14T14T+4HT[2Tt+1nω0sin(nω0t)2Tn2ω02cos(nω0t)]14T34T=8HT2[[14Tn2πTsin(n2πT14T)+1n24π2T2cos(n2πT14T)][14Tn2πTsin(n2πT(14T))+1n24π2T2cos(n2πT(14T))]]+4HT[[2T(34T)+1n2πTsin(n2πT34T)2Tn24π2T2cos(n2πT34T)][2T(14T)+1n2πTsin(n2πT(14T))2Tn24π2T2cos(n2πT(14T))]]=8HT2[[T28πnsin(12nπ)+T2n24π2cos(12nπ)][T28πnsin(12nπ)+T2n24π2cos(12nπ)]]+4HT[[T4πnsin(32nπ)T2π2n2cos(32nπ)][3T4πnsin(12nπ)T2π2n2cos(12nπ)]]=8HT2[T28πnsin(12nπ)T28πnsin(12nπ)+T2n24π2cos(12nπ)T2n24π2cos(12nπ)0]+4HT[T4πnsin(32nπ)3T4πnsin(12nπ)T2π2n2cos(32nπ)+T2π2n2cos(12nπ)0]=8HT2[2T28πnsin(12nπ)]+integrate other side=2Hπnsin(12nπ)+integrate other side

testfunction=


Sawtooth Wave

OCTAVE Scripts to Plot Fourier Series

Square Wave

clf;            %Clear Figure
t=0:.01:10;     %Limits of the graph
T=2*pi          %Definition of the period
M=100           %Number of iterations to undergo
sum1=0;         %Initialize the sum to 
%----------FOURIER SERIES----------% for m=1:1:M, %For m=1, increment by 1 until you get to M if(m!=0) sum1 = sum1 + ((2/(pi*m))-(2/(pi*m))*cos(m*pi))*sin(m*2*pi/T*t); end end
%---------------PLOT---------------% plot(t,real(sum1),'b-') title('Fourier Series Representation of a Wave') xlabel('time (seconds)') ylabel('Function') grid on;
legend(num2str(M) ' terms'); print("squarewave.png","-dpng")  % Prints the plot to a png file called squarewave.png


TODO:

  • finish the triangle wave derivation
  • start sawtooth wave derivation
  • put pictures in
  • implement triangle wave Fourier Series in OCTAVE
  • implement sawtooth wave Fourier Series in OCTAVE