algorithm_rust 0.6.0

some common rust_algorithms, Everyone can participate, and the project will continue to be updated, all the algorithms comes from <Introduction to Algorithms III>
Documentation
use std::ops::{Add, Sub, Mul};
use crate::structure::Complex;

///离散傅立叶变换
/// # Examples
/// ```
///  let signal = vec![0.0, 1.0, 0.0, 1.0]; // Input signal
///	let spectrum = algori::math::dft(&signal);
///
///	for (k, value) in spectrum.iter().enumerate() {
///            println!("Frequency {}: {:?}", k, value);
///	}	
///
/// ```


pub fn DFT<T: Copy + Default + std::convert::From<f64>>(signal: &[T]) -> Vec<Complex<T>> 
where
    T: Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Copy + Into<f64>
{
    let n = signal.len();
    let mut spectrum = vec![Complex::new(T::default(), T::default()); n];

    for k in 0..n {
        let mut sum = Complex::new(T::default(), T::default());
        for t in 0..n {
            let angle = -2.0 * std::f64::consts::PI * k as f64 * t as f64 / n as f64;
            let c = Complex::new(angle.cos().into(), angle.sin().into());
            let value = Complex::new(signal[t], T::default());
            sum = sum + value * c;
        }
        spectrum[k] = sum;
    }

    spectrum
}