-
Notifications
You must be signed in to change notification settings - Fork 0
/
FourierAnalysis.tex
99 lines (81 loc) · 4.55 KB
/
FourierAnalysis.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% Schematic Fourier Analysis
% Author: Tobit Flatscher (https://github.com/2b-t)
%
% Disclaimer
% The following code is based on a previous version of popular community member
% Jake but I tried to make it more visually appealing. Some noise is added to the
% curves in order to make them look more realistic.
%
% Description
% This code creates a schematic representation of an FFT analysis. A signal
% over time is decomposed into its harmonic oscillations with a corresponding
% frequency using a Fourier series. The amplitude of the frequency components
% is plotted.
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{fillbetween} %for fill under curve
\begin{document}
%define colors
\definecolor{lightgray}{rgb}{0.8, 0.8, 0.8} %grid of coordinate system, axes
\definecolor{midgray}{rgb}{0.6, 0.6, 0.6} %layer of border
\definecolor{darkgray}{rgb}{0.4, 0.4, 0.4} %curves, fill under curve
\begin{tikzpicture} %create tikz picture
\begin{axis}[ %create 3d plot within tikz
set layers=standard, %use predefined layers
view={50}{30}, %perspective adjustment
domain=0:10, %plot limit in time direction
samples y=1, %samples for frequency direction
unit vector ratio*=1 2 1, %rescale unit vectors
hide axis, %do not plot axes
xtick=\empty, ytick=\empty, ztick=\empty, %no ticks on coordinate axes
clip=false %let me plot outside the coordinate system
]
%limit variables
\def\xmax{100} %limits for curves and layers
\def\xmin{0}
\def\ymax{35}
\def\ymin{5}
\def\zmax{25}
\def\zmin{-5}
\def\xlayer{110} %frequency layer
\def\sumcurve{0} %sum curve of time signal
%frequency curves
\pgfplotsinvokeforeach{1,2,3}{ %for each frequency component
\draw [on layer=background, lightgray] (axis cs:0,#1,0) -- (axis cs:10,#1,0); %axes
\addplot3 [on layer=main, darkgray, smooth, samples=200] (x,#1,{1.3*sin(2*#1*x*(157))/(#1*2)}); %plot curves (curves are somewhat arbitrary)
\xdef\sumcurve{\sumcurve + sin(#1*x*(157))/(#1*2)} %add current curve to sumcurve
}
%transparent layers
\fill[white,opacity=0.7] (\xmin,0,\zmin) -- (\xmin,0,\zmax) -- (\xmax,0,\zmax) -- (\xmax,0,\zmin) -- cycle; %transparent layer in time space
\fill[white,opacity=0.7] (\xlayer,\ymin,\zmin) -- (\xlayer,\ymin,\zmax) -- (\xlayer,\ymax,\zmax) -- (\xlayer,\ymax,\zmin) -- cycle; % transparent layer for frequency space
%grid lines
\pgfplotsinvokeforeach{\xmin,\xmin+5,...,\xmax}{ %create horizontal grid lines (time layer)
\draw[lightgray,opacity=0.6] (#1,0,\zmin) -- (#1,0,\zmax);
}
\pgfplotsinvokeforeach{\ymin,\ymin+2.5,...,\ymax}{ %create horizontal grid lines (frequency layer)
\draw[lightgray,opacity=0.6] (\xlayer,#1,\zmin) -- (\xlayer,#1,\zmax);
}
\pgfplotsinvokeforeach{\zmin,\zmin+5,...,\zmax}{ %create vertical grid lines (both layers)
\draw[lightgray,opacity=0.6] (\xmin,0,#1) -- (\xmax,0,#1);
\draw[lightgray,opacity=0.6] (\xlayer,\ymin,#1) -- (\xlayer,\ymax,#1);
}
%borders layer
\draw[midgray] (\xmin,0,\zmin) -- (\xmin,0,\zmax) -- (\xmax,0,\zmax) -- (\xmax,0,\zmin) -- cycle; %time space layer border line
\draw[midgray] (\xlayer,\ymin,\zmin) -- (\xlayer,\ymin,\zmax) -- (\xlayer,\ymax,\zmax) -- (\xlayer,\ymax,\zmin) -- cycle; %frequency space layer border line
%sum curve
\addplot3 [samples=200] (x,0,{\sumcurve+rand/7+0.2*sin(x*400)}); %sum curve time space with added random noise
% frequency curve
\addplot3 [name path=f,samples=200,domain=0.5:3.5] (11,x,{rand/30+2*sin((x-0.7)*180)^200*e^(-x/2)-0.3}); %experimentally modified curve with noise
%create fill under curve
\addplot3 [name path=ax,draw=none,samples=2,domain=0.5:3.5] (11,x,-0.5); %create fill axis
\addplot3 [darkgray] fill between [of=f and ax]; %create fill between curve and axis
%create coordinate axis
\draw[-{stealth}] (\xmin,0,\zmin-7) -- (\xmax/5.3,0,\zmin-7); %time axis
\draw[-{stealth}] (\xlayer,\ymin,\zmin-7) -- (\xlayer,\ymin+\ymax/4,\zmin-7); %frequency axis
%axis labels
\node[scale=0.7] at (0,0,-21) {Time}; %axis time space
\node[scale=0.7] at (100,22,-32) {Frequency}; %axis frequency space
\end{axis}
\end{tikzpicture}
\end{document}