0% found this document useful (0 votes)
92 views

MCC Expt 4 Walsh Code

This document describes an experiment implementing Walsh codes for code division multiple access (CDMA) communication. It provides background on Walsh codes, which are orthogonal codes used in CDMA. The experiment involves encoding data from two stations using Walsh codes, combining the encoded data onto a shared channel, and decoding the original data by multiplying the channel signals with the appropriate codes. The program demonstrates encoding, transmission, and decoding of data between two stations using 4-bit Walsh codes.

Uploaded by

Alka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

MCC Expt 4 Walsh Code

This document describes an experiment implementing Walsh codes for code division multiple access (CDMA) communication. It provides background on Walsh codes, which are orthogonal codes used in CDMA. The experiment involves encoding data from two stations using Walsh codes, combining the encoded data onto a shared channel, and decoding the original data by multiplying the channel signals with the appropriate codes. The program demonstrates encoding, transmission, and decoding of data between two stations using 4-bit Walsh codes.

Uploaded by

Alka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computer Engineering Exp. No.

Semester B.E. Semester VII – Computer Engineering


Subject Mobile Application Development Technology Lab
Subject Professor In-charge
Assisting Teachers
Laboratory M313

Student Name
Roll Number 17102A0057
Grade and Subject
Teacher’s Signature

Experiment Number 4

Experiment Title Implementation of Walsh Code for CDMA


Resources Required Hardware: Programming Language :
Computer system Python/Java/C/C++
Theory
Walsh Code
Walsh Codes are most commonly used in the orthogonal codes of
CDMA applications. These codes correspond to lines of a special
square matrix called the Hadamard matrix. For a set of Walsh codes of
length N, it consists of n lines to form a square matrix of n × n Walsh
code.

The system uses 64 Walsh function matrix 64. The first line of this
matrix contains a string of all zeros with each of the following lines
containing different combinations of bit 0 and 1. Each line is
orthogonal and equal representation for binary bits. When
implemented with the CDMA system, each mobile user uses one of the
64 sequences of rows in the matrix as a spreading code. And, it
provides zero cross-correlation among all the other users.

Where n is a power of 2 and indicates the different dimensions of the


matrix W. Further, n represents the logic NOT operation on all bits in
Department of Computer Engineering Exp. No.4
this matrix. The three matrices W2, W4, and W8, respectively show the
Walsh function for the dimension 2, 4, and 8.

Each line of the 64 Walsh matrix 64 corresponds to a channel number.


The channel number 0 is mapped to the first row of the Walsh matrix,
which is the code of all zeros.

To calculate the cross-correlation between the sequences, we will need


to convert the bits into the matrix to form the antithesis of ± 1 values.

Procedure:
The station encodes its data bit as follows.
● +1 if bit = 1
● -1 if bit = 0
● no signal(interpreted as 0) if station is idle
Each station is assigned a unique orthogonal sequence (code) which is
N bit long for N stations
Each station does a scalar multiplication of its encoded data bit and
code sequence.
The resulting sequence is then placed on the channel.
Since the channel is common, amplitudes add up and hence resultant
channel sequence is sum of sequences from all channels.
If station 1 wants to listen to station 2, it multiplies (inner product) the
channel sequence with code of station S2.
The inner product is then divided by N to get data bit transmitted from
station 2.
Eg:- Assume 4 stations S1, S2, S3, S4. We’ll use 4×4 Walsh Table to
assign codes to them.
C1 = [+1 +1 +1 +1]
C2 = [+1 -1 +1 -1]
C3 = [+1 +1 -1 -1]
C4 = [+1 -1 -1 +1]

Let their data bits currently be:


Department of Computer Engineering Exp. No.4
D1 = -1
D2 = -1
D3 = 0 (Silent)
D4 = +1

Resultant channel sequence = C1.D1 + C2.D2 + C3.D3 +


C4.D4
= [-1 -1 -1 -1] + [-1 +1 -1
+1] + [0 0 0 0]

+ [+1 -1 -1 +1]
= [-1 -1 -3 +1]

Now suppose station 1 wants to listen to station 2.


Inner Product = [-1 -1 -3 +1] x C2
= -1 + 1 - 3 - 1 = -4

Data bit that was sent = -4/4 = -1.

Program:

num_bits = int(input("Enter number of bits: "))

# Enter data, if 0, replace by -1


A = int(input("Enter A Data: "))
B = int(input("Enter B Data: "))
if B == 0:
B = -1

# Accept num_bits length of codes for A and B, if any bits are 0,


replace by -1
A_code = list(input("Enter A Code: "))
A_code = [-1 if x == '0' else int(x) for x in A_code]

B_code = list(input("Enter B Code: "))


B_code = [-1 if x == '0' else int(x) for x in B_code]

# Create data at Station A by multiplying each A code bit by actual


A data
A_data = []
for a in A_code:
A_data.append(a * A)

# Same as above
B_data = []
for b in B_code:
B_data.append(b * B)

print("A Code:", A_code)


Department of Computer Engineering Exp. No.4
print("B Code:", B_code)

print("A Station:", A_data)


print("B Station:", B_data)

# Resultant data in channel is just per-bit sum of data at each


station
channel_data = []
for i in range(num_bits):
channel_data.append(A_data[i] + B_data[i])
# if channel_data[-1] == 0:
# channel_data[-1] = -1

print("Channel Data:", channel_data)

# To decode A data from channel data, multiply channel data bits by


A's code bits
dec_A_data = []
dec_B_data = []

for i in range(num_bits):
dec_A_data.append(channel_data[i] * A_code[i])
dec_B_data.append(channel_data[i] * B_code[i])

print("Decoded A Data Stream:", dec_A_data)


print("Decoded B Data Stream:", dec_B_data)

# Final step, sum up decoded data stream and then divide it by


number of stations
# In our case, it is 2, so divide by 2
# But we kept number of bits variable
# So instead of number of stations divide it by number of bits
dec_A = sum(dec_A_data) // num_bits
dec_B = sum(dec_B_data) // num_bits

dec_A = 0 if dec_A == -1 else dec_A


dec_B = 0 if dec_B == -1 else dec_B

print("Decoded A Data:", dec_A)


print("Decoded B Data:", dec_B)
Department of Computer Engineering Exp. No.4

Output

Conclusion Implementation of Walsh code algorithm for CDMA architecture is


successfully completed.

You might also like