begin cdma decode

This commit is contained in:
eneller
2026-03-23 19:26:22 +01:00
parent ea3fbb4898
commit b80ac9d931

View File

@@ -62,7 +62,7 @@ perms <- combn(x = orthogonals,m = 2, simplify = FALSE)
```{r encode}
output = c()
output <- c()
for (j in 1:ncol(lines_bin)){
col <- lines_bin[,j]
output_symbol <- 0
@@ -73,8 +73,43 @@ for (j in 1:ncol(lines_bin)){
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)
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)
}
}
```