Write a matlab function nybblise which takes as input digital signal of 0’s and 1’s stored in a vector of size N ×1, and breaks it into four 4-bit nybbles, which are returned as the columns of a 4×N/4 matrix.
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 x 1
Output: A - nybbles as a 4 x N/4 matrix OR -1 if N is not a multiple of 4
Note: This function must use loops rather than MATLAB built-in functions such as reshape, fliplr, flipud.
1
Expert's answer
2016-09-20T11:10:03-0400
% nybblise.m function A = nybblise(d) % First index is used to calculate how many multiples of 4 (thus number of columns) it takes to get % 'd' given 'd' is a multiple of 4 to begin with. index = 0; % Second index is used to for a loop where a zero matrix of size 4*N (where % N = number of columns needed which is the value of 'index') in which the % 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 <= (index-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
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment