%% This function is used to simulate a burst error noise.
%% Using this function, the user can specify how many consecutive bits (flipped_bits) will be flipped.
%% The location of the flipped bits is randomly chosen inside each frame.
function [out] = scramblerflip(in)

% Copyright 2005-2011 The MathWorks, Inc.

frame_size = length(in);
flipped_bits = 6;
if (flipped_bits >= frame_size) 
    error(message('HDLLink:scramblerflip:InvalidFrameSize'));
end
a = 1; b = frame_size-flipped_bits+1;
x = floor(a + (b-a) * rand(1));
%% Create a vector mask where '0'- no flip, and '1'- flip.
mask(1:frame_size)=0;
mask(x:x+flipped_bits-1)= 1;
mask=mask';
%% Use XOR operation to flip relevant bits --> A XOR '1' = NOT(A)
out = double(xor(boolean(in),boolean(mask)));
end