Advertisement
Guest User

trabalho

a guest
Jul 5th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 2.04 KB | None | 0 0
  1. palavra = input ("Digite uma palavra: ", "s");
  2. arrayDec = toascii(palavra);
  3.  
  4. printf("Array ASCII: ");
  5. for i = 1 : length(arrayDec)
  6.   printf("%d  ", arrayDec(i));
  7. end
  8.  
  9. % binarização
  10. matrixBin = dec2bin(arrayDec, 8);
  11.  
  12. % cell de strings vira num
  13. matrixNum = str2num(matrixBin);
  14.  
  15. % transforma de uma cell pra array simples
  16. arrayNum = rot90(matrixNum);
  17.  
  18. % divide os numeros de toda a cell e adiciona em um array só
  19. arrayNumDiv = [];
  20. zeroAux = [0];
  21. for i = 1 : length(arrayNum)
  22.   aux = sprintf("%d", arrayNum(i)) - '0';
  23.  
  24.   if (length(aux) < 8)
  25.     while (length(aux) < 8)
  26.       aux = [zeroAux, aux];
  27.     endwhile
  28.   endif
  29.  
  30.   arrayNumDiv = [arrayNumDiv, aux];
  31. endfor
  32.  
  33. subplot(3, 1, 1);
  34. plotargrafico(arrayNumDiv, "Palavra binario", 1.1, -1.1, 32);
  35. printf("\n Palavra: ");
  36. printf("%d", arrayNumDiv);
  37.  
  38. % NRZ encoding. pra dar distancia entre 1 e 0, os zeros viram -1
  39. arrayNumDivNRZ = arrayNumDiv;
  40. for i = 1 : length(arrayNumDivNRZ)
  41.   if (arrayNumDivNRZ(i) == 0)
  42.     arrayNumDivNRZ(i) = -1;
  43.   endif
  44. endfor
  45.  
  46. subplot(3, 1, 2);
  47. plotargrafico(arrayNumDivNRZ, "Após NRZ", 1.1, -1.1, 32);
  48. printf("\n NRZ: ");
  49. printf("%d ", arrayNumDivNRZ);
  50.  
  51. # ASK
  52. frequencia = 40;
  53. tempo = 0.000125; #0.0000625
  54.  
  55. tempoIntervalo = length(arrayNumDiv)/32;
  56. timeframe = (0 : tempo : tempoIntervalo - tempo)';
  57. onda = sin(2 * pi * frequencia * timeframe);
  58. ondaAux = sin(2 * pi * frequencia * timeframeAux);
  59.  
  60. tamanhoSeg = (length(onda) / length(arrayNumDivNRZ)); # Descobre o tamanho de cada segmento.
  61.  
  62. i = 1;
  63. j = 1;
  64. k = tamanhoSeg;
  65. contadorOndaAux = 1;
  66.  
  67. # refazer essa merda
  68. while (j <= length(arrayNumDivNRZ))
  69.   if (arrayNumDivNRZ(j) == -1)
  70.     while (i <= k)
  71.       onda(i) = 0;
  72.       contadorOndaAux = 1;
  73.       i++;  
  74.     endwhile
  75.   elseif (arrayNumDivNRZ(j) == 1)
  76.     while (i <= k)
  77.       onda(i) = ondaAux(contadorOndaAux);
  78.       contadorOndaAux++;
  79.       i++;
  80.     endwhile
  81.   endif
  82.   i = k;
  83.   k = k + tamanhoSeg;
  84.   j++;
  85. endwhile
  86.  
  87. subplot(3, 1, 3);
  88. plot(timeframe, onda);
  89. axis([0 (tempoIntervalo - tempo) -1.2 1.2]);
  90. grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement