Skip to content
This repository was archived by the owner on Dec 6, 2021. It is now read-only.

Commit f4e5b2a

Browse files
author
OverPoweredDev
committed
added bipolar encoding
1 parent 380fc7f commit f4e5b2a

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![banner](https://github.com/OverPoweredDev/SignalPlotter/blob/master/images/bannerproj.png?raw=true)
22

3-
It's just a simple Program that uses either python or C++ to plot digital Signals in simple encodings like RZ, NRZ-L, NRZ-I, Manchester and Differential Manchester
3+
It's just a simple Program that uses either python or C++ to plot digital Signals in simple encodings like RZ, NRZ-Linear, NRZ-Inverted, Bipolar Encoding, Manchester and Differential Manchester
44

55
Made it because in true CSE Student fashion, I decided to automate in an hour what would've been a 2 minute homework assignment
66

cpp_implementation/plotter

392 Bytes
Binary file not shown.

cpp_implementation/plotter.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ string getSignal() {
2323
int getEncoding() {
2424
int choice;
2525
cout
26-
<< "Choose a type of Encoding\n1) Unipolar NRZ\n2) Polar NRZ\n3) NRZ Inverted\n4) RZ\n5) Manchester\n6) Differential Manchester"
26+
<< "Choose a type of Encoding\n1) Unipolar NRZ\n2) Polar NRZ\n3) NRZ Inverted\n4) Bipolar\n5) RZ\n6) Manchester\n7) Differential Manchester"
2727
<< endl;
2828
cin >> choice;
2929
return choice;
@@ -68,6 +68,7 @@ class Encoding {
6868

6969
class Unipolar_NRZ : Encoding {
7070
private:
71+
7172
int logic_low = 0;
7273

7374
public:
@@ -172,6 +173,42 @@ class RZ : Encoding {
172173
}
173174
};
174175

176+
class Bipolar : Encoding {
177+
private:
178+
179+
int prev = 0;
180+
181+
public:
182+
explicit Bipolar(string sgn) : Encoding(sgn) {};
183+
184+
void draw() {
185+
for (char c: signal) {
186+
if (c == '1') {
187+
one(prev);
188+
prev = prev == 0 ? 1 : 0;
189+
}
190+
else
191+
zero();
192+
}
193+
}
194+
195+
void zero() {
196+
signalShift(pos_x, 100 + base);
197+
signalMove(distance, 0);
198+
}
199+
200+
void one(int num) {
201+
if (num == 0) {
202+
signalShift(pos_x, 100 + (logic_high/2));
203+
signalMove(distance, 0);
204+
}
205+
else {
206+
signalShift(pos_x, 100 + (logic_low/2));
207+
signalMove(distance, 0);
208+
}
209+
}
210+
};
211+
175212
class Manchester : Encoding {
176213
public:
177214
explicit Manchester(string sgn) : Encoding(sgn) {};
@@ -256,16 +293,21 @@ int main() {
256293
break;
257294
}
258295
case 4: {
259-
RZ signal(sgn);
296+
Bipolar signal(sgn);
260297
signal.draw();
261298
break;
262299
}
263300
case 5: {
264-
Manchester signal(sgn);
301+
RZ signal(sgn);
265302
signal.draw();
266303
break;
267304
}
268305
case 6: {
306+
Manchester signal(sgn);
307+
signal.draw();
308+
break;
309+
}
310+
case 7: {
269311
Diff_Manchester signal(sgn);
270312
signal.draw();
271313
break;

0 commit comments

Comments
 (0)