-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.kt
27 lines (22 loc) · 1.23 KB
/
.kt
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
// Import required libraries and classes
import org.jtransforms.fft.FloatFFT_1D
// Define the input signal to be transformed
val signal = floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f)
// Perform the FFT on the input signal
val fft = FloatFFT_1D(signal.size.toLong())
fft.realForward(signal)
// Print the resulting frequency domain representation of the signal
for (i in signal.indices) {
val magnitude = Math.sqrt(signal[i].toDouble().pow(2.0) + signal[i + 1].toDouble().pow(2.0))
val phase = Math.atan2(signal[i + 1].toDouble(), signal[i].toDouble())
println("Frequency bin $i: Magnitude = $magnitude, Phase = $phase")
}
/*
Explanation:
We first import the required library "org.jtransforms.fft.FloatFFT_1D" for performing the FFT.
We define an input signal to be transformed, which is a simple array of 8 float values.
We create an instance of the "FloatFFT_1D" class with the size of the input signal as a parameter.
We call the "realForward" method of the "FloatFFT_1D" instance to perform the FFT on the input signal.
We loop through the resulting signal and calculate the magnitude and phase of each frequency bin.
We print out the resulting frequency domain representation of the signal, which shows the magnitude and phase of each frequency bin.
*/