Mathcad - FFT TriangleWave - University of...
Click here to load reader
Transcript of Mathcad - FFT TriangleWave - University of...
FFT_TriangleWave.xmcd 10/29/2010 1
Create Data and Sample Exactly One Period
N 64:= i 0 1, N 1−..:= T 3:= ω2 π⋅
T:= Δt
TN
:= fs1
Δt:=
Triangle Wave
fT t Tp, ( ) if mod t Tp, ( )Tp2
<4 mod t Tp, ( )⋅
Tp1−, 1
4T
mod t Tp, ( )Tp2
−⎛⎜⎝
⎞⎟⎠
−, ⎡⎢⎣
⎤⎥⎦
:=
ti i Δt⋅ 1.0⋅:=
0 1 2 31−
0.5−
0
0.5
1
fT ti T, ( )
Δt i⋅
Calculate Coefficients with FFT Algorithm. In MathCAD, fft and FFT are alternate forms. FFTcarries the negative sign on the exponential, and is multiplied by 1/N in going from time to frequency. The function fft has the positive sign on the exponential, and is multiplied by1/sqrt(N) in going from time to frequency.
Fi fT ti T, ( ):= k 0 1, N 1−..:= X N FFT F( )⋅:= rows X( ) 33=
n 0 1, N2
..:= An2N
Xn:= A0
X0
N:= A N
2
1N
X N
2
⋅:=
ϕn if Xn 0> arg Xn( ), 0, ( ):= f nnT
:=
F1 t( ) A01
N
2
n
An cos 2 π⋅ f n⋅ t⋅ ϕn+( )⋅( )∑=
⎡⎢⎢⎢⎣
⎤⎥⎥⎥⎦
⎡⎢⎢⎢⎣
⎤⎥⎥⎥⎦
+:=
FFT_TriangleWave.xmcd 10/29/2010 2
0 1 103× 2 103× 3 103×1−
0.5−
0
0.5
1Signal Reconstruction
Fi
F1 Δt i⋅( )
Δt i⋅ 1000⋅
i1 0 1, 2 N⋅ 1−..:=
0 2 4 61−
0.5−
0
0.5
1Signal Reconstruction over Two Periods
xi
F1 Δt i1⋅( )
Δt i⋅ Δt i1⋅,
FFT_TriangleWave.xmcd 10/29/2010 3
Display Amplitude, Phase Diagram
0 5 10 150
0.2
0.4
0.6
0.8
1Amplitude Spectrum
Frequency (Hz)
Am
plitu
de
An
fn
0 5 10 15200−
100−
0
100
200Phase Spectrum
Frequency (Hz)
Phas
e (d
egre
es)
ϕn180
π⋅
fn
Parseval' Theorem for FFT.
1N
0
N 1−
i
Fi mean F( )−( )2∑=
⋅ 0.577914=
1
N
21−
n
12
An( )2⋅⎡⎢
⎣⎤⎥⎦∑
=
A N
2
⎛⎜⎝
⎞⎟⎠
2+ 0.577914=
1
N
21−
n
12
An( )2⋅⎡⎢
⎣⎤⎥⎦∑
=
⎡⎢⎢⎢⎣
⎤⎥⎥⎥⎦
0.577914=
FFT_TriangleWave.xmcd 10/29/2010 4
m 1:= c 0.5:= k 20:= T 3:= ω2 π⋅
T:= Fo 1:=
ωnsm
:=ωn
2 π⋅0.159 s0.5
= ζc
2 m s⋅⋅:= ζ 0.25 s 0.5−
=
Define the transfer function |H(jω)| and arg[H(jω)], plot frequency response.
θn arg1
2 π⋅ f n⋅( )2− m⋅ i 2⋅ π⋅ f n⋅( ) c⋅+ k+
⎡⎢⎢⎣
⎤⎥⎥⎦
:=Hn1
2 π⋅ f n⋅( )2− m⋅ i 2⋅ π⋅ f n⋅( ) c⋅+ k+
:=
0 5 10 150
0.1
0.2
0.3
0.4
Hn
fn
0 5 10 154−
3−
2−
1−
0
θn
fn
FFT_TriangleWave.xmcd 10/29/2010 5
Compute the Fourier series for the output, reconstruct Fourier series, amplitudeand phase spectrum.
X 0:= Xn An Hn:=
0 5 10 150
0.02
0.04
0.06
Xn
fn
FFT_TriangleWave.xmcd 10/29/2010 6
ti1 i1 Δt⋅ 1.0⋅:=
xi10
N
2
n
Xn( ) cos 2 π⋅ f n⋅ ti1⋅ θn+ ϕn+( )⋅⎡⎣ ⎤⎦∑=
:=
0 2 4 60.06−
0.04−
0.02−
0
0.02
0.04
0.06
xi1
ti1
Compute the RMS value of the input and output
sx
1
N
21−
n
12
Xn( )2⋅⎡⎢
⎣⎤⎥⎦∑
=
X N
2
⎛⎜⎝
⎞⎟⎠
2+:= sx 0.036801= stdev x( ) 0.036801=
sF
1
N
21−
n
12
An( )2⋅⎡⎢
⎣⎤⎥⎦∑
=
A N
2
⎛⎜⎝
⎞⎟⎠
2+:= sF 0.577914=
FFT_TriangleWave.xmcd 10/29/2010 7
f
0
01
2
3
4
5
6
7
8
9
10
11
12
13
14
15
00.333
0.667
1
1.333
1.667
2
2.333
2.667
3
3.333
3.667
4
4.333
4.667
...
=