Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
su
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
dmeiss2s
su
Commits
d8298244
Commit
d8298244
authored
9 years ago
by
Daniel Meißner
Committed by
Daniel Meißner
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
scripts: added script that can detect noise floor
parent
b776eba7
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
gr_grc/scripts/detect_noise_flore.py
+107
-0
107 additions, 0 deletions
gr_grc/scripts/detect_noise_flore.py
gr_grc/scripts/dump_to_signal_blocks.py
+10
-5
10 additions, 5 deletions
gr_grc/scripts/dump_to_signal_blocks.py
with
117 additions
and
5 deletions
gr_grc/scripts/detect_noise_flore.py
0 → 100644
+
107
−
0
View file @
d8298244
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import
sys
import
numpy
as
np
from
gnuradio
import
blocks
from
gnuradio
import
gr
class
top_block
(
gr
.
top_block
):
def
__init__
(
self
,
samp_rate
=
2e6
,
file_path
=
sys
.
argv
[
1
],
measure_time
=
sys
.
argv
[
2
]):
gr
.
top_block
.
__init__
(
self
,
"
Top Block
"
)
##################################################
# Variables
##################################################
self
.
samp_rate
=
samp_rate
# Queue
self
.
msgq_out
=
blocks_message_sink_0_msgq_out
=
gr
.
msg_queue
(
0
)
##################################################
# Blocks
##################################################
self
.
blocks_head_0
=
blocks
.
head
(
gr
.
sizeof_gr_complex
*
1
,
int
(
samp_rate
)
*
int
(
measure_time
))
self
.
blocks_throttle_0
=
blocks
.
throttle
(
gr
.
sizeof_gr_complex
*
1
,
\
10
*
samp_rate
,
\
True
)
self
.
blocks_message_sink_0
=
blocks
.
message_sink
(
gr
.
sizeof_float
*
1
,
\
blocks_message_sink_0_msgq_out
,
\
False
)
self
.
blocks_file_source_0
=
blocks
.
file_source
(
gr
.
sizeof_gr_complex
*
1
,
\
str
(
file_path
),
\
False
)
self
.
blocks_complex_to_mag_squared_0
=
blocks
.
complex_to_mag_squared
(
1
)
##################################################
# Connections
##################################################
self
.
connect
((
self
.
blocks_file_source_0
,
0
),
(
self
.
blocks_throttle_0
,
0
))
self
.
connect
((
self
.
blocks_throttle_0
,
0
),
(
self
.
blocks_head_0
,
0
))
self
.
connect
((
self
.
blocks_head_0
,
0
),
(
self
.
blocks_complex_to_mag_squared_0
,
0
))
self
.
connect
((
self
.
blocks_complex_to_mag_squared_0
,
0
),
\
(
self
.
blocks_message_sink_0
,
0
))
def
get_samp_rate
(
self
):
return
self
.
samp_rate
def
set_samp_rate
(
self
,
samp_rate
):
self
.
samp_rate
=
samp_rate
self
.
blocks_throttle_0
.
set_sample_rate
(
self
.
samp_rate
)
def
main
(
top_block_cls
=
top_block
,
options
=
None
):
"""
Examples:
1. USRP spectrum sense /usr/share/gnuradio/examples/uhd/usrp_spectrum_sense.py
"""
tb
=
top_block_cls
()
tb
.
start
()
samples_count
=
0
samples_average
=
np
.
empty
(
0
,
dtype
=
'
float32
'
)
samples_median
=
np
.
empty
(
0
,
dtype
=
'
float32
'
)
samples_std
=
np
.
empty
(
0
,
dtype
=
'
float32
'
)
minimum
=
999999999.9
maximum
=
0.0
while
True
:
# pull from message queue
msg
=
tb
.
msgq_out
.
delete_head
()
msg_string
=
msg
.
to_string
()
# convert string with floats into an numpy array
samples
=
np
.
fromstring
(
msg_string
,
dtype
=
'
float32
'
)
samples_average
=
np
.
append
(
samples_average
,
np
.
average
(
samples
))
samples_median
=
np
.
append
(
samples_median
,
np
.
median
(
samples
))
samples_std
=
np
.
append
(
samples_std
,
np
.
std
(
samples
))
mi
=
np
.
amin
(
samples
)
ma
=
np
.
amax
(
samples
)
if
mi
<
minimum
:
minimum
=
mi
if
ma
>
maximum
:
maximum
=
ma
samples_count
+=
len
(
samples
)
if
samples_count
>=
int
(
sys
.
argv
[
2
])
*
2e6
:
break
print
(
"
\n
Processed %s samples!
\n
"
%
(
3
*
int
(
2e6
)))
print
(
"
min: %s
"
%
minimum
)
print
(
"
max: %s
\n
"
%
maximum
)
print
(
"
average: %s
"
%
np
.
average
(
samples_average
))
print
(
"
median: %s
"
%
np
.
median
(
samples_median
))
print
(
"
standard diviation: %s
"
%
np
.
std
(
samples_std
))
if
__name__
==
'
__main__
'
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
gr_grc/scripts/
count_zero
s.py
→
gr_grc/scripts/
dump_to_signal_block
s.py
100755 → 100644
+
10
−
5
View file @
d8298244
...
...
@@ -27,7 +27,12 @@ class top_block(gr.top_block):
self
.
blocks_throttle_0
=
blocks
.
throttle
(
gr
.
sizeof_gr_complex
*
1
,
\
10
*
samp_rate
,
\
True
)
self
.
blocks_threshold_ff_0
=
blocks
.
threshold_ff
(
0.0006
,
0.0006
,
0
)
#self.threshold = 0.0006
# 0.0000317
# 0.00031
self
.
threshold
=
3.17382e-05
*
2
self
.
blocks_threshold_ff_0
=
blocks
.
threshold_ff
(
self
.
threshold
,
self
.
threshold
)
self
.
blocks_message_sink_0
=
blocks
.
message_sink
(
gr
.
sizeof_float
*
1
,
\
blocks_message_sink_0_msgq_out
,
\
False
)
...
...
@@ -98,7 +103,7 @@ def main(top_block_cls=top_block, options=None):
count_zero
+=
np
.
count_nonzero
(
samples
!=
1.0
)
# Section 5
if
ones
>
0
:
if
ones
>
0
and
np
.
count_nonzero
(
samples
)
>
150
:
# skip first message queue sample
if
len
(
arrays_with_ones
)
==
0
:
hash
=
{}
...
...
@@ -111,10 +116,10 @@ def main(top_block_cls=top_block, options=None):
if
(
last_recorded_samples
[
'
count_before_array
'
]
+
\
len
(
last_recorded_samples
[
'
samples
'
]))
==
samples_sum
:
print
(
"
ones in block: %s samples: %s
"
%
(
np
.
count_nonzero
(
samples
),
len
(
samples
)))
for
sample
in
samples
:
arrays_with_ones
[
-
1
][
'
samples
'
]
=
np
.
append
(
\
arrays_with_ones
[
-
1
][
'
samples
'
],
sample
\
)
arrays_with_ones
[
-
1
][
'
samples
'
]
=
np
.
append
\
(
arrays_with_ones
[
-
1
][
'
samples
'
],
sample
)
else
:
hash
=
{}
...
...
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