Question

Encoding Simulator, Use JavaScript or similar to encode NRZ(X-Z wildcard), NRZ-I(U-W), Bipolar AMI (P-T), Pseudoternary(K-O), Manchester(F-J),...

Encoding Simulator, Use JavaScript or similar to encode NRZ(X-Z wildcard), NRZ-I(U-W), Bipolar AMI (P-T), Pseudoternary(K-O), Manchester(F-J), Diff. Manchester(A-E)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Save below code as .html extension

===========================================================================================

NRZ-I(U-W) :

<!DOCTYPE html>
<html>
<head>
   <title>NRZ-L</title>
   <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,700,900' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.1.0/particles.min.js"></script>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
   <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/typed.js/1.1.7/typed.min.js" type="text/javascript"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="../topics.css">
</head>
<body>
<header>
<div class="container" style="margin: 0;">
<div class="header-section">
<div id="particles-js">
</div>
<div class="header-font center-align">
  
<span class="topic">NRZ-L</span>
</div>
</div>
</div>
</header>

<div class="container">
<div class="row" style="margin-top: 30px; margin-bottom: 40px;">
<div class="col s12 m12 l6">
<div style="background-color: #DEDEDE;" id="terminal">
<center>About NRZ-L</center>
<div class="black white-text" id="black-screen">
<div class="details">
<span id="about_nrz-l"></span>
</div>
</div>
</div>
</div>
<div class="col s12 m12 l6" id="data-entry" style="padding-top: 30px;">
<div class="row">
<div class="input-field col s5">
<input id="data_bit" type="text" class="validate">
<label for="data_bit">Enter Data Bit</label>
</div>
<div class="input-field col s5">
<input id="voltage" type="text" class="validate">
<label for="voltage">Enter Voltage</label>
</div>
<div class="" style="padding-top: 13px;">
<button class="btn waves-effect waves-light" id="submit">Generate Graph
<i class="material-icons right">send</i>
</button>
</div>
</div>
</div>
</div>
</div>
  
<div id="nrz_l">
</div>


<script >
var string = "";
string+="In NRZ-L the level of voltage determines the value of the bit.<br>"
string+="Rules:<br>"
string+="• 0 bit is represented by +V<br>"
string+="• 1 bit is represented by -V."

// Typing Content
$("#about_nrz-l").typed({
strings: [
string
],
typeSpeed: 0,
});

$(document).ready(function () {

   particlesJS.load('particles-js', '../particles.json', function() {
       console.log('callback - particles.json config loaded');
   });

   $('#terminal').height(1.3 * $('#data-entry').height());
   $('#submit').click(function(){
      
       //Reading the value of databits and voltage
      
       var data_bit = $('#data_bit').val();
       var voltage = $("#voltage").val();
      
       //Checking if the user has not entered the databits and voltage
      
       if(data_bit==="" && voltage==="")
       {
           Materialize.toast('Please enter data bits and voltage', 1000, 'black')
       }
       else if(data_bit==="") //Checking if the user has not entered the databits
       {
           Materialize.toast('Please enter data bits', 1000, 'black')  
       }
       else if(voltage==="") //Checking if the user has not entered the voltage
       {
           Materialize.toast('Please enter voltage', 1000, 'black')  
       }
       else
       {
           console.log(data_bit);
           console.log(voltage);  
           arr_databit = data_bit.toString();
           var proper = true;
           var count=0;
           for(i=0;i<arr_databit.length;i++)
           {
               if(arr_databit[i]==="0" || arr_databit[i]==="1")
               {
                   count++;
               }
           }
           if(count!==arr_databit.length)   
           {   
               proper=false;
           }
          
           //Checking if the user has not entered numerical voltage and proper databits
           if(!Number(voltage) && !proper)
           {
               Materialize.toast('Please enter numerical value of voltage only, and binary databits only', 2000, 'black');
           }
           else if(!Number(voltage)) //check if voltage is not correct
           {  
               Materialize.toast('Please enter numerical value of voltage only', 2000, 'black');
           }
           else if(!proper) //check if databits are not proper
           {
               Materialize.toast('Please enter binary databits only', 2000, 'black');
           }
           else
           {
               console.log(arr_databit);
               var x_axis=[];
               var y_axis = [];
               var i=0;
               var k=0;
              
               //Initial Setting for time=0
              
              
               if(arr_databit[0]==0) //According to NRZ-L if databit is 0
               { //Then y-axis should have positive voltage
                   x_axis[k] = k;
                   y_axis[k] = 1*voltage;
               }
               else //If databit is 1 the y-axis should have
               { //negative voltage
                   x_axis[k] = k;
                   y_axis[k] = -1*voltage;  
               }
               k++;
              
               //For every databit NRZ-L rules are followed
              
              
               for(var i=0;i<arr_databit.length;i++)
               {  
                   if(arr_databit[i]==1)
                   {  
                       x_axis[k] = k;
                       y_axis[k] = -1*voltage;
                   }
                   else
                   {
                       x_axis[k] = k;
                       y_axis[k] = 1*voltage;  
                   }
                   k++;
               }

               console.log(x_axis);
               console.log(y_axis);

               //settings done to plot the graph
              
               var trace4 = {
               x: x_axis,
               y: y_axis,
               mode: 'lines+markers',
               name: 'vh',
               line: {shape: 'vh'},
               type: 'scatter'
               };


               var data = [trace4];

               var layout = {legend: {
               y: 0,
               traceorder: 'reversed',
               font: {size: 16},
               yref: 'paper'
               }};

               //plotly called to plot the graph
              
               Plotly.newPlot('nrz_l', data, layout);
           }
       }
      
   });
})

</script>

</body>
</html>

===============================================================================================

Bipolar AMI (P-T) :

<!DOCTYPE html>
<html>
<head>
   <title>Polar Line Encoding</title>
   <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,700,900' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.1.0/particles.min.js"></script>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/typed.js/1.1.7/typed.min.js" type="text/javascript"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="../topics.css">
</head>
<body>
  
<header>
<div class="container" style="margin: 0;">
<div class="header-section">
<div id="particles-js">
</div>
<div class="header-font center-align">
<span class="topic">Bipolar Line Encoding</span>
</div>
</div>
</div>
</header>

<div class="container">
<div class="row" style="margin-top: 30px; margin-bottom: 40px;">
<div class="col s12 m12 l6">
<div style="background-color: #DEDEDE;" id="terminal">
<center>About Bipolar Line Encoding</center>
<div class="black white-text" id="black-screen">
<div class="details">
<span id="about_bipolar"></span>
</div>
</div>
</div>
</div>
<div class="col s12 m12 l6" id="data-entry" style="padding-top: 30px;">
<div class="row">
<div class="input-field col s5">
<input id="data_bit" type="text" class="validate">
<label for="data_bit">Enter Data Bit</label>
</div>
<div class="input-field col s5">
<input id="voltage" type="text" class="validate">
<label for="voltage">Enter Voltage</label>
</div>
<div class="" style="padding-top: 13px;">
<button class="btn waves-effect waves-light" id="submit">Generate Graph
<i class="material-icons right">send</i>
</button>
</div>
</div>
</div>
</div>
</div>

<h3 class="plot">Plot for AMI</h3>
<div id="ami">
</div>

<h3 class="plot">Plot for NRZ-I</h3>
<div id="pseudoternary">
</div>


<!-- Floating button -->
<div class="fixed-action-btn">
<a class="btn-floating btn-large tooltipped red" data-position="left" data-tooltip="Home" href="../">
<i class="large material-icons">folder</i>
</a>
<ul>
<li><a class="btn-floating tooltipped red" data-position="left" data-tooltip="NRZ-L" href="../nrz-l"><i class="material-icons" >L</i></a></li>
<li><a class="btn-floating tooltipped yellow darken-1" data-position="left" data-tooltip="NRZ-I" href="../nrz-i"><i class="material-icons">I</i></a></li>
<li><a class="btn-floating tooltipped green" data-position="left" data-tooltip="Manchester" href="../manchester"><i class="material-icons">M</i></a></li>
<li><a class="btn-floating tooltipped blue" data-position="left" data-tooltip="Differential Manchester" href="../differential-manchester"><i class="material-icons">D</i></a></li>
<li><a class="btn-floating tooltipped black" data-position="left" data-tooltip="Polar Encodings" href="../polar"><i class="material-icons">P</i></a></li>
</ul>
<div class="fixed-action-btn horizontal">
<a class="btn-floating btn-large red" data-position="bottom" data-tooltip="Home" href="../">
<i class="large material-icons">folder</i>
</a>
<ul>
<li><a class="btn-floating tooltipped green" data-position="top" data-tooltip="Bipolar" href="../bipolar"><i class="material-icons">B</i></a></li>
<li><a class="btn-floating tooltipped blue" data-position="top" data-tooltip="Pseudoternary" href="../pseudoternary"><i class="material-icons">P</i></a></li>
<li><a class="btn-floating tooltipped black" data-position="top" data-tooltip="AMI" href="../ami"><i class="material-icons">A</i></a></li>
</ul>
</div>
</div>
<!-- End of floating button -->
</body>
<script >

