Mã C# cho pp1 tạm gọi pp 3T 
File txt dữ liệu và hình ảnh với giá trị 11001010 bit thấp phát trước.

Code:
using System;
namespace FSK
{
class FSKClass
{
static int InputValue = 0;
static int Phase = 0;
static int PhaseShift = 0;
static int FS = 8000;
static int F0 = 1300;
static int F1 = 2100;
static int DeltaW0;
static int DeltaW1;
static System.IO.StreamWriter file;
[STAThread]
static void Main(string[] args)
{
DeltaW0 = Round(360*F0/FS);
DeltaW1 = Round(360*F1/FS);
InputValue = 202;
file = new System.IO.StreamWriter("c:\\test.txt");
FSK();
file.Close();
Console.ReadLine();
}
static void FSK()
{
for (int i=0; i<=40000;i++)
{ if ((i % 750) == 0) SampleInt();
if ((i % 5000) == 0) BaudInt(i);
}
}
static void SampleInt()
{
Phase += PhaseShift;
if (Phase >= 360) Phase = Phase - 360;
file.WriteLine("{0}",LookupSin(Phase));
}
static void BaudInt(int i)
{
if (i!=0) Phase += Round(PhaseShift*(i % 750)/750);
if ((InputValue & 1) == 0)
{
PhaseShift = DeltaW0;
}
else
{
PhaseShift = DeltaW1;
}
Console.WriteLine("{0} {1}",InputValue & 1,PhaseShift);
InputValue = InputValue >> 1;
if (i!=0) Phase -= Round(PhaseShift*(i % 750)/750);
}
static int LookupSin(int degrees)
{
return Round((1+Math.Sin(Math.PI*degrees/180))*2048);
}
static int Round(double v)
{
return System.Convert.ToInt32(v);
}
}
}

Comment