From 85f2a900039d92402f8fedc9df94054fa1fd15a7 Mon Sep 17 00:00:00 2001 From: pradeep Date: Wed, 22 May 2019 11:06:33 +0530 Subject: [PATCH] Simple fft on complex signal example --- Cargo.toml | 3 +++ examples/fft.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 examples/fft.rs diff --git a/Cargo.toml b/Cargo.toml index e71d72a58..dff0e6647 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,3 +76,6 @@ path = "examples/acoustic_wave.rs" name = "conway" path = "examples/conway.rs" +[[example]] +name = "fft" +path = "examples/fft.rs" diff --git a/examples/fft.rs b/examples/fft.rs new file mode 100644 index 000000000..53d4316ab --- /dev/null +++ b/examples/fft.rs @@ -0,0 +1,35 @@ +use arrayfire::*; +use num::Complex; + +type Complex32 = Complex; + +#[allow(unused_must_use)] +#[allow(unused_variables)] +fn main() { + set_device(0); + info(); + let samples = 10; + let dims = Dim4::new(&[samples, 1, 1, 1]); + + let values = vec![ + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0), + Complex::new(0.0, 2.0) + ]; + + let signal = Array::new(&values, dims); + + af_print!("signal", signal); + + // Used length of input signal as norm_factor + let output = fft(&signal, 0.1, samples as i64); + + af_print!("Output", output); +}