This is a MATLAB QUESTION. please dont attmept it with C++ Write a function nybb
ID: 3784937 • Letter: T
Question
This is a MATLAB QUESTION. please dont attmept it with C++
Write a function nybblise which takes as input digital signal of 0's and l's stored in a vector of size N times 1, and breaks it into four 4-bit nybbles, which are returned as the columns of a 4 times N/4 matrix. For example, the 16 bit input should be mapped as: [d_1 d_2 TripleDot d_16] Implies [d_1 d_5 d_9 d_13 d_2 d_6 d_10 d_14 d_3 d_7 d_11 d_15 d_4 d_8 d_12 d_16] Your function must return -1 if the N is not a multiple of 4. Following is the signature of the function. function A = nybblise(d) Input: d - digital signal as a vector of size N times 1 Output: A - nybbles as a 4 times N/4 matrix OR - 1 if N is not a multiple of 4Explanation / Answer
% nybblise.m
function A = nybblise(d)
% here the First index is mainly used to calculate how many multiples of 4 (thus number of columns) it takes to get
% and 'd' given 'd' is a multiple of 4 to begin with.
index = 0;
%thus Second index is used to for a loop where a zero matrix of size 4*N (where
%finaly N = number of columns needed which is the value of 'index') in which the
% here values of 'd' replace the zero matrix to output A with a 4*N matrix with the values of 'd'.
index2 = 0;
% d_mul is first set to the length of input 'd' and is used later to find
% the number of columns needed for our output using 'index'
d_mul = length(d);
%
while d_mul > 0
d_mul = d_mul - 4;
index = index + 1;
end
matrix = zeros(4,index);
if d_mul == 0
while index2 <= (i
ndex-1)
matrix(:,(index2+1)) = d([(index2*4+1) (index2*4+2) (index2*4+3) (index2*4+4)]);
index2 = index2+1;
end
A = matrix;
else
A = -1;
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.