Skip to content

Commit

Permalink
blocks/sources/hackrf: fix 8-bit unsigned to float sample conversion
Browse files Browse the repository at this point in the history
this block presumed HackRF samples were encoded as unsigned 8-bit
values, with negative values from 0 - 127, zero at 128, and positive
values from 129 to 255, but the samples are actually signed 8-bit values
in two's complement representation.
  • Loading branch information
vsergeev committed Aug 31, 2016
1 parent 25d6486 commit e36c0f1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions radio/blocks/sources/hackrf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ local function read_callback_factory(...)
-- Resize output vector
out:resize(transfer.valid_length/2)

-- Convert complex u8 in buf to complex floats in output vector
-- Convert complex s8 in buf to complex floats in output vector
for i = 0, out.length-1 do
out.data[i].real = (transfer.buffer[2*i] - 127.5) * (1/127.5)
out.data[i].imag = (transfer.buffer[2*i+1] - 127.5) * (1/127.5)
out.data[i].real = ffi.cast("int8_t *", transfer.buffer)[2*i] * (1/127.5)
out.data[i].imag = ffi.cast("int8_t *", transfer.buffer)[2*i+1] * (1/127.5)
end

-- Write to each output fd
Expand Down

0 comments on commit e36c0f1

Please sign in to comment.