The DFT function below works fine but I want to use the list, generated from that function, in the Update function.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FFT : MonoBehaviour
{
public ArrayList amp = new ArrayList();
public ArrayList freq = new ArrayList();
void DFT()
{
float[] X = {1, 2, 3};
float[] Y = {2, 3, 5};
float N = X.Length;
for(int k = 0; k < N; k++)
{
float re = 0;
float im = 0;
for(int n = 0; n < N; n++)
{
float phi = (2 * Mathf.PI * k * n) / N;
re += X[n] * Mathf.Cos(phi) + Y[n] * Mathf.Sin(phi);
im += Y[n] * Mathf.Cos(phi) - X[n] * Mathf.Sin(phi);
}
var freqq = k;
var ampp = Mathf.Sqrt(re*re + im*im);
var phasse = Mathf.Atan2(re, im);
phase.Add(phasse);
amp.Add(ampp);
freq.Add(freqq);
}
}
}
I want to use the lists elements in another function (for example in Update)
void Update()
{
for(var i = 0; i < 2; ++i)
{
var x = amp[i] * Mathf.Cos(freq[i]);
var y = amp[i] * Mathf.Sin(freq[i]);
var pos = new Vector3(x, y, 0);
//Debug.Log(pos);
}
}
The problem is that amp[i]
and freq[i]
doesn't work in another function.