end
# ╔═╡ 5cde4c70-eaa4-11ea-214c-633b65f18a18
-md"# Week 3 & 4 - Fourier analysis"
+md"# DFT"
# ╔═╡ 78adff50-ed5a-11ea-3c3a-cf4de58dce71
md"""
Produces an **N-point** signal in the frequency domain
"""
-# ╔═╡ 0f4abce0-ed34-11ea-2245-0590b879023f
+# ╔═╡ b81dfe60-f688-11ea-06d0-7158c35b3a5e
begin
+ # 'x' is a discrete function where values are x[0], x[1], etc.
+ # 'k' is the nth coefficient to compute.
+ # 'N' is the number of values in 'x'.
analysis(x, k, N) = sum(x(n) * exp(-im * 2π / N * n * k) for n ∈ 0:N-1)
- synthesis(X, n, N) = 1 / N * sum(X(k) * exp(im * 2π / N * n * k) for k ∈ 0:N-1)
+ # 'X' is the discret fourier transform result where values are X[0], X[1], etc.
+ # 'n' is the nth point to compute.
+ # 'N' is the number of values in 'X'.
+ synthesis(X, n, N) = 1 / N * sum(X(k) * exp(im * 2π / N * n * k) for k ∈ 0:N-1)
+end
+
+# ╔═╡ 875262d0-f688-11ea-0677-07825a60c6c5
+md"## Example
+
+$f(n) = sin(n \cdot 2π / 100) + sin(10 \cdot n \cdot 2π / 100 + π / 4)$
+"
+
+# ╔═╡ 0f4abce0-ed34-11ea-2245-0590b879023f
+begin
# Input signal 'f'.
f(n) = sin(n * 2π / 100) + 0.2 * sin(10 * n * 2π / 100 + π / 4)
# ╔═╡ e0ae4d60-f054-11ea-249c-41c05d1b7cf7
md"## Example of a linear signal"
+# ╔═╡ b186e30e-f682-11ea-1936-47067564c826
+md"# 1.4.1 DFS - Discrete Fourier series
+
+DFS is a DFT with periodicity explicit.
+"
+
# ╔═╡ 1e4174f0-ed34-11ea-0c3a-69ad2f7d6561
let
N = 32
f(n) = x[(n % N) + 1]
points_in_freq_domain = [analysis(f, k, N) for k ∈ 0:N-1]
- plot_signal = scatter(x, label = false, title = "Time domain", )
- plot_fft = scatter(0:N-1, points_in_freq_domain .|> norm, label = false, title = "Frequency domain: F(n): Magnitude")
- plot(plot_signal, plot_fft, layout = (2, 1))
+ plot_signal = scatter(x, label = false, title = "Time domain for one period", )
+ plot_fft = scatter(0:N-1, points_in_freq_domain .|> norm, label = false, title = "Frequency domain for one period: F(n): Magnitude")
+
+ points_in_freq_domain_2_periods = [analysis(f, k, 2N) for k ∈ 0:2N-1]
+ plot_signal_2_periods = scatter([x; x], label = false, title = "Time domain for two periods", )
+ plot_fft_2_periods = scatter(0:2N-1, points_in_freq_domain_2_periods .|> norm, label = false, title = "Frequency domain for two periods: F(n): Magnitude")
+
+ plot(plot_signal, plot_fft, plot_signal_2_periods, plot_fft_2_periods, layout = (4, 1), size = (800, 800))
end
+# ╔═╡ 4acf4260-f68d-11ea-1cc5-c15a74776107
+md"Here the coefficient at position 0 is 0 because the signal is centered around 0 (mean = 0)."
+
+# ╔═╡ 23291580-f690-11ea-24eb-3d95ce599f42
+md"# 1.4.2 DTFT - Discrete-Time Fourier Transform"
+
# ╔═╡ 4d5cabe2-f06a-11ea-349f-6f940c85692e
md"## Example of exponation decaying sequence"
α = 0.9
f(n) = if n < 0 0 else α^n end
scatter(-5:40, f)
+
end
# ╔═╡ Cell order:
# ╠═5bd37650-e579-11ea-354b-65f651b7fc69
# ╟─5cde4c70-eaa4-11ea-214c-633b65f18a18
# ╟─78adff50-ed5a-11ea-3c3a-cf4de58dce71
+# ╠═b81dfe60-f688-11ea-06d0-7158c35b3a5e
+# ╟─875262d0-f688-11ea-0677-07825a60c6c5
# ╠═0f4abce0-ed34-11ea-2245-0590b879023f
-# â\95 â\95\9010a85110-ed34-11ea-36ff-175bceac4be1
-# â\95 â\95\901609ba40-ed34-11ea-29d2-41e5742df891
-# â\95 â\95\901915e8d0-ed34-11ea-37b7-2f4938bcf27e
-# â\95 â\95\9020bb8390-ed5e-11ea-2415-cbc53e60cc0a
+# â\95\9fâ\94\8010a85110-ed34-11ea-36ff-175bceac4be1
+# â\95\9fâ\94\801609ba40-ed34-11ea-29d2-41e5742df891
+# â\95\9fâ\94\801915e8d0-ed34-11ea-37b7-2f4938bcf27e
+# â\95\9fâ\94\8020bb8390-ed5e-11ea-2415-cbc53e60cc0a
# ╟─0f318a60-efb7-11ea-0416-3ded1c40b27a
-# â\95 â\95\901badaab0-ed34-11ea-2709-df7b90e4e6a6
+# â\95\9fâ\94\801badaab0-ed34-11ea-2709-df7b90e4e6a6
# ╟─e0ae4d60-f054-11ea-249c-41c05d1b7cf7
+# ╟─b186e30e-f682-11ea-1936-47067564c826
# ╠═1e4174f0-ed34-11ea-0c3a-69ad2f7d6561
+# ╟─4acf4260-f68d-11ea-1cc5-c15a74776107
+# ╟─23291580-f690-11ea-24eb-3d95ce599f42
# ╟─4d5cabe2-f06a-11ea-349f-6f940c85692e
# ╠═3dac19b0-f06a-11ea-34ee-291908925549