Forums

Introduce Single Error Bit

Started by tp_viju August 22, 2007
Hi,

I got a program as below which generates random binary codes (Phase
1.1). After that have to add parity bit to the codes(1.2). The next
step is to generate error to the code, but it generates error ( Index
exceeds matrix dimensions). Y is it so and some one got the right
answer?

%Phase 1.1

n;% # of bits
b=round(rand(1,n));% creates random binary code
disp('Random Data Bit Array');
disp(b);

%Phase 1.2

a=rem(sum(b),2)==1;% checking for parity
b(n+1)=a; % adds parity check bit to the codeword
disp('Codes with parity bit to be transmitted')
disp(b);

noise=randerr(1,n+1); %create noise
error=bitxor(b,noise); %introduce error into code
Dear Viju
Is this a part of your program or you have some other lines in it.??

Your current program is working fine and I am able to execute it without any
errors.

One of the output I got from your program
Random Data Bit Array
0 0 0 1 1 0 1 1 0 1

Codes with parity bit to be transmitted
0 0 0 1 1 0 1 1 0 1 1

Codes with Error
0 0 0 0 1 0 1 1 0 1 1
With Best Regards
Prajit S Nair

On 8/21/07, tp_viju wrote:
> Hi,
>
> I got a program as below which generates random binary codes (Phase
> 1.1). After that have to add parity bit to the codes(1.2). The next
> step is to generate error to the code, but it generates error ( Index
> exceeds matrix dimensions). Y is it so and some one got the right
> answer?
>
> %Phase 1.1
>
> n;% # of bits
> b=round(rand(1,n));% creates random binary code
> disp('Random Data Bit Array');
> disp(b);
>
> %Phase 1.2
>
> a=rem(sum(b),2)==1;% checking for parity
> b(n+1)=a; % adds parity check bit to the codeword
> disp('Codes with parity bit to be transmitted')
> disp(b);
>
> noise=randerr(1,n+1); %create noise
> error=bitxor(b,noise); %introduce error into code
>
>
>