begin cdma decode
This commit is contained in:
39
cdma.Rmd
39
cdma.Rmd
@@ -62,7 +62,7 @@ perms <- combn(x = orthogonals,m = 2, simplify = FALSE)
|
|||||||
|
|
||||||
|
|
||||||
```{r encode}
|
```{r encode}
|
||||||
output = c()
|
output <- c()
|
||||||
for (j in 1:ncol(lines_bin)){
|
for (j in 1:ncol(lines_bin)){
|
||||||
col <- lines_bin[,j]
|
col <- lines_bin[,j]
|
||||||
output_symbol <- 0
|
output_symbol <- 0
|
||||||
@@ -73,8 +73,43 @@ for (j in 1:ncol(lines_bin)){
|
|||||||
single_symbol <- (-1)^(1+symbol) * code # the resulting encoded vector
|
single_symbol <- (-1)^(1+symbol) * code # the resulting encoded vector
|
||||||
output_symbol <- output_symbol + single_symbol # the sum of all encoded vectors
|
output_symbol <- output_symbol + single_symbol # the sum of all encoded vectors
|
||||||
}
|
}
|
||||||
output <-append(output, output_symbol)
|
output <-append(output, list(output_symbol))
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Decode
|
||||||
|
Decoding CDMA is achieved by calculating the dot product of the received encoded symbol with each channel's characteristic code.
|
||||||
|
```{r decode}
|
||||||
|
decoded <- c()
|
||||||
|
for (symbol in output){
|
||||||
|
decoded_col <- c()
|
||||||
|
for(i in 1:nrow(orthogonals)){
|
||||||
|
code <- orthogonals[i,]
|
||||||
|
decoded_symbol <- if(code%*% symbol > 0) 1 else 0
|
||||||
|
decoded_col <- append(decoded_col,decoded_symbol)
|
||||||
|
}
|
||||||
|
decoded<- append(decoded, list(decoded_col))
|
||||||
|
}
|
||||||
|
decoded_m <- do.call(cbind,decoded)
|
||||||
|
```
|
||||||
|
|
||||||
|
Then we apply our text encoding on each line separately.
|
||||||
|
```{r text-decode}
|
||||||
|
chunk <- function(x, chunk_size) {
|
||||||
|
split(x, cut(seq_along(x), breaks = seq(0, length(x), by = chunk_size), include.lowest = TRUE))
|
||||||
|
}
|
||||||
|
for (i in 1:nrow(decoded_m)){
|
||||||
|
line <- decoded_m[i,]
|
||||||
|
symbols <- chunk(line, 7)
|
||||||
|
for (symbol in symbols){
|
||||||
|
binary_str <- paste(symbol, collapse = "")
|
||||||
|
# Convert the binary string to a decimal value
|
||||||
|
decimal <- strtoi(binary_str, base = 2)
|
||||||
|
print(decimal)
|
||||||
|
# Convert the decimal value to an ASCII character
|
||||||
|
char <- intToUtf8(decimal)
|
||||||
|
print(char)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user