fix: cdma decode

This commit is contained in:
eneller
2026-03-23 19:41:39 +01:00
parent b80ac9d931
commit 37cd47f56a

View File

@@ -37,11 +37,7 @@ 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])
print(lines_bin)
```
## Orthogonal Code
@@ -93,23 +89,27 @@ for (symbol in output){
decoded_m <- do.call(cbind,decoded)
```
Then we apply our text encoding on each line separately.
We can now do a simple check if all the values we decoded are the same:
```{r decode-demo}
decoded_m == lines_bin
```
Then we apply our text encoding on each line separately, respecting the LSB/MSB order.
```{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))
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 = "")
binary_str <- paste(rev(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)
}
}
```