码分多址cdma通信

The analogy behind code-division multiple access says there are four people and two out of them are talking with each other in some language what other two don't know and the same goes for those two also. For example, two of them talking in Punjabi and two in Bengali. Those two talking in Punjabi has no idea about Bengali and same for Bengali guys too. So, there is no interruption in their respective communication. The same analogy has been used for CDMA.

代码分区多址访问背后的类比说,有四个人,其中两个人正在用某种语言互相交谈,而其他两个人则不知道,这两个人也是如此。 例如,其中两个在旁遮普邦说话,两个在孟加拉国说话。 这两个在旁遮普邦说话的人对孟加拉语一无所知,孟加拉人也一样。 因此,它们各自的通信不会中断。 CDMA也使用了相同的类比。

We discuss the concept with the help of an example,

我们将通过一个示例来讨论这个概念,

    Say there are four stations: A, B, C, D
    Each station has assigned a code say C1, C2, C3, C4
    Each of them sending their respective data say D1, D2, D3, D4
    All of them throws their data multiplying with the code
    
    Thus data on the channel is
    C1D1 + C2D2 + C3D3 + C4D4

The receiver who wants to retrieve simply multiplying the data with its code and divide by the number of the station.

想要检索的接收器只需将数据与其代码相乘并除以站号即可。

Now, this is possible because of the coding theory. Let's see the how codes are generated, encoding and decoding of data bit and rules of addition and multiplication

现在,由于编码理论,这是可能的。 让我们看看如何生成代码,数据位的编码和解码以及加法和乘法的规则

Code generation:

代码生成:

Code generation is done by Walsh table

代码生成由Walsh表完成

Walsh table is a kind of recursive table which is represented by

Walsh表是一种递归表,由

    
Where W1= [1] 2N=No of stations So, for 2 stations
Code for first station is [1 1] //vector Code for second station is [1 -1] //vector Additions and multiplications are vector scalar type Say [1 0]*[-1 1]=(1*-1)+ (0*1)]=-1+0=-1
wash table 2
wash table 1

Encoding and decoding of data

数据编码和解码

  • If a station is sending bit 0, it's encoded as -1

    如果工作站正在发送位0,则其编码为-1

  • If a station is sending bit 1, it's encoded as 1

    如果工作站正在发送位1,则将其编码为1

  • If station is idle, it's encoded as 0

    如果工作站空闲,则编码为0

Example with 2 stations

2个站的例子

    Say, Station A sends 1, B sends 0
    Code of A: [1 1]
    Data of A: 1
    Code of B: [1 -1]
    Data of B: -1

    Dara on channel
    1*[1 1] + -1*[1 -1]
    =[1 1] + [-1 1]
    =[0 2] //scalar addition of vector

    Now say A wants to retrieve its data
    So multiply data on channel with A’s code
    ([0 2] * [1 1 ] )/2
    =(0*1 + 2*1)=2/2=1

    For B
    ([0 2] * [1 -1])/2=-2/2=-1


C++ implementation

C ++实现

#include <bits/stdc++.h>
using namespace std;

class CDMA { 
	public:
	int** wtable; 
	int** copy; 
	int* channel_sequence; 

	void setUp(int data[], int num_stations) { 
		int n=num_stations;
		wtable = new int* [n];

		for(int i=0;i<n;i++)
			wtable[i]=new int[n];

		copy = new int* [n];
		for(int i=0;i<n;i++)
			copy[i]=new int[n]; 

		buildWalshTable(num_stations, 0, num_stations - 1, 0, num_stations - 1, false); 

		showWalshTable(num_stations); 

		for (int i = 0; i < num_stations; i++) { 
			for (int j = 0; j < num_stations; j++) { 
				copy[i][j] = wtable[i][j];  
				wtable[i][j] *= data[i]; 
			} 
		} 

		channel_sequence = new int[n]; 

		for (int i = 0; i < num_stations; i++) { 
			for (int j = 0; j < num_stations; j++) { 
				channel_sequence[i] += wtable[j][i]; 
			} 
		} 
	} 

	void listenTo(int sourceStation, int num_stations) {
		int innerProduct = 0; 
		for (int i = 0; i < num_stations; i++) { 
			innerProduct += copy[sourceStation][i] * channel_sequence[i]; 
		} 

		int k=innerProduct/num_stations;
		
		if(k==1)
			cout<<"The data received from station "<<sourceStation+1<<" is: "<<k<<endl;
		else if(k==-1)
			cout<<"The data received from station "<<sourceStation+1<<" is: 0"<<endl;
		else
			cout<<"Station "<<sourceStation+1<<" is idle, it didn't send any data\n"; 
	} 

	//building walsh table
	int buildWalshTable(int len, int i1, int i2, int j1,int j2, bool isBar) { 
		if (len == 2) { 
			if (!isBar) { 
				wtable[i1][j1] = 1; 
				wtable[i1][j2] = 1; 
				wtable[i2][j1] = 1; 
				wtable[i2][j2] = -1; 
			} 
			else { 
				wtable[i1][j1] = -1; 
				wtable[i1][j2] = -1; 
				wtable[i2][j1] = -1; 
				wtable[i2][j2] = +1; 
			} 
			return 0; 
		} 

		int midi = (i1 + i2) / 2; 
		int midj = (j1 + j2) / 2; 

		buildWalshTable(len / 2, i1, midi, j1, midj, isBar); 
		buildWalshTable(len / 2, i1, midi, midj + 1, j2, isBar); 
		buildWalshTable(len / 2, midi + 1, i2, j1, midj, isBar); 
		buildWalshTable(len / 2, midi + 1, i2, midj + 1, j2, !isBar); 

		return 0; 
	} 

	void showWalshTable(int num_stations) {
		cout<<"................Displaying walsh table..................\n";
		//cout<<endl; 
		for (int i = 0; i < num_stations; i++) { 
			for (int j = 0; j < num_stations; j++) { 
				cout<<wtable[i][j]<<"  "; 
			} 
			cout<<"\n"; 
		} 
		cout<<"----------------------------------------------------------\n"; 
	}
};

int main() {
	cout<<"-------------------------------CDMA Implementation------------------------\n";
	
	int num_stations; 
	cout<<"Enter no of stations\n";

	cin>>num_stations;
	//data bits corresponding to each station 
	cout<<"Press 1 if station is sending bit 1\n";
	cout<<"Press -1 if station is sending bit 0\n";
	cout<<"Press 0 if station is idle\n";
	int* data=new int[num_stations];
	for(int i=0;i<num_stations;i++){
		cout<<"enter for station "<<i+1<<endl;
		cin>>data[i];
	}

	CDMA channel; 

	channel.setUp(data, num_stations); 

	// station you want to listen to 
	cout<<"Enter station no you want to listen to\n";
	int sourceStation;
	cin>> sourceStation;

	channel.listenTo(sourceStation-1, num_stations); 
	return 0;
} 


Output 1

输出1

-------------------------------CDMA Implementation------------------------
Enter no of stations
4
Press 1 if station is sending bit 1
Press -1 if station is sending bit 0
Press 0 if station is idle
enter for station 1
1
enter for station 2
0
enter for station 3
-1
enter for station 4
-1
................Displaying walsh table..................
1  1  1  1  
1  -1  1  -1  
1  1  -1  -1  
1  -1  -1  1  
----------------------------------------------------------
Enter station no you want to listen to
4
The data received from station 4 is: 0

Output 2

输出2

-------------------------------CDMA Implementation------------------------
Enter no of stations
8
Press 1 if station is sending bit 1
Press -1 if station is sending bit 0
Press 0 if station is idle
enter for station 1
1
enter for station 2
1
enter for station 3
-1
enter for station 4
-1
enter for station 5
0
enter for station 6
0
enter for station 7
-1
enter for station 8
1
................Displaying walsh table..................
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  
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  
----------------------------------------------------------
Enter station no you want to listen to
5
Station 5 is idle, it didn't send any data


翻译自: https://www.includehelp.com/computer-networks/code-division-multiple-access-cdma.aspx

码分多址cdma通信

更多推荐