Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TimeSignal
- {
- public float[] x;
- public float[] y;
- public TimeSignal(int N)
- {
- x = new float[N];
- y = new float[N];
- }
- }
- public class LineFFT : MonoBehaviour
- {
- LineRenderer lr;
- TimeSignal signal = new TimeSignal(1000);
- void Start()
- {
- lr = GetComponent<LineRenderer>();
- for(int i = 0; i < 1000; i++)
- {
- //x-values
- signal.x[i] = Mathf.Lerp(0, 100, (float)i / 1000f);
- //y-values
- signal.y[i] = 2 * Mathf.Sin(1 * signal.x[i]) + 1* Mathf.Cos(2 * signal.x[i] + Mathf.PI/4.2f);
- }
- lr.SetPositions(DFT(signal, 3.0f));
- }
- // Update is called once per frame
- void Update()
- {
- lr.SetPositions(DFT(signal, Time.time * 0.25f));
- }
- Vector3[] DFT(TimeSignal X, float k)
- {
- int N = X.x.Length;
- Vector3[] c = new Vector3[N];
- for(int n = 0; n < N; n++)
- {
- c[n] = X.y[n] * new Vector3(
- Mathf.Cos((2 * Mathf.PI) / N * k * n),
- -Mathf.Sin((2 * Mathf.PI) / N * k * n),
- 0);
- }
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement