cdma encoding

This commit is contained in:
eneller
2026-03-23 18:47:43 +01:00
parent 508db25b51
commit ea3fbb4898

View File

@@ -20,21 +20,61 @@ on the receiving side.
knitr::opts_chunk$set(echo = TRUE)
```
## Getting Input
## 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')
lines_bin <- unlist(lapply(lines, utf8ToInt))
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)
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)$ in that satisfy pairwise orthogonality $a \perp b$.
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)
}
```