fix: cdma decode
This commit is contained in:
20
cdma.Rmd
20
cdma.Rmd
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user