Program:
clc;
clear all;
code_length = input('Enter Code Length = ');
data_stream = input('Enter Data Bit Stream = ');
%Generating Walsh Code
code = [-1 -1; -1 +1];
[r1 c1] = size(code);
disp('Walsh code generated = ');
while r1<code_length
code = [code,code;code,-1*code];
[r1 c1] = size(code);
disp(code);
end
code_length = length(code); %length (number of bits) of code
Y = size(data_stream);
N = Y(1); %number of unique senders / bit streams
I = Y(2); %number of bits per stream
T = []; %sum of all transmitted and encoded data on channel
data_received = []; %vector of reconstructed bits at receiver
%show data bits and codes
disp('Data bit stream to be transmitted = '),disp(data_stream);
disp('Walsh codes used for transmission = '),disp(code);
%encode bits and transmit
G = zeros(I,code_length);
for n = 1:N
Z = zeros(I,code_length);
for i = 1:I
for m = 1:code_length
Z(i,m) = [data_stream(n,i)*code(n,m)];
end
end
G = G + Z;
end
%show channel traffic
for i = 1:I
T = [ T G(i,:) ];
end
disp('Resulting traffic on the channel = '),disp(T);
%decode and reconstruct
for n = 1:N
tot = zeros(1,I);
R = zeros(I,code_length);
for i = 1:I
for m = 1:code_length
R(i,m) = G(i,m) * code (n,m);
tot(i) = tot(i) + R (i,m);
end
end
data_received = [data_received ; tot / code_length];
end
disp('Reconstructed data at the receiver = '),disp(data_received);
Output:
Enter Code Length = 4
Enter Data Bit Stream = [ 1 -1 1 -1 1 1 -1 -1 ;
-1 -1 1 1 1 -1 -1 1 ;
1 1 -1 -1 -1 1 1 -1 ;
1 1 1 1 -1 -1 -1 -1 ];
Walsh code generated =
-1 -1 -1 -1
-1 1 -1 1
-1 -1 1 1
-1 1 1 -1
Data bit stream to be transmitted =
1 -1 1 -1 1 1 -1 -1
-1 -1 1 1 1 -1 -1 1
1 1 -1 -1 -1 1 1 -1
1 1 1 1 -1 -1 -1 -1
Walsh codes used for transmission =
-1 -1 -1 -1
-1 1 -1 1
-1 -1 1 1
-1 1 1 -1
Resulting traffic on the channel =
Columns 1 through 19
-2 -2 2 -2 0 0 4 0 -2 2 -2 -2 0 4 0 0 0 0 -4
Columns 20 through 32
0 0 -4 0 0 2 -2 2 2 2 2 -2 2
Reconstructed data at the receiver =
1 -1 1 -1 1 1 -1 -1
-1 -1 1 1 1 -1 -1 1
1 1 -1 -1 -1 1 1 -1
1 1 1 1 -1 -1 -1 -1
clc;
clear all;
code_length = input('Enter Code Length = ');
data_stream = input('Enter Data Bit Stream = ');
%Generating Walsh Code
code = [-1 -1; -1 +1];
[r1 c1] = size(code);
disp('Walsh code generated = ');
while r1<code_length
code = [code,code;code,-1*code];
[r1 c1] = size(code);
disp(code);
end
code_length = length(code); %length (number of bits) of code
Y = size(data_stream);
N = Y(1); %number of unique senders / bit streams
I = Y(2); %number of bits per stream
T = []; %sum of all transmitted and encoded data on channel
data_received = []; %vector of reconstructed bits at receiver
%show data bits and codes
disp('Data bit stream to be transmitted = '),disp(data_stream);
disp('Walsh codes used for transmission = '),disp(code);
%encode bits and transmit
G = zeros(I,code_length);
for n = 1:N
Z = zeros(I,code_length);
for i = 1:I
for m = 1:code_length
Z(i,m) = [data_stream(n,i)*code(n,m)];
end
end
G = G + Z;
end
%show channel traffic
for i = 1:I
T = [ T G(i,:) ];
end
disp('Resulting traffic on the channel = '),disp(T);
%decode and reconstruct
for n = 1:N
tot = zeros(1,I);
R = zeros(I,code_length);
for i = 1:I
for m = 1:code_length
R(i,m) = G(i,m) * code (n,m);
tot(i) = tot(i) + R (i,m);
end
end
data_received = [data_received ; tot / code_length];
end
disp('Reconstructed data at the receiver = '),disp(data_received);
Output:
Enter Code Length = 4
Enter Data Bit Stream = [ 1 -1 1 -1 1 1 -1 -1 ;
-1 -1 1 1 1 -1 -1 1 ;
1 1 -1 -1 -1 1 1 -1 ;
1 1 1 1 -1 -1 -1 -1 ];
Walsh code generated =
-1 -1 -1 -1
-1 1 -1 1
-1 -1 1 1
-1 1 1 -1
Data bit stream to be transmitted =
1 -1 1 -1 1 1 -1 -1
-1 -1 1 1 1 -1 -1 1
1 1 -1 -1 -1 1 1 -1
1 1 1 1 -1 -1 -1 -1
Walsh codes used for transmission =
-1 -1 -1 -1
-1 1 -1 1
-1 -1 1 1
-1 1 1 -1
Resulting traffic on the channel =
Columns 1 through 19
-2 -2 2 -2 0 0 4 0 -2 2 -2 -2 0 4 0 0 0 0 -4
Columns 20 through 32
0 0 -4 0 0 2 -2 2 2 2 2 -2 2
Reconstructed data at the receiver =
1 -1 1 -1 1 1 -1 -1
-1 -1 1 1 1 -1 -1 1
1 1 -1 -1 -1 1 1 -1
1 1 1 1 -1 -1 -1 -1