$(".plot").hide();
var string = "";
string+="Here is all about Bipolar line encoding"

// Typing Content
$("#about_bipolar").typed({
strings: [
string
],
typeSpeed: 0,
});

$(document).ready(function () {
   particlesJS.load('particles-js', '../particles.json', function() {
       console.log('particles.json config loaded');
   });

   $('#terminal').height($('#data-entry').height());
  
   $('#submit').click(function(){
       //Reading the value of databits and voltage
       var data_bit = $('#data_bit').val();
       var voltage = $("#voltage").val();
       //Checking if the user has not entered the databits and voltage
       if(data_bit==="" && voltage==="")
       {
           Materialize.toast('Please enter data bits and voltage', 1000, 'black')
       }
       else if(data_bit==="") //Checking if the user has not entered the databits
       {
           Materialize.toast('Please enter data bits', 1000, 'black')  
       }
       else if(voltage==="") //Checking if the user has not entered the voltage
       {
           Materialize.toast('Please enter voltage', 1000, 'black')  
       }
       else
       {
           console.log(data_bit);
           console.log(voltage);  
           arr_databit = data_bit.toString();
           console.log(arr_databit);
           var proper = true;
           var count=0;
           for(i=0;i<arr_databit.length;i++)
           {
               if(arr_databit[i]==="0" || arr_databit[i]==="1")
               {
                   count++;
               }
           }
           //Checking if the user has entered only 0s and 1s as databits and numerical value of voltage
           if(count!==arr_databit.length)
           {
               proper=false;
           }
           if(!Number(voltage) && !proper)
           {
               Materialize.toast('Please enter numerical value of voltage only, and binary databits only', 2000, 'black');
           }
           else if(!Number(voltage)) //check if voltage is not correct
           {  
               Materialize.toast('Please enter numerical value of voltage only', 2000, 'black');
           }
           else if(!proper) //check if databits are not proper
           {
               Materialize.toast('Please enter binary databits only', 2000, 'black');
           }
           else
           {
               $(".plot").show();

               // AMI plot
               var amix_axis=[];
               var amiy_axis = [];
               var i=0;
               var k=0;
               var prev=0;
               if(arr_databit[0]==0)
               {
                   amix_axis[k] = k;
                   amiy_axis[k] = 0;
               }
               else
               {
                   amix_axis[k] = k;
                   amiy_axis[k] = 1*voltage;  
               }
               k++;
               for(var i=0;i<arr_databit.length;i++)
               {  
                   if(arr_databit[i]==1&&i==0)
                   {  
                       amix_axis[k] = k;
                       amiy_axis[k] = 1*voltage;
                       prev=1;
                      
                   }
                   else
                   {
                   if(arr_databit[i]==1)
                   {
                       if(prev==-1)
                       {
                           amix_axis[k]=k;
                           amiy_axis[k]=1*voltage;
                           prev=1;
                          
                       }
                       else if (prev==1)
                       {
                           amix_axis[k]=k;
                           amiy_axis[k]=-1*voltage;
                           prev=-1;
                          
                   }
                       else
                       {
                           amix_axis[k]=k;
                           amiy_axis[k]=1*voltage;
                           prev=1;
                       }
                   }
                   else
                   {
                       amix_axis[k]=k;
                       amiy_axis[k]=0;
                      
                   }
                      
                      
                   }
                   k++;
               }

               console.log(amix_axis);
               console.log(amiy_axis);

               var trace1 = {
               x: amix_axis,
               y: amiy_axis,
               mode: 'lines+markers',
               name: 'vh',
               line: {shape: 'vh'},
               type: 'scatter'
               };


               var data = [trace1];

               var layout = {legend: {
               y: 0,
               traceorder: 'reversed',
               font: {size: 16},
               yref: 'paper'
               }};

               Plotly.newPlot('ami', data, layout);

               // PseudoTernary Plot
               var pseudoternaryx_axis=[];
               var pseudoternaryy_axis = [];
               var i=0;
               var k=0;
               var prev=0;
               if(arr_databit[0]==1)
               {
                   pseudoternaryx_axis[k] = k;
                   pseudoternaryy_axis[k] = 0;
               }
               else
               {
                   pseudoternaryx_axis[k] = k;
                   pseudoternaryy_axis[k] = 1*voltage;  
               }
               k++;
               for(var i=0;i<arr_databit.length;i++)
               {  
                   if(arr_databit[i]==0 && i==0)
                   {  
                       pseudoternaryx_axis[k] = k;
                       pseudoternaryy_axis[k] = 1*voltage;
                       prev=1;
                   }
                   else
                   {
                   if(arr_databit[i]==0)
                   {
                       if(prev==-1)
                       {
                           pseudoternaryx_axis[k]=k;
                           pseudoternaryy_axis[k]=1*voltage;
                           prev=1;
                          
                       }
                       else if (prev==1)
                       {
                           pseudoternaryx_axis[k]=k;
                           pseudoternaryy_axis[k]=-1*voltage;
                           prev=-1;
                          
                   }
                       else
                       {
                           pseudoternaryx_axis[k]=k;
                           pseudoternaryy_axis[k]=1*voltage;
                           prev=1;
                       }
                   }
                   else
                   {
                       pseudoternaryx_axis[k]=k;
                       pseudoternaryy_axis[k]=0;
                      
                   }
                      
                      
                   }
                   k++;
               }

               console.log(pseudoternaryx_axis);
               console.log(pseudoternaryy_axis);

               var trace2 = {
               x: pseudoternaryx_axis,
               y: pseudoternaryy_axis,
               mode: 'lines+markers',
               name: 'vh',
               line: {shape: 'vh'},
               type: 'scatter'
               };


               var data = [trace2];

               var layout = {legend: {
               y: 0,
               traceorder: 'reversed',
               font: {size: 16},
               yref: 'paper'
               }};

               Plotly.newPlot('pseudoternary', data, layout);
           }
       }
      
   });
})

