How to get last two bits except for LSB from audio signal in MATLAB?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2016-10-5
bitset(YourArray, bitset(YourArray, 2, NewBit2Array), 3, NewBit3Array)
3 个评论
Walter Roberson
2016-10-5
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
2016-10-9
Opps, should be
bitset(bitset(YourArray, 2, NewBit2Array), 3, NewBit3Array)
更多回答(1 个)
Geoff Hayes
2016-10-4
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 个评论
Walter Roberson
2016-10-6
编辑:Walter Roberson
2016-10-6
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Code Generation and Deployment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!