I'm gonna rewrite everything : IFFT ISN'T JUST REVERSING THE TERMS RETARD

This commit is contained in:
2025-09-23 21:37:40 +02:00
parent 399d7852ac
commit d191b912b0
7 changed files with 4902 additions and 4839 deletions

View File

@ -1,8 +1,5 @@
use std::{
f32::consts::PI,
fs::File,
io::{Read, Write},
ops::{Add, Div, Mul, Sub},
f32::consts::PI, fs::File, io::{Read, Write}, ops::{Add, Div, Mul, Sub}
};
mod bfsk;
@ -40,8 +37,50 @@ fn euclid_mod(a: f32, m: f32) -> f32 {
let r = a % m;
if r < 0.0 { r + m } else { r }
}
struct QuickLCG(i32);
impl QuickLCG
{
pub fn seed(val: i32) -> QuickLCG
{
QuickLCG(val % 10)
}
pub fn next(&mut self) -> i32
{
self.0 = self.0.overflowing_mul(9321).0.overflowing_add(5672).0 % 10;
self.0
}
}
fn main() {
test();
//test();
simple_test();
}
fn simple_test()
{
let sample_count = 7;
let mut dft = NaiveDFT::create(sample_count);
let mut fft = RaderFFT::create(sample_count);
let mut rand = QuickLCG::seed(2981237);
for (a, b) in dft.get_input().iter_mut().zip(fft.get_input().iter_mut())
{
let re = (rand.next() - 5) as f32;
let im = (rand.next() - 5) as f32;
*a = Complex32::new(re, im);
*b = Complex32::new(re, im);
}
dft.execute(windows::rectanguar);
fft.execute(windows::rectanguar);
for (a, b) in dft.get_output().iter().zip(fft.get_output().iter())
{
println!("{:0<7.3} {:0<7.3} \t {:0<7.3} {:0<7.3}", a.re, a.im, b.re, b.im);
}
}
fn test() {
@ -51,23 +90,25 @@ fn test() {
//let sample_count = 71*71;
//let sample_count = 71 * 71;
//let sample_count = 4804;
let sample_count = 4799;
let sample_count = 4809;
let mut o1 = Nco::new(freq1);
let mut o2 = Nco::new(freq2);
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();
//let mut fft = ::create(sample_count);
//let mut dft = MixedRadixFFT::create(sample_count);
let mut fft = create_fft(sample_count);
//let mut dft = create_fft(sample_count);
for x in fft.get_input().iter_mut() {
*x = o1.cexp() + o2.cexp();
//*y = *x;
o1.step();
o2.step();
}
//fft.execute(windows::rectanguar);
dft.execute(windows::rectanguar);
fft.execute(windows::rectanguar);
//dft.execute(windows::rectanguar);
let root = BitMapBackend::new("out.png", (640, 480)).into_drawing_area();
root.fill(&WHITE).unwrap();
@ -81,20 +122,22 @@ fn test() {
//chart.configure_mesh().draw()?;
/*
chart
.draw_series(LineSeries::new(
(0..sample_count)
.zip(dft.get_output().iter())
.map(|(x, y)| (x as f32, (*y).arg() * (*y).mag())),
.map(|(x, y)| (x as f32, (*y).arg() )),
&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())
.zip(fft.get_output().iter())
.map(|(x, y)| (x as f32, (*y).mag() / sample_count as f32)),
&BLUE,
))
@ -109,6 +152,15 @@ fn test() {
.unwrap();
root.present().unwrap();
let mut f = File::create("out.csv").unwrap();
for x in fft.get_output().iter()
{
f.write_all(
format!("{},\n", x.mag() / sample_count as f32).to_string().as_bytes()
).unwrap();
}
}
fn modulate() {