Redo rader

This commit is contained in:
2025-09-23 19:35:49 +02:00
parent a300386f7f
commit 399d7852ac
10 changed files with 313 additions and 82 deletions

View File

@ -17,9 +17,15 @@ use fft::rader;
use nco::Nco;
use plotters::prelude::*;
use crate::fft::{
create_fft, dft::NaiveDFT, mixed_radix::MixedRadixFFT, prime_factors, rader::{compute_prime_primitive_root, exp_mod, RaderFFT}, radix2::Radix2FFT, DFT
DFT, create_fft,
dft::NaiveDFT,
mixed_radix::MixedRadixFFT,
prime_factors,
rader::{RaderFFT, compute_prime_primitive_root, exp_mod},
rader2::{Rader2FFT, next_pow2},
radix2::Radix2FFT,
windows,
};
// Utilities
@ -43,23 +49,25 @@ fn test() {
let freq2 = 2. * PI / 8.0;
//let sample_count = 71*71;
//let sample_count = 71*71;
let sample_count = 4800;
//let sample_count = 71 * 71;
//let sample_count = 4804;
let sample_count = 4799;
let mut o1 = Nco::new(freq1);
let mut o2 = Nco::new(freq2);
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();
let mut fft = RaderFFT::create(sample_count);
let mut dft = RaderFFT::create(sample_count);
for (x, y) in fft.get_input().iter_mut().zip(dft.get_input().iter_mut()) {
*y = o1.cexp();// + o2.cexp();
//*y = *x;
o1.step();
o2.step();
}
fft.execute();
//fft.execute(windows::rectanguar);
dft.execute(windows::rectanguar);
let root = BitMapBackend::new("out.png", (640, 480)).into_drawing_area();
root.fill(&WHITE).unwrap();
@ -68,22 +76,37 @@ fn test() {
.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();
.build_cartesian_2d(0f32..(sample_count as f32), -PI..PI)
.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())),
(0..sample_count)
.zip(dft.get_output().iter())
.map(|(x, y)| (x as f32, (*y).arg() * (*y).mag())),
&RED,
)).unwrap()
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));
))
.unwrap()
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], RED));
chart
.draw_series(LineSeries::new(
(0..sample_count)
.zip(dft.get_output().iter())
.map(|(x, y)| (x as f32, (*y).mag() / sample_count as f32)),
&BLUE,
))
.unwrap()
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], BLUE));
chart
.configure_series_labels()
.background_style(&WHITE.mix(0.8))
.border_style(&BLACK)
.draw().unwrap();
.draw()
.unwrap();
root.present().unwrap();
}