-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfourier.lua
More file actions
25 lines (20 loc) · 731 Bytes
/
fourier.lua
File metadata and controls
25 lines (20 loc) · 731 Bytes
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
---@diagnostic disable: need-check-nil
local Fourier = require "Fourier"
local signal = {}
local time = {}
local harmonic = 30
-- testing sawtooth wave
local frequency = 1
for i = 1, 1000 do
time[i] = (i - 1) * 0.001 -- time array (0.001 second intervals)
signal[i] = Fourier:saw(i, frequency, time[i])
end
-- Decompose the signal into Fourier coefficients
local coeffs = Fourier:decompose(signal, harmonic, frequency, time)
local file = io.open("wave.dat", "w")
-- Recompose the signal from the coefficients
local recomposeSignal = {}
for i, ti in ipairs(time) do
recomposeSignal[i] = Fourier:recompose(coeffs, frequency, ti)
file:write(string.format("%f\t %f\t %f\n", ti, signal[i], recomposeSignal[i]))
end