Creating a Array of binary values
显示 更早的评论
I'm trying to do the quantization of a wav file on Matlab, but I'm struggling to get this function right.
Quant = zeros(1,length(y));
Q = peak2peak(y);
N = 2^8;
Delta = double(Q)/double(N); %Analog aproximation of each value on y
Faixa = 0:Delta:double(Q)-Delta; %Array of 256 analog values
for k1 = 1:length(y)
for k2 = 1:N-1
if (y(k1)>Faixa(k2) && y(k1)<=Faixa(k2+1))
Quant(k1) = dec2bin(k2,8); %Saving on array Quant the binary value corresponding to its analog comparison
break
end
end
end
Y has 16000 values, and I'm getting the following message: In an assignment A(I) = B, the number of elements in B and I must be the same.
1 个评论
Matthew Eicholtz
2015-9-8
The reason you are getting that error is because you are trying to store an 8-bit binary string (dec2bin(k2,8)) in a double array index with 1 row ( Quant(k1)). MATLAB does not like this.
I'm not sure what you want Quant to look like, but 2 options are:
- Make Quant a cell array of length(y) and store the binary strings in each cell.
- Make Quant have 8 rows (or columns depending on your desires), and store the 8-bits that way.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Fixed-Point Math Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!