We’d love to hear any feedback or comment from you!

###### Engineering · Computer Science
Question details

convert this java code to c#

//Define the class for binary FSK modulation and de-modulation
public class BinaryFSK {
// Driver method main
public static void main(String args[]) {
// Define array for Binary Information
int x[] = { 1, 0, 0, 1, 1, 0, 1 };

// Define variable for bit period
double bp = 0.000001;

// Display Binary information
System.out.println("Binary information at Trans mitter: ");
for (int i = 0; i < x.length; i++)
System.out.print(x[i] + " ");

// XX representation of transmitting binary information as digital signal XXX
int se[] = new int[100];
int bit[] = new int[700];
int j = 0;
for (int n = 0; n < x.length; n++) {
if (x[n] == 1) {
// Initialize the array se
for (int i = 0; i < 100; i++) {
se[i] = 1;

// Update the bit array
bit[j++] = se[i];
}
}

else if (x[n] == 0) {
// Initialize the array se
for (int i = 0; i < 100; i++) {
se[i] = 0;

// Update the bit array
bit[j++] = se[i];
}
}
}

// Initialize the t1 array
double t1[] = new double[700];
j = 0;
for (double i = (bp / 100); i <= 100 * x.length * (bp / 100); i = i + (bp / 100))
t1[j++] = i;

// XXXXXXXXXXXXXXXXXXXXXXXXXXX Binary-FSK modulation XXXXXXXXXXXXXXX
int A = 5; // Amplitude of carrier signal
double br = 1 / bp; // bit rate
double f1 = br * 8; // Carrier frequency for information as 1
double f2 = br * 2; // Carrier frequency for information as 0
double t2[] = new double[700];
int ss = t2.length;
double m[] = new double[700];
double y[] = new double[700];

j = 0;
for (double i = (bp / 99); i <= bp; i = i + (bp / 99))
t2[j++] = i;

j = 0;
for (int i = 0; i < x.length; i++) {
if (x[i] == 1)
for (int k = 0; k < t2.length; k++) {
y[k] = A * Math.cos(2 * Math.PI * f1 * t2[k]);

// Initialize the modulation array m
m[j++] = y[k];
}

else
for (int k = 0; k < t2.length; k++) {
y[k] = A * Math.cos(2 * Math.PI * f2 * t2[k]);

// Initialize the modulation array m
m[j++] = y[k];
}
}

double t3[] = new double[700];
j = 0;
for (double i = (bp / 99); i <= bp * x.length; i = i + (bp / 99))
t3[j++] = i;

// XXXXXXXXXXXXXXXXXX Binary FSK demodulation XXXXXXXXXXXXXXXXXXXX
// Define the array mn
double mn[] = new double[700];
double t[] = new double[700];
double y1[] = new double[700];
double y2[] = new double[700];
double mm[] = new double[700];
double mmm[] = new double[700];
double t4[] = new double[700];
double z1, z2;
long zz1;
long zz2;

j = 0;
int l = 0;
for (int n = ss; n <= m.length; n = n + ss) {
for (double i = (bp / 99); i <= bp; i = i + (bp / 99))
t[j++] = i;

for (int i = 0; i < t.length; i++) {
y1[i] = Math.cos(2 * Math.PI * f1 * t[i]); // Carrier signal for information 1
y2[i] = Math.cos(2 * Math.PI * f2 * t[i]); // Carrier signal for information 0

for (int k = n - (ss - 1); k <= n; k++) {
mm[k] = y1[k] * m[k];
mmm[k] = y2[k] * m[k];
for (double o = (bp / 99); o <= bp; o = o + (bp / 99))
t4[l++] = o;

z1 = integrate(t4, mm, 0, 10); // Integration
z2 = integrate(t4, mmm, 0, 10); // Integration

zz1 = Math.round(2 * z1 / bp);
zz2 = Math.round(2 * z2 / bp);

}
}
}
j = 0;
for (double k = (bp / 100); k <= 100 * mn.length * (bp / 100); k = k + (bp / 100))
t4[j++] = k;
}

// Definition of method integrate
static double integrate(double t4[], double mm[], int a, int b) {
double sum = 0.5 * (mm[a] + mm[b]);
double h = (b - a) / 100;
for (int i = 0; i < mm.length; i++) {
double x = a + h * i;
sum = sum + mm[i] * x;
}

return sum * h;
}

}