Skip to content

Commit

Permalink
added subdivisions, added a pause key, expanded README
Browse files Browse the repository at this point in the history
  • Loading branch information
Stvff committed Jul 3, 2023
1 parent 7e22b8b commit 27977d1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# waterfall
A waterfall spectrum analyzer for the ADALM-PLUTO, written in Odin, using fenster and libiio. Only on X11 (for now?).
A waterfall spectrum analyzer for the ADALM-PLUTO SDR, written in Odin, using fenster and libiio. Only on X11 (for now?).
This is a project that was made for the University of Twente First year's Electrical Engineering Wireless transmission project of 2023.

## Dependencies
X11 (so basically, Linux), [Odin](https://github.com/odin-lang/Odin), [libiio](https://github.com/analogdevicesinc/libiio), bash
Linux, X11, [Odin](https://github.com/odin-lang/Odin), [libiio](https://github.com/analogdevicesinc/libiio), bash, gcc

## Building and running
First you build it:\
`$ ./make.sh`\
Then you can run it:\
Then, connect the ADALM-PLUTO to your pc.\
Now you can run it:\
`$ ./waterfall`\
It should bring up the window. Running it in the terminal is highly recommended.
It should bring up the window.

## Usage
The middle of the screen is the '0-frequency' of the complex fourier transform. Pressing the up-and-down arrow keys changes the frequency that the ADALM 'focuses' on.
How to actually interpret that is unclear, but I suspect it changes the center frequency as well.
Pressing the up-and-down arrow keys changes the frequency that the ADALM-PLUTO 'focuses' on, and with it, the center frequency.\
The center frequency is at the middle of the screen.

## Details
It starts at 100MHz, a sampling rate of 60MHz (whatever that entails exactly), and an FFT bin size of 1024.\
It starts at 100MHz, a sampling rate of 60MHz (whatever that entails exactly), and an FFT bin size of 1024. Every frame is normalized, so if there's no one loud signal, you will see a lot of noise.\
In this repo, there are functions for reading and writing .WAV files, which can be implemented quite easily.\
There is currently a memory leak and more wierdness going on with closing the device and destroying the buffer. I am not sure why it won't destroy the buffer properly.
54 changes: 43 additions & 11 deletions main.odin
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import "wav"
import "iio"

main :: proc() {
level :: uint(10)
bin_size :: 1 << level
level := uint(10)
bin_size := uint(1 << level)
sample_rate :: 60_000_000
focus_freq := 100_000_000
history_size :: 800

info := iio.prep_and_get_device(iio.STANDARD_IP, focus_freq, sample_rate, bin_size)
info := iio.prep_and_get_device(iio.STANDARD_IP, focus_freq, sample_rate, int(bin_size))
if !info.success do return
// defer iio.undo_device(&info)

Expand Down Expand Up @@ -43,9 +43,11 @@ main :: proc() {
delete(freqs_buffer)
}

was_pressed := false
arrow_was_pressed := false
space_was_pressed := false
paused := false
for !fenster.loop(fen) {
for y := fen.height - 1; y > 0 ; y -= 1 {
if !paused do for y := fen.height - 1; y > 0 ; y -= 1 {
this_line := scr_buf[fen.width*y : fen.width*(y+1)]
next_line := scr_buf[fen.width*(y-1) : fen.width*y]
copy(this_line, next_line)
Expand All @@ -61,30 +63,60 @@ main :: proc() {
}
}

pressed := false
/* coloured subdivisions */
{
for k: uint = bin_size >> 2; k < bin_size; k += (bin_size >> 2){
x := int(k)
y := history_size - 20
fen.buf[x + int(fen.width)*y] = fenster.RED
}
for k: uint = bin_size >> 3; k < bin_size; k += (bin_size >> 2){
x := int(k)
y := history_size - 10
fen.buf[x + int(fen.width)*y] = fenster.RED
}
for k: uint = bin_size >> 4; k < bin_size; k += (bin_size >> 3){
x := int(k)
y := history_size - 5
fen.buf[x + int(fen.width)*y] = fenster.BLUE
}
for k: uint = bin_size >> 5; k < bin_size; k += (bin_size >> 4){
x := int(k)
y := history_size - 5
fen.buf[x + int(fen.width)*y] = fenster.GREEN
}
}

arrow_pressed := false
space_pressed := false
freq_jump := 0
if fen.keys[ARROW_KEY.UP] {
pressed = true
arrow_pressed = true
freq_jump = 10_000_000
}
if fen.keys[ARROW_KEY.DOWN] {
pressed = true
arrow_pressed = true
freq_jump = -10_000_000
}
if fen.keys[SPACE_KEY] {
space_pressed = true
}
if space_pressed && !space_was_pressed do paused = !paused

if pressed && !was_pressed {
if arrow_pressed && !arrow_was_pressed {
focus_freq += freq_jump
fmt.printf("new center frequency: %d MHz...", focus_freq/1_000_000)
// iio.undo_device(&info) /* this crashes, so it's commented out for now, even though it leaks memory */
info := iio.prep_and_get_device(iio.STANDARD_IP, focus_freq, sample_rate, bin_size)
info := iio.prep_and_get_device(iio.STANDARD_IP, focus_freq, sample_rate, int(bin_size))
if !info.success {
fmt.printf(" failed :(\n")
return
}
fmt.printf(" success!\n")
}

was_pressed = pressed
arrow_was_pressed = arrow_pressed
space_was_pressed = space_pressed

if fen.keys[ESC_KEY] || fen.keys['Q'] do break
}
Expand Down
2 changes: 2 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set -e

(cd iio; bash make_lib.sh)
(cd fenster; bash make_lib.sh)

Expand Down

0 comments on commit 27977d1

Please sign in to comment.