Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- palavra = input ("Digite uma palavra: ", "s");
- arrayDec = toascii(palavra);
- printf("Array ASCII: ");
- for i = 1 : length(arrayDec)
- printf("%d ", arrayDec(i));
- end
- % binarização
- matrixBin = dec2bin(arrayDec, 8);
- % cell de strings vira num
- matrixNum = str2num(matrixBin);
- % transforma de uma cell pra array simples
- arrayNum = rot90(matrixNum);
- % divide os numeros de toda a cell e adiciona em um array só
- arrayNumDiv = [];
- zeroAux = [0];
- for i = 1 : length(arrayNum)
- aux = sprintf("%d", arrayNum(i)) - '0';
- if (length(aux) < 8)
- while (length(aux) < 8)
- aux = [zeroAux, aux];
- endwhile
- endif
- arrayNumDiv = [arrayNumDiv, aux];
- endfor
- subplot(3, 1, 1);
- plotargrafico(arrayNumDiv, "Palavra binario", 1.1, -1.1, 32);
- printf("\n Palavra: ");
- printf("%d", arrayNumDiv);
- % NRZ encoding. pra dar distancia entre 1 e 0, os zeros viram -1
- arrayNumDivNRZ = arrayNumDiv;
- for i = 1 : length(arrayNumDivNRZ)
- if (arrayNumDivNRZ(i) == 0)
- arrayNumDivNRZ(i) = -1;
- endif
- endfor
- subplot(3, 1, 2);
- plotargrafico(arrayNumDivNRZ, "Após NRZ", 1.1, -1.1, 32);
- printf("\n NRZ: ");
- printf("%d ", arrayNumDivNRZ);
- # ASK
- frequencia = 40;
- tempo = 0.000125; #0.0000625
- tempoIntervalo = length(arrayNumDiv)/32;
- timeframe = (0 : tempo : tempoIntervalo - tempo)';
- onda = sin(2 * pi * frequencia * timeframe);
- ondaAux = sin(2 * pi * frequencia * timeframeAux);
- tamanhoSeg = (length(onda) / length(arrayNumDivNRZ)); # Descobre o tamanho de cada segmento.
- i = 1;
- j = 1;
- k = tamanhoSeg;
- contadorOndaAux = 1;
- # refazer essa merda
- while (j <= length(arrayNumDivNRZ))
- if (arrayNumDivNRZ(j) == -1)
- while (i <= k)
- onda(i) = 0;
- contadorOndaAux = 1;
- i++;
- endwhile
- elseif (arrayNumDivNRZ(j) == 1)
- while (i <= k)
- onda(i) = ondaAux(contadorOndaAux);
- contadorOndaAux++;
- i++;
- endwhile
- endif
- i = k;
- k = k + tamanhoSeg;
- j++;
- endwhile
- subplot(3, 1, 3);
- plot(timeframe, onda);
- axis([0 (tempoIntervalo - tempo) -1.2 1.2]);
- grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement