How to get last two bits except for LSB from audio signal in MATLAB?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ayesha jabeen
el 4 de Oct. de 2016
Comentada: Walter Roberson
el 9 de Oct. de 2016
i have a code in which i am getting LSB values of audio signal now i am want to get last two bits except for LSB..Here is code:
fid1=fopen('ash.wav','r');
header=fread(fid1,40,'uint8=>char');
data_size=fread(fid1,1,'uint32');
[dta,count]=fread(fid1,inf,'uint16');
fclose(fid1);
lsb=1;
identity=[1 0 1 0 1 0 1 0]';
dta(index)=bitset(dta(index),lsb,identity(1:8));
dta(index)=bitset(dta(index),lsb,m_bin(1:10));
index=([indices(19):indices(28)]);
dta(index)=bitset(dta(index),lsb,n_bin(1:10));
index=([indices(29):indices(28+len)]);
dta(index)=bitset(dta(index),lsb,msg_bin(1:len)');
how to do it?
2 comentarios
michael
el 4 de Oct. de 2016
Please write the complete code in a code format, so that it would be readable
ayesha jabeen
el 5 de Oct. de 2016
Editada: Walter Roberson
el 5 de Oct. de 2016
Respuesta aceptada
Walter Roberson
el 5 de Oct. de 2016
bitset(YourArray, bitset(YourArray, 2, NewBit2Array), 3, NewBit3Array)
3 comentarios
Walter Roberson
el 5 de Oct. de 2016
Those arrays should be the same size as YourArray, and they should hold the new value to go into bit 2 for each corresponding location, and the new value to go into bit 3 for each corresponding location.
If you are only changing a single location, you still need to use the two bitset() calls. bitset() is not able on its own to realize that you want to change multiple bits in a single location, so you need to call it once for each bit position to be changed at the location.
Walter Roberson
el 9 de Oct. de 2016
Opps, should be
bitset(bitset(YourArray, 2, NewBit2Array), 3, NewBit3Array)
Más respuestas (1)
Geoff Hayes
el 4 de Oct. de 2016
ayesha - if
lsb=1;
and
dta(index)=bitset(dta(index),lsb,msg_bin(1:len)');
sets the least significant bit (lsb), then to set the bits before this one, you would just bitshift lsb to the left to modify the two bits prior to lsb. For example,
% bit shift once to to modify the bit prior to lsb
bitToModify = bitshift(lsb, 1);
% bit shift twice to modify the bit that is two away from lsb
bitToModify = bitshift(lsb, 2);
4 comentarios
Walter Roberson
el 6 de Oct. de 2016
Editada: Walter Roberson
el 6 de Oct. de 2016
bitset() returns a value rather than modifying the array in place, so you need to make those into assignments.
Also bitshift(lsb,2) would be 4 rather than 3 so you would not be storing into bits 1, 2, 3, but instead 1, 2, 4. The second parameter should just be a bit number in natural numbers.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!