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
Commits
2d9a5a5b
Commit
2d9a5a5b
authored
9 years ago
by
Matt McPherrin
Browse files
Options
Downloads
Patches
Plain Diff
Change sample_rate to u32 -- float doesn't make sense there
parent
40edadc6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+3
-2
3 additions, 2 deletions
README.md
src/lib.rs
+5
-5
5 additions, 5 deletions
src/lib.rs
with
8 additions
and
7 deletions
README.md
+
3
−
2
View file @
2d9a5a5b
Goertzel
--------
The Goertzel Algoritm is a simplified discrete fourier transform, useful for
tone detection.
The Goertzel Algoritm is a single-bin discrete fourier transform, useful for
tone detection with a small number of tones. This has not yet been extensively
tested, but appears to basically work.
This diff is collapsed.
Click to expand it.
src/lib.rs
+
5
−
5
View file @
2d9a5a5b
...
...
@@ -22,8 +22,8 @@ pub struct Partial {
}
impl
Parameters
{
pub
fn
new
(
target_freq
:
f32
,
sample_rate
:
f
32
,
window_size
:
usize
)
->
Self
{
let
k
=
target_freq
*
(
window_size
as
f32
)
/
sample_rate
;
pub
fn
new
(
target_freq
:
f32
,
sample_rate
:
u
32
,
window_size
:
usize
)
->
Self
{
let
k
=
target_freq
*
(
window_size
as
f32
)
/
(
sample_rate
as
f32
)
;
let
omega
=
(
f32
::
consts
::
PI
*
2.
*
k
)
/
(
window_size
as
f32
);
let
cosine
=
omega
.cos
();
Parameters
{
...
...
@@ -64,7 +64,7 @@ impl Partial {
#[test]
fn
zero_data
()
{
let
p
=
Parameters
::
new
(
1800.
,
8000
.
,
256
);
let
p
=
Parameters
::
new
(
1800.
,
8000
,
256
);
assert!
(
p
.start
()
.add
(
&
[
0
;
256
])
.finish_mag
()
==
0.
);
assert!
(
p
.start
()
.add
(
&
[
0
;
128
])
.add
(
&
[
0
;
128
])
.finish_mag
()
==
0.
);
}
...
...
@@ -80,10 +80,10 @@ fn sine() {
buf
[
sample
]
=
((
time
*
freq
*
2.
*
PI
)
.sin
()
*
std
::
i16
::
MAX
as
f32
)
as
i16
;
}
let
p
=
Parameters
::
new
(
freq
,
8000
.
,
8000
);
let
p
=
Parameters
::
new
(
freq
,
8000
,
8000
);
let
mag
=
p
.start
()
.add
(
&
buf
[
..
])
.finish_mag
();
for
testfreq
in
(
0
..
30
)
.map
(|
x
|
(
x
*
100
)
as
f32
)
{
let
p
=
Parameters
::
new
(
testfreq
,
8000
.
,
8000
);
let
p
=
Parameters
::
new
(
testfreq
,
8000
,
8000
);
let
testmag
=
p
.start
()
.add
(
&
buf
[
..
])
.finish_mag
();
println!
(
"{:4}: {:12.3}"
,
testfreq
,
testmag
);
if
(
freq
-
testfreq
)
.abs
()
>
100.
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment