Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Matlab, w rite a function nybblise which takes as input digital signal of 0’s

ID: 668711 • Letter: I

Question

In Matlab, write a 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. For example, the 16 bit input should be mapped as:

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.

Explanation / Answer

function A = nybblise(d)
    L = length(d) ;
    remainder = rem(L,4);

    if remainder != 0
       A = -1;
   else
      arrLen = L/4;
      mnarray = zeros(4, arrLen);
      for i = 1 : arrLen
          
            index = (i-1) * 4;
            mnarray(1,i) = d(index+1);
            mnarray(2,i) = d(index+2);
            mnarray(3,i) = d(index+3);
            mnarray(4,i) = d(index+4);
      end
      A = mnarray;
   end
end

d = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];

mna = nybblise(d);

disp(mna);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote