#include<stdio.h>
#define max_user 10
#define max_data_length 20
#define max_sig_length 20
int no_user=0,no_sig_bit=0,no_data_bit=0;
int sig_seq[max_user][max_sig_length];
int z[max_data_length][max_sig_length];
int data_stream[max_user][max_data_length];
void sender();
void receiver();
void main(){
FILE *f = fopen("CDMA.txt", "w");
if (f == NULL)
{
printf("Error opening file!\n");
exit(1);
}
sender(f);
receiver(f);
fclose(f);
}
void sender(FILE *f){
int i,j;
int n=0;
printf("===========================================================\n");
printf(" Input Required Information \n");
printf("===========================================================\n");
fprintf(f,"===========================================================\n");
fprintf(f," SENDER \n");
fprintf(f,"===========================================================\n");
printf("Enter number of user (<=%d) ",max_user);
scanf("%d",&no_user);
printf("Enter number of data bit (<=%d) ",max_data_length);
scanf("%d",&no_data_bit);
printf("Enter number of signature bit (<=%d) ",max_sig_length);
scanf("%d",&no_sig_bit);
printf("----------------------------------------------------\n");
/* User */
for(i=0;i<no_user;i++){
printf("Enter data for User %d\n",i+1);
/* Data Stream */
printf("Enter the Data Stream bit (+1 | -1)\n");
for(j=0;j<no_data_bit;j++){
scanf("%d",&n);
if(n==1 || n==-1)
data_stream[i][j]=n;
else{
printf("Wrong data bit, Re-Enter\n");
j--;
}
}
/* Signature Code */
printf("Enter the Signature Code (+1 | -1)\n");
for(j=0;j<no_sig_bit;j++){
scanf("%d",&n);
if(n==1 || n==-1)
sig_seq[i][j]=n;
else{
printf("Wrong Signature bit, Re-Enter\n");
j--;
}
}
}
for(i=0;i<no_user;i++){
fprintf(f,"\nSender %d\n",i+1);
fprintf(f,"---------------------\n");
fprintf(f,"Data Stream: ");
for(j=0;j<no_data_bit;j++)
fprintf(f,"%d ",data_stream[i][j]);
fprintf(f,"\n");
fprintf(f,"Signature Sequence: ");
for(j=0;j<no_sig_bit;j++)
fprintf(f,"%d ",sig_seq[i][j]);
fprintf(f,"\n");
}
fprintf(f,"_________________________________________________\n");
/* Encoding */
fprintf(f,"Encoded Data:\n");
fprintf(f,"---------------------\n");
for(i=0;i<no_data_bit;i++){
fprintf(f,"|");
for(j=0;j<no_sig_bit;j++){
n=0;
while(n<no_user){
z[i][j]=z[i][j]+data_stream[n][i]*sig_seq[n][j];
n++;
}
// Channel Output
fprintf(f,"%d ",z[i][j]);
}
fprintf(f,"|");
}
fprintf(f,"\n");
}
void receiver(FILE *f){
int i,j;
int n=0,sum=0;
fprintf(f,"===========================================================\n");
fprintf(f," RECEIVER \n");
fprintf(f,"===========================================================\n");
/* Decoding */
fprintf(f,"\nReceived Channel Output:\n");
fprintf(f,"-----------------------------\n");
for(i=0;i<no_data_bit;i++){
fprintf(f,"|");
for(j=0;j<no_sig_bit;j++)
fprintf(f,"%d ",z[i][j]);
fprintf(f,"|");
}
fprintf(f,"\n");
fprintf(f,"\nSignature Code to be used:\n");
fprintf(f,"-----------------------------\n");
for(i=0;i<no_user;i++){
fprintf(f,"User %d: ",i+1);
for(j=0;j<no_sig_bit;j++)
fprintf(f,"%d ",sig_seq[i][j]);
fprintf(f,"\n");
}
fprintf(f,"\nDecoded data stream:\n");
fprintf(f,"--------------------------------\n");
while(n<no_user){
fprintf(f,"\nReceiver %d\n",n+1);
fprintf(f,"---------------------\n");
fprintf(f,"Data Stream: ");
for(i=0;i<no_data_bit;i++){
sum=0;
for(j=0;j<no_sig_bit;j++)
sum=sum+z[i][j]*sig_seq[n][j];
data_stream[n][i]=sum/no_sig_bit;
fprintf(f,"%d ",data_stream[n][i]);
}
fprintf(f,"\n");
n++;
}
}
#define max_user 10
#define max_data_length 20
#define max_sig_length 20
int no_user=0,no_sig_bit=0,no_data_bit=0;
int sig_seq[max_user][max_sig_length];
int z[max_data_length][max_sig_length];
int data_stream[max_user][max_data_length];
void sender();
void receiver();
void main(){
FILE *f = fopen("CDMA.txt", "w");
if (f == NULL)
{
printf("Error opening file!\n");
exit(1);
}
sender(f);
receiver(f);
fclose(f);
}
void sender(FILE *f){
int i,j;
int n=0;
printf("===========================================================\n");
printf(" Input Required Information \n");
printf("===========================================================\n");
fprintf(f,"===========================================================\n");
fprintf(f," SENDER \n");
fprintf(f,"===========================================================\n");
printf("Enter number of user (<=%d) ",max_user);
scanf("%d",&no_user);
printf("Enter number of data bit (<=%d) ",max_data_length);
scanf("%d",&no_data_bit);
printf("Enter number of signature bit (<=%d) ",max_sig_length);
scanf("%d",&no_sig_bit);
printf("----------------------------------------------------\n");
/* User */
for(i=0;i<no_user;i++){
printf("Enter data for User %d\n",i+1);
/* Data Stream */
printf("Enter the Data Stream bit (+1 | -1)\n");
for(j=0;j<no_data_bit;j++){
scanf("%d",&n);
if(n==1 || n==-1)
data_stream[i][j]=n;
else{
printf("Wrong data bit, Re-Enter\n");
j--;
}
}
/* Signature Code */
printf("Enter the Signature Code (+1 | -1)\n");
for(j=0;j<no_sig_bit;j++){
scanf("%d",&n);
if(n==1 || n==-1)
sig_seq[i][j]=n;
else{
printf("Wrong Signature bit, Re-Enter\n");
j--;
}
}
}
for(i=0;i<no_user;i++){
fprintf(f,"\nSender %d\n",i+1);
fprintf(f,"---------------------\n");
fprintf(f,"Data Stream: ");
for(j=0;j<no_data_bit;j++)
fprintf(f,"%d ",data_stream[i][j]);
fprintf(f,"\n");
fprintf(f,"Signature Sequence: ");
for(j=0;j<no_sig_bit;j++)
fprintf(f,"%d ",sig_seq[i][j]);
fprintf(f,"\n");
}
fprintf(f,"_________________________________________________\n");
/* Encoding */
fprintf(f,"Encoded Data:\n");
fprintf(f,"---------------------\n");
for(i=0;i<no_data_bit;i++){
fprintf(f,"|");
for(j=0;j<no_sig_bit;j++){
n=0;
while(n<no_user){
z[i][j]=z[i][j]+data_stream[n][i]*sig_seq[n][j];
n++;
}
// Channel Output
fprintf(f,"%d ",z[i][j]);
}
fprintf(f,"|");
}
fprintf(f,"\n");
}
void receiver(FILE *f){
int i,j;
int n=0,sum=0;
fprintf(f,"===========================================================\n");
fprintf(f," RECEIVER \n");
fprintf(f,"===========================================================\n");
/* Decoding */
fprintf(f,"\nReceived Channel Output:\n");
fprintf(f,"-----------------------------\n");
for(i=0;i<no_data_bit;i++){
fprintf(f,"|");
for(j=0;j<no_sig_bit;j++)
fprintf(f,"%d ",z[i][j]);
fprintf(f,"|");
}
fprintf(f,"\n");
fprintf(f,"\nSignature Code to be used:\n");
fprintf(f,"-----------------------------\n");
for(i=0;i<no_user;i++){
fprintf(f,"User %d: ",i+1);
for(j=0;j<no_sig_bit;j++)
fprintf(f,"%d ",sig_seq[i][j]);
fprintf(f,"\n");
}
fprintf(f,"\nDecoded data stream:\n");
fprintf(f,"--------------------------------\n");
while(n<no_user){
fprintf(f,"\nReceiver %d\n",n+1);
fprintf(f,"---------------------\n");
fprintf(f,"Data Stream: ");
for(i=0;i<no_data_bit;i++){
sum=0;
for(j=0;j<no_sig_bit;j++)
sum=sum+z[i][j]*sig_seq[n][j];
data_stream[n][i]=sum/no_sig_bit;
fprintf(f,"%d ",data_stream[n][i]);
}
fprintf(f,"\n");
n++;
}
}
Good work Proff. Anu
ReplyDeletethank's
ReplyDelete