matlabzero-pad

Zero Padding, Discarding of Bits, and Adding Start and Stop Bits - MATLAB


UPDATE: I used zeros() instead of padarray and problem solved.

I have a bit sequence stored in a column vector bs. I want to generate a frame that has a length of 1280 data bits plus 1 start bit (1) and 1 stop bit (0).

Therefore, if the length of bs is less than 1280, I have to zero pad it untill it gets equal to 1280. I tried bs = padarray(bs, 1280-length(bs)); but it does not work.

If the length of bs is greater than 1280, then I have to get only the first 1280 elements of it and I will discard the rest. I assume the following line will do the job: bs = bs(1:1280); Is that correct?

If the length of bs is equal to 1280, than it is OK.

Next, I have to add a start bit (1) at the beginning and a stop bit (0) at the end to form my frame which will have length 1 + 1280 + 1 = 1282 bits. How can I do that?

Thanks.


Solution

  • Maybe you can try this method

    Padded_vector = [0; non_Padded_vector; 1];
    

    Hope it will solve your problem