Still not working
This commit is contained in:
66
src/main.rs
66
src/main.rs
@ -15,13 +15,11 @@ use complex::Complex;
|
||||
use complex::Complex32;
|
||||
use fft::rader;
|
||||
use nco::Nco;
|
||||
use plotters::prelude::*;
|
||||
|
||||
|
||||
use crate::fft::{
|
||||
DFT, create_fft,
|
||||
dft::NaiveDFT,
|
||||
mixed_radix::MixedRadixFFT,
|
||||
rader::{RaderFFT, compute_prime_primitive_root, exp_mod},
|
||||
radix2::Radix2FFT,
|
||||
create_fft, dft::NaiveDFT, mixed_radix::MixedRadixFFT, prime_factors, rader::{compute_prime_primitive_root, exp_mod, RaderFFT}, radix2::Radix2FFT, DFT
|
||||
};
|
||||
|
||||
// Utilities
|
||||
@ -44,42 +42,50 @@ fn test() {
|
||||
let freq1 = 2. * PI / 4.0;
|
||||
let freq2 = 2. * PI / 8.0;
|
||||
|
||||
let sample_count = 4799;
|
||||
//let sample_count = 71*71;
|
||||
//let sample_count = 71*71;
|
||||
let sample_count = 4800;
|
||||
|
||||
let mut o1 = Nco::new(freq1);
|
||||
let mut o2 = Nco::new(freq2);
|
||||
|
||||
|
||||
let mut fft = RaderFFT::create(sample_count);
|
||||
//let mut dft = NaiveDFT::create(sample_count);
|
||||
let vals = fft.get_input();
|
||||
//let vals_dft = dft.get_input();
|
||||
for x in vals.iter_mut() {
|
||||
let mut fft = create_fft(sample_count);
|
||||
//let mut fft = create_fft(sample_count);
|
||||
for x in fft.get_input().iter_mut() {
|
||||
*x = o1.cexp() + o2.cexp();
|
||||
//*y = *x;
|
||||
//*x = o2.cexp(); //+ o2.cexp();
|
||||
//*x = *x * (1. / x.mag());
|
||||
|
||||
o1.step();
|
||||
o2.step();
|
||||
}
|
||||
|
||||
fft.execute();
|
||||
//dft.execute();
|
||||
let output = fft.get_output();
|
||||
|
||||
let mut f = File::create("out.csv").unwrap();
|
||||
for (i, v) in output.iter().enumerate() {
|
||||
f.write_all(
|
||||
format!(
|
||||
"{},{},\n",
|
||||
i as f32 / sample_count as f32,
|
||||
v.mag(),
|
||||
//v2.mag()
|
||||
)
|
||||
.to_string()
|
||||
.as_bytes(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let root = BitMapBackend::new("out.png", (640, 480)).into_drawing_area();
|
||||
root.fill(&WHITE).unwrap();
|
||||
let mut chart = ChartBuilder::on(&root)
|
||||
.caption("fft", ("sans-serif", 50).into_font())
|
||||
.margin(5)
|
||||
.x_label_area_size(30)
|
||||
.y_label_area_size(30)
|
||||
.build_cartesian_2d(0f32..(sample_count as f32), 0f32..(sample_count as f32)).unwrap();
|
||||
|
||||
//chart.configure_mesh().draw()?;
|
||||
|
||||
chart
|
||||
.draw_series(LineSeries::new(
|
||||
(0..sample_count).zip(fft.get_output().iter()).map(|(x, y)| (x as f32, y.mag())),
|
||||
&RED,
|
||||
)).unwrap()
|
||||
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));
|
||||
|
||||
chart
|
||||
.configure_series_labels()
|
||||
.background_style(&WHITE.mix(0.8))
|
||||
.border_style(&BLACK)
|
||||
.draw().unwrap();
|
||||
|
||||
root.present().unwrap();
|
||||
}
|
||||
|
||||
fn modulate() {
|
||||
|
||||
Reference in New Issue
Block a user