81 lines
2.2 KiB
Plaintext
81 lines
2.2 KiB
Plaintext
---
|
|
title: "CDMA"
|
|
subtitle: "Software Defined Radio"
|
|
output: pdf_document
|
|
date: "`r Sys.Date()`"
|
|
---
|
|
# Assignment
|
|
In the R environment for statistical computing, develop
|
|
software support for generating a CDMA composite
|
|
signal. Provide four parallel communication channels
|
|
with corresponding characteristic code sequences of 5
|
|
bits length. Define software support for accepting
|
|
ASCII characters (via a terminal or reading from a data
|
|
file), converting ASCII characters into binary data,
|
|
coding with the respective code sequence of the given
|
|
communication channel, and decoding and deciding
|
|
on the receiving side.
|
|
|
|
```{r setup, include=FALSE}
|
|
knitr::opts_chunk$set(echo = TRUE)
|
|
```
|
|
|
|
## Input and binary interpretation
|
|
We first get input by reading a file `input.txt`, where each line (0-3) is one communication channel.
|
|
Because UTF8 maintains compatibility with ASCII, the UTF8 conversion can be used assuming that the input is only ASCII.
|
|
ASCII characters require 7 bits of information per character.
|
|
```{r input}
|
|
lines <- readLines('./input.txt',encoding = 'ASCII')
|
|
strToBin <- function(s){
|
|
# FIXME for strings longer than 1
|
|
r <- as.integer(intToBits(utf8ToInt(s)))
|
|
r <- r[1:7]
|
|
return(r)
|
|
}
|
|
lines_bin <- do.call(rbind, lapply(lines, strToBin))
|
|
```
|
|
|
|
```{r input-demo, echo=FALSE}
|
|
print(lines)
|
|
print(lines_bin[1])
|
|
print(lines_bin[2])
|
|
print(lines_bin[3])
|
|
print(lines_bin[4])
|
|
|
|
```
|
|
|
|
## Orthogonal Code
|
|
For an orthogonal code, we are looking for vectors $(a,b,...n)$ that satisfy pairwise orthogonality $a \perp b$.
|
|
```{r orth}
|
|
o1 <- c( 1, 1, 1, 1, 1)
|
|
o2 <- c(-1,-1, 1, 1, 1)
|
|
o3 <- c( 1,-1, 1,-1,-1)
|
|
o4 <- c(-1, 1, 1,-1,-1)
|
|
orthogonals <- do.call(rbind,list(o1,o2,o3,o4))
|
|
```
|
|
|
|
```{r orth-demo, include=FALSE}
|
|
perms <- combn(x = orthogonals,m = 2, simplify = FALSE)
|
|
```
|
|
|
|
## Encode
|
|
|
|
|
|
```{r encode}
|
|
output = c()
|
|
for (j in 1:ncol(lines_bin)){
|
|
col <- lines_bin[,j]
|
|
output_symbol <- 0
|
|
for (i in 1:length(col)){
|
|
symbol <- col[i] # the symbol to be encoded
|
|
code <- orthogonals[i,] # the code vector
|
|
|
|
single_symbol <- (-1)^(1+symbol) * code # the resulting encoded vector
|
|
output_symbol <- output_symbol + single_symbol # the sum of all encoded vectors
|
|
}
|
|
output <-append(output, output_symbol)
|
|
}
|
|
```
|
|
|
|
|