How to perform OOK modulation on Audio signal?
Show older comments
I have to convert my Audio signal in to discrete form and have to perform OOK modulation on it.
Answers (1)
Walter Roberson
on 21 Jun 2018
0 votes
6 Comments
Asra Khalid
on 22 Jun 2018
Walter Roberson
on 22 Jun 2018
Use the 'native' option of wavread() so that you get integer values instead of floating point. Convert the integers to binary by using de2bi() or by using dec2bin() and then subtracting '0' (the character corresponding to the digit 0)
Asra Khalid
on 26 Jun 2018
Walter Roberson
on 26 Jun 2018
You do not make any changes to the OOK code itself. You make changes to how you read the data to be sent by OOK, and how you deal with the received data.
signal = waveread('YourFile.mp3', 'native');
sigbin = reshape( (dec2bin(signal(:,1), 8) - '0').', 1, []);
Now sigbin is a binary signal that you transmit using OOK or other method. OOK does not care where the data came from or what it "means".
On the other side, as you receive the signal, take every group of 8 bits and
byte = sum(group_of_8 .* 2.^(7:-1:0))
and add it to the output array or play it or whatever.
Asra Khalid
on 26 Jun 2018
Edited: Walter Roberson
on 26 Jun 2018
Walter Roberson
on 26 Jun 2018
signal(:,1) is the first channel of the input signal.
dec2bin(something, 8) converts the input to character-coded binary with a minimum of 8 bits. 8 is specified because it could happen that the range of input values took less than 8 bits and we need a constant output width for the rest to work.
Subtracting the character '0' from the dec2bin() result converts each '0' to 0 and '1' to 1, thereby converting from character-coded binary to numeric binary.
dec2bin creates output in which the bits for any one input are across the rows. We want to take that output and make a single row vector in which the bits for any one input are beside each other. We start by transposing so that the bits for one output go down the columns, so 8 rows by however many columns are needed. With that memory arrangement, we can now reshape to 1 row and as many columns are needed.
a7 a6 a5 a4 a3 a2 a1 a0
b7 b6 a5 b4 b3 b2 b1 b0
->
a7 b7
a6 b6
a5 b5
a4 b4
a3 b3
a2 b2
a1 b1
a0 b0
->
a7 a6 a5 a4 a3 a2 a1 a0 b7 b6 b5 b4 b3 b2 b1 b0
The reconstruction formula I gave takes a single group of 8 numeric bits like a7 a6 a5 a4 a3 a2 a1 a0 and constructs the numeric vector 2^(7:-1:0) which is 2^[7 6 5 4 3 2 1 0] which is [128 64 32 16 8 4 2 1] . It multiplies the a7 a6 a5 a4 a3 a2 a1 a0 by that, getting a7*128 a6*64 a5*32 a4*16 a3*8 a2*4 a1*2 a0*1 . Then it adds those getting a7*128+a6*64+a5*32+a4*16+a3*8+a2*4+ a1*2+a0*1 . Which is precisely the numeric integer reconstruction of the binary sequence a7 a6 a5 a4 a3 a2 a1 a0, by definition.
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!