Skip to content

Commit

Permalink
Fixed Hamming tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas-Ball committed Sep 13, 2024
1 parent 752392e commit 63f1c76
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 318 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![MIT](https://img.shields.io/github/license/purdue-orbital/SuperDSP)](../master/LICENSE)

# SuperDSP (WIP)

This library is a very work in progress, and the interface currently is subject to changes.
Expand Down
36 changes: 17 additions & 19 deletions examples/bladerf_waterfall/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
// use superdsp::gui::time_chart_complex::TimeChartComplex;
// //use superdsp::gui::waterfall::Waterfall;
// use superdsp::objects::object::DSPObject;
// use superdsp::radios;
//
//
//
// fn main() {
// let mut src = radios::bladerf::src::BladeRfSrc::new(915000000, 1_000_000, 1_000_000, 1_000_000, 1024);
// let mut chart = TimeChartComplex::new();
// //let mut waterfall = Waterfall::new(1024);
//
// let s = src.get_bus();
//
// waterfall.set_bus(s);
// chart.set_bus(s);
//
// superdsp::objects::GUIExecutor::run(vec![Box::new(waterfall), Box::new(chart)], Box::new(src));
// }
use superdsp::gui::time_chart_complex::TimeChartComplex;
use superdsp::gui::waterfall::Waterfall;
use superdsp::objects::object::DSPObject;
use superdsp::radios;

fn main() {
let mut src = radios::bladerf::src::BladeRfSrc::new(915000000, 1_000_000, 1_000_000, 1_000_000, 1024);
let mut chart = TimeChartComplex::new();
let mut waterfall = Waterfall::new();

let s = src.get_bus();

waterfall.set_bus(s);
chart.set_bus(s);

superdsp::objects::GUIExecutor::run(vec![Box::new(waterfall), Box::new(chart)], Box::new(src));
}
2 changes: 1 addition & 1 deletion examples/wave_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use superdsp::objects::wave_gen_time::WaveStepGenTime;
fn main() {
let mut wave_step_gen = WaveStepGenTime::new(440.0, 1.0, 0.0, 44100.0);
let mut chart = TimeChart::new();

let s = wave_step_gen.get_bus();
chart.set_bus(s);

Expand Down
7 changes: 2 additions & 5 deletions examples/wave_generator_complex_waterfall/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#![feature(generic_const_exprs)]

use superdsp::gui::waterfall::Waterfall;
use superdsp::objects::GUIExecutor;
use superdsp::objects::object::DSPObject;
use superdsp::objects::wave_gen_time_complex::WaveStepGenTimeComplex;
use std::thread;

fn main() {
let mut waterfall:Waterfall<256> = Waterfall::new();
let mut gen = WaveStepGenTimeComplex::new(8.0, 1.0, 0.0, 16.0);
let mut waterfall: Waterfall<256> = Waterfall::new();
let mut gen = WaveStepGenTimeComplex::new(200.0, 1.0, 0.0, 441.0);

waterfall.set_bus(gen.get_bus());
GUIExecutor::run(vec![Box::new(waterfall)], Box::new(gen))
Expand Down
8 changes: 4 additions & 4 deletions src/filters_and_windows/hamming.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This function is based on the triangle filter function from wikipedia found here: https://en.wikipedia.org/wiki/Window_function

/// Creates a triangle filter of size N
/// Formula: f(x) = 1 - |((n - o) - (N / 2)) / (L / 2)| for n in 0..N
/// Creates a hamming window of size N
/// Formula: f(x) = (25.0/46.0) - ((1 - (25.0/46.0)) * cos((2*pi*(n - offset))/N)) for n in 0..N
///
/// Where:
/// L can be N, N+1, or N+2
Expand All @@ -14,14 +14,14 @@
///
/// # Returns
/// [f32; N] - Triangle window\
pub fn triangle_window<const N: usize>(l: usize, offset: usize) -> [f32; N] {
pub fn hamming_window<const N: usize>(l: usize, offset: usize) -> [f32; N] {
let mut filter = [0.0; N];

let a_nought: f32 = 25.0/46.0;
let float_large_n: f32 = N as f32;

for n in 0..N {
let float_small_n = n as f32;
let float_small_n = n as f32 - offset as f32;
filter[n] = a_nought - (1.0-a_nought) * libm::cosf((2.0*core::f32::consts::PI*float_small_n)/float_large_n);
}

Expand Down
12 changes: 7 additions & 5 deletions src/filters_and_windows/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// This function is based on the triangle filter function from wikipedia found here: https://en.wikipedia.org/wiki/Window_function

use core::f32::consts::PI;

/// Creates a triangle filter of size N
/// Formula: f(x) = 1 - |((n - o) - (N / 2)) / (L / 2)| for n in 0..N
///
///
/// Where:
/// L can be N, N+1, or N+2
/// o is the bin offset
///
///
/// # Arguments
/// N: usize - Size of the filter
/// l: usize - Filter setting (N, N+1, or N+2)
/// offset: usize - Bin offset
///
///
/// # Returns
/// [f32; N] - Triangle window
pub fn triangle_window<const N: usize>(l: usize, offset: usize) -> [f32; N] {
let mut filter = [0.0; N];

for n in 0..N {
filter[n] = 1.0 - (((n - offset) as f32 - (N as f32 / 2.0)) / (l as f32 / 2.0)).abs();
}

filter
}
Loading

0 comments on commit 63f1c76

Please sign in to comment.