Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goertzel-nostd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
goertzel-nostd
Compare revisions
031692008a59a21afd2b4d5d280c309ef6a268ca to fe41702fd1c285fed71742c02b19857116b17ab1
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
stephen/goertzel-nostd
Select target project
No results found
fe41702fd1c285fed71742c02b19857116b17ab1
Select Git revision
Swap
Target
stephen/goertzel-nostd
Select target project
stephen/goertzel-nostd
1 result
031692008a59a21afd2b4d5d280c309ef6a268ca
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
fix clippy lints
· e57df06e
Stephen D
authored
2 years ago
e57df06e
use iterator for input
· fe41702f
Stephen D
authored
1 year ago
fe41702f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Cargo.toml
+1
-1
1 addition, 1 deletion
Cargo.toml
src/lib.rs
+15
-14
15 additions, 14 deletions
src/lib.rs
with
16 additions
and
15 deletions
Cargo.toml
View file @
fe41702f
[package]
edition
=
"2021"
name
=
"goertzel-nostd"
version
=
"0.
2.1
"
version
=
"0.
3.0
"
authors
=
[
"Stephen D"
]
repository
=
"https://gitlab.scd31.com/stephen/goertzel-nostd"
keywords
=
[
"dsp"
,
"goertzel"
,
"fft"
,
"fourier"
]
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
View file @
fe41702f
...
...
@@ -4,7 +4,7 @@
// allow std in tests
#![cfg_attr(not(test),
no_std)]
use
core
::
f32
::
consts
::
PI
;
use
core
::
{
borrow
::
Borrow
,
f32
::
consts
::
PI
}
;
/// Set up parameters (and some precomputed values for those).
#[derive(Clone,
Copy)]
...
...
@@ -46,23 +46,24 @@ impl Parameters {
}
}
pub
fn
mag
(
self
,
samples
:
&
[
f32
]
)
->
f32
{
pub
fn
mag
<
V
:
Borrow
<
f32
>
,
I
:
Iterator
<
Item
=
V
>>
(
self
,
samples
:
I
)
->
f32
{
self
.start
()
.add_samples
(
samples
)
.finish_mag
()
}
pub
fn
mag_squared
(
self
,
samples
:
&
[
f32
]
)
->
f32
{
pub
fn
mag_squared
<
V
:
Borrow
<
f32
>
,
I
:
Iterator
<
Item
=
V
>>
(
self
,
samples
:
I
)
->
f32
{
self
.start
()
.add_samples
(
samples
)
.finish_mag_squared
()
}
}
impl
Partial
{
pub
fn
add_samples
(
mut
self
,
samples
:
&
[
f32
]
)
->
Self
{
for
&
sample
in
samples
{
let
this
=
self
.params.term_coefficient
*
self
.prev
-
self
.prevprev
+
sample
;
pub
fn
add_samples
<
V
:
Borrow
<
f32
>
,
I
:
Iterator
<
Item
=
V
>>
(
mut
self
,
samples
:
I
)
->
Self
{
for
sample
in
samples
{
let
this
=
self
.params.term_coefficient
*
self
.prev
-
self
.prevprev
+
sample
.borrow
()
;
self
.prevprev
=
self
.prev
;
self
.prev
=
this
;
self
.count
+=
1
;
}
self
.count
+=
samples
.len
();
self
}
pub
fn
finish
(
self
)
->
(
f32
,
f32
)
{
...
...
@@ -85,11 +86,11 @@ impl Partial {
#[test]
fn
zero_data
()
{
let
p
=
Parameters
::
new
(
1800.
,
8000
,
256
);
assert!
(
p
.start
()
.add_samples
(
&
[
0.0
;
256
])
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add_samples
([
0.0
;
256
]
.iter
()
)
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add_samples
(
&
[
0.0
;
128
])
.add_samples
(
&
[
0.0
;
128
])
.add_samples
([
0.0
;
128
]
.iter
()
)
.add_samples
([
0.0
;
128
]
.iter
()
)
.finish_mag
()
==
0.
);
...
...
@@ -107,13 +108,13 @@ fn sine() {
}
let
p
=
Parameters
::
new
(
freq
,
8000
,
8000
);
let
mag
=
p
.start
()
.add_samples
(
&
buf
[
..
])
.finish_mag
();
let
mag
=
p
.start
()
.add_samples
(
buf
[
..
]
.iter
()
)
.finish_mag
();
for
testfreq
in
(
0
..
30
)
.map
(|
x
|
(
x
*
100
)
as
f32
)
{
let
p
=
Parameters
::
new
(
testfreq
,
8000
,
8000
);
let
testmag
=
p
.mag
(
&
buf
[
..
]);
println!
(
"{
:4}: {:12.3}"
,
testfreq
,
testmag
);
let
testmag
=
p
.mag
(
&
buf
[
..
]
.iter
()
);
println!
(
"{testfreq
:4}: {
testmag
:12.3}"
);
if
(
freq
-
testfreq
)
.abs
()
>
100.
{
println!
(
"{} > 10*{
}"
,
mag
,
testmag
);
println!
(
"{
mag
} > 10*{testmag
}"
);
assert!
(
mag
>
10.
*
testmag
);
}
}
...
...
This diff is collapsed.
Click to expand it.