</script>
</html>

===============================================================================================

Pseudoternary(K-O) : (copy below code and replace with NRZ-l code's script tag )

<div id="pseudoternary"> </div> <script> var string = ""; string+="A variation of AMI encoding is called pseudoternanry.<br>" string+="Rules:<br>" string+="• 1 bit is encoded as a neutral zero voltage<br>" string+="• 0 bit is encoded as alternating positive and negative voltages." // Typing Content $("#about_pseudoternary").typed({ strings: [ string ], typeSpeed: 0, }); $(document).ready(function () { particlesJS.load('particles-js', '../particles.json', function() { console.log('callback - particles.json config loaded'); }); $('#terminal').height(1.5 * $('#data-entry').height()); $('#submit').click(function(){ //Reading the value of databits and voltage var data_bit = $('#data_bit').val(); var voltage = $("#voltage").val(); //Checking if the user has not entered the databits and voltage if(data_bit==="" && voltage==="") { Materialize.toast('Please enter data bits and voltage', 1000) } else if(data_bit==="") //Checking if the user has not entered the databits { Materialize.toast('Please enter data bits', 1000) } else if(voltage==="") //Checking if the user has not entered the voltage { Materialize.toast('Please enter voltage', 1000) } else { console.log(data_bit); console.log(voltage); arr_databit = data_bit.toString(); console.log(arr_databit); var proper = true; var count=0; for(i=0;i<arr_databit.length;i++) { if(arr_databit[i]==="0" || arr_databit[i]==="1") { count++; } } //Checking if the user has entered only 0s and 1s as databits and numerical value of voltage if(count!==arr_databit.length) { proper=false; } if(!Number(voltage) && !proper) { Materialize.toast('Please enter numerical value of voltage only, and binary databits only', 2000, 'black'); } else if(!Number(voltage)) //check if voltage is not correct { Materialize.toast('Please enter numerical value of voltage only', 2000, 'black'); } else if(!proper) //check if databits are not proper { Materialize.toast('Please enter binary databits only', 2000, 'black'); } else { var x_axis=[]; var y_axis = []; var i=0; var k=0; var prev=0; //initial setting for time=0 //1 means 0 voltage //0 means +ve voltage if(arr_databit[0]==1) { x_axis[k] = k; y_axis[k] = 0; } else { x_axis[k] = k; y_axis[k] = 1*voltage; } k++; for(var i=0;i<arr_databit.length;i++) { if(arr_databit[i]==0 && i==0) //if first bit is 0 then its +ve voltage { x_axis[k] = k; y_axis[k] = 1*voltage; prev=1; } else { if(arr_databit[i]==0) //if bit is 0 and previous voltage level is -ve { //current level is +ve if(prev==-1) { x_axis[k]=k; y_axis[k]=1*voltage; prev=1; } else if (prev==1) //if bit is 0 and previous voltage level is +ve { //current level is -ve x_axis[k]=k; y_axis[k]=-1*voltage; prev=-1; } else { x_axis[k]=k; y_axis[k]=1*voltage; prev=1; } } else //if bit=1 then 0 voltage { x_axis[k]=k; y_axis[k]=0; } } k++; } console.log(x_axis); console.log(y_axis); //setting graph specifications var trace4 = { x: x_axis, y: y_axis, mode: 'lines+markers', name: 'vh', line: {shape: 'vh'}, type: 'scatter' }; var data = [trace4]; var layout = {legend: { y: 0, traceorder: 'reversed', font: {size: 16}, yref: 'paper' }}; //calling plotly to plot the graph Plotly.newPlot('pseudoternary', data, layout); } } }); }) </script>

===============================================================================================

Manchester(F-J) : (copy below code and replace with NRZ-l code's script tag )

<div id="manchester"> </div> <script > var string = ""; string+="It is the combination of RZ and NRZ-L.<br>" string+="The duration of bit is divided into 2 halves it remains at one level in first half and other level in second half." //Typing Content $("#about_manchester").typed({ strings: [ string ], typeSpeed: 0, }); $(document).ready(function () { particlesJS.load('particles-js', '../particles.json', function() { console.log('particles.json config loaded'); }); $('#terminal').height(1.3 * $('#data-entry').height()); $('#submit').click(function(){ //Reading the value of databits and voltage var data_bit = $('#data_bit').val(); var voltage = $("#voltage").val(); //Checking if the user has not entered the databits and voltage if(data_bit==="" && voltage==="") { Materialize.toast('Please enter data bits and voltage', 1000, 'black') } else if(data_bit==="") //Checking if the user has not entered the databits { Materialize.toast('Please enter data bits', 1000, 'black') } else if(voltage==="") //Checking if the user has not entered the voltage { Materialize.toast('Please enter voltage', 1000, 'black') } else { console.log(data_bit); console.log(voltage); arr_databit = data_bit.toString(); var proper = true; var count=0; //Checking if the user has entered only 0s and 1s as databits and numerical value of voltage for(i=0;i<arr_databit.length;i++) { if(arr_databit[i]==="0" || arr_databit[i]==="1") { count++; } } if(count!==arr_databit.length) { proper=false; } if(!Number(voltage) && !proper) { Materialize.toast('Please enter numerical value of voltage only, and binary databits only', 2000, 'black'); } else if(!Number(voltage)) //check if voltage is not correct { Materialize.toast('Please enter numerical value of voltage only', 2000, 'black'); } else if(!proper) //check if databits are not proper { Materialize.toast('Please enter binary databits only', 2000, 'black'); } else { var x_axis=[]; var y_axis = []; var i=0; var k=0; //initial setting for time=0 //0 means +ve voltage //1 means -ve voltage if(arr_databit[0]=="0") { x_axis[k] = k; y_axis[k] = 1*voltage; k++; } else { x_axis[k] = k; y_axis[k] = -1*voltage; k++; } for(var i=0;i<arr_databit.length;i++) { if(arr_databit[i]=="1") //According to Manchester scheme { //If bit is 1 then first half of time voltage=-ve x_axis[k] = k; //next half its +ve y_axis[k] = -1*voltage; k++; x_axis[k] = k; y_axis[k] = 1*voltage; k++; } else //If bit is 0 then first half is +ve voltage { //next half is -ve voltage x_axis[k] = k; y_axis[k] = 1*voltage; k++; x_axis[k]=k; y_axis[k]=-1*voltage; k++; } } console.log(x_axis); console.log(y_axis); var copy_x_axis = []; var pos=0.5; copy_x_axis[0]=0; //setting graph to transit at the middle for(var i=0;i<x_axis.length;i++) { if(i!=0) { copy_x_axis[i]=pos; console.log(copy_x_axis[i]); pos+=0.5; } } //setting graph specifications var trace4 = { x: copy_x_axis, y: y_axis, mode: 'lines+markers', name: 'vh', line: {shape: 'vh'}, type: 'scatter' }; var data = [trace4]; var layout = {legend: { y: 0, traceorder: 'reversed', font: {size: 16}, yref: 'paper' }}; //calling plotly to plot the graph Plotly.newPlot('manchester', data, layout); } } }); }) </script>
===============================================================================================

Differential Manchester(A-E) : (copy below code and replace with NRZ-l code's script tag )

<div id="differential_manchester"> </div> <script > var string = ""; string+="It is the combination of RZ and NRZ-I.<br>" string+="The transition is in the middle of the bit but this time value of the bit decides which transition.<br>" string+="Rules<br>" string+="• 0 means transition<br>" string+="• 1 means no transition." // Typing Content $("#about_differentialmanchester").typed({ strings: [ string ], typeSpeed: 0, }); $(document).ready(function () { particlesJS.load('particles-js', '../particles.json', function() { console.log('particles.json config loaded'); }); $('#terminal').height(1.5 * $('#data-entry').height()); $('#submit').click(function(){ //Reading the value of databits and voltage var data_bit = $('#data_bit').val(); var voltage = $("#voltage").val(); //Checking if the user has not entered the databits and voltage if(data_bit==="" && voltage==="") { Materialize.toast('Please enter data bits and voltage', 1000, 'black') } else if(data_bit==="") //Checking if the user has not entered the databits { Materialize.toast('Please enter data bits', 1000, 'black') } else if(voltage==="") //Checking if the user has not entered the voltage { Materialize.toast('Please enter voltage', 1000, 'black') } else { console.log(data_bit); console.log(voltage); arr_databit = data_bit.toString(); console.log(arr_databit); var proper = true; var count=0; for(i=0;i<arr_databit.length;i++) { if(arr_databit[i]==="0" || arr_databit[i]==="1") { count++; } } //Checking if the user has entered only 0s and 1s as databits and numerical value of voltage if(count!==arr_databit.length) { proper=false; } if(!Number(voltage) && !proper) { Materialize.toast('Please enter numerical value of voltage only, and binary databits only', 2000, 'black'); } else if(!Number(voltage)) //check if voltage is not correct { Materialize.toast('Please enter numerical value of voltage only', 2000, 'black'); } else if(!proper) //check if databits are not proper { Materialize.toast('Please enter binary databits only', 2000, 'black'); } else { var x_axis=[]; var y_axis = []; var i=0; var k=0; //initial setting for time=0 //0 means +ve voltage //1 means -ve voltage if(arr_databit[0]=="1") { x_axis[k] = k; y_axis[k] = -1*voltage; k++; } else { x_axis[k] = k; y_axis[k] = 1*voltage; k++; } for(var i=0;i<arr_databit.length;i++) { if(arr_databit[i]=="0") //According to Differential Manchester Rules { //if the bit is 0 and previous level of voltage is +ve if(y_axis[k-1]==1*voltage) //for first half it is -ve voltage { //for second half it is +ve voltage x_axis[k] = k; //if previous level is -ve then y_axis[k] = -1*voltage; //for first half it is +ve voltage k++; //for second half it is -ve voltage x_axis[k] = k; y_axis[k] = 1*voltage; k++; } else { x_axis[k] = k; y_axis[k] = 1*voltage; k++; x_axis[k] = k; y_axis[k] = -1*voltage; k++; } } else { if(y_axis[k-1]==1*voltage) //if the bit is 1 and previous level of voltage is +ve { //for first half it is +ve voltage x_axis[k] = k; //for second half it is -ve voltage y_axis[k] = 1*voltage; //if previous level is -ve then k++; //for first half it is -ve voltage x_axis[k]=k; //for second half it is +ve voltage y_axis[k]=-1*voltage; k++; } else { x_axis[k] = k; y_axis[k] = -1*voltage; k++; x_axis[k]=k; y_axis[k]=1*voltage; k++; } } } console.log(x_axis); console.log(y_axis); //setting graph to transit at the middle var copy_x_axis = []; var pos=0.5; copy_x_axis[0]=0; for(var i=0;i<x_axis.length;i++) { if(i!=0) { copy_x_axis[i]=pos; console.log(copy_x_axis[i]); pos+=0.5; } } //setting graph specifications var trace4 = { x: copy_x_axis, y: y_axis, mode: 'lines+markers', name: 'vh', line: {shape: 'vh'}, type: 'scatter' }; var data = [trace4]; var layout = {legend: { y: 0, traceorder: 'reversed', font: {size: 16}, yref: 'paper' }}; //calling plotly to plot the graph Plotly.newPlot('differential_manchester', data, layout); } } }); }) </script>

Add a comment
Know the answer?
Add Answer to:
Encoding Simulator, Use JavaScript or similar to encode NRZ(X-Z wildcard), NRZ-I(U-W), Bipolar AMI (P-T), Pseudoternary(K-O), Manchester(F-J),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT