#include <stdio.h>
#include <stdlib.h>
#define NUMBER_OF_SEQUENCES 8
#define IS_ORTHOGONAL 0
#define IS_NOT_ORTHOGONAL -1
#define N_NODES 4
typedef struct {
int chip[NUMBER_OF_SEQUENCES];
} ChipSeq;
void PrintChipSeq(ChipSeq *X);
int Add(ChipSeq *X, ChipSeq* Y, ChipSeq *R)
{
int i;
for (i=0; ichip[i] = X->chip[i] + Y->chip[i];
}
return 0;
}
int DotProduct(ChipSeq *X, ChipSeq *Y, ChipSeq *Res)
{
ChipSeq temp;
int i;
if (!X || !Y)
return -1;
for(i=0; ichip[i] = X->chip[i] * Y->chip[i];
return 0;
}
void InitChip(ChipSeq *A, int initVal)
{
int i;
for(i=0; ichip[i] = initVal;
}
int CheckOrthogonality(ChipSeq *X, ChipSeq *Y)
{
int i;
int sum = 0;
for (i=0; ichip[i] * Y->chip[i];
if (sum/NUMBER_OF_SEQUENCES == 0)
return IS_ORTHOGONAL; // it is orthogonal
else
return IS_NOT_ORTHOGONAL;
}
int RecoverBit(ChipSeq *S, ChipSeq *SenderSeq)
{
int i;
int sum=0;
for(i=0; ichip[i] * SenderSeq->chip[i];
return (sum/NUMBER_OF_SEQUENCES <= 0 ? 0 : 1); } int Negative(ChipSeq *A, ChipSeq *Comp) { int i; for(i=0; ichip[i] = -(A->chip[i]);
}
void PrintChipSeq(ChipSeq *X)
{
int i;
printf("[ ");
for (i=0; ichip[i]);
printf("]");
}
void CopySeq(ChipSeq* src, ChipSeq* dest)
{
if (src && dest)
memcpy(dest, src, sizeof(ChipSeq));
}
void ConvertToBipolar(ChipSeq *A, ChipSeq *Bip)
{
int i;
for(i=0; ichip[i] == 1)
Bip->chip[i] = 1;
if (A->chip[i] == 0)
Bip->chip[i] = -1;
}
}
void Send(int n, int bit[], ChipSeq node[], ChipSeq *S)
{
ChipSeq bp[N_NODES], temp;
int i,j;
if (n>N_NODES) return;
for(i=0; iif (bit[i]==1)
CopySeq(&node[i], &bp[i]);
else
Negative(&node[i], &bp[i]);
}
memset(S, 0, sizeof(ChipSeq));
for(i=0; iAdd(S, &bp[i], S);
}
}
int GenerateRandom(void)
{
return random() % 2;
}
int main(int argc, char *argv[])
{
int i,j;
ChipSeq node[4] = { {{0, 0, 0, 1, 1, 0, 1, 1}},
{{0, 0, 1, 0, 1, 1, 1, 0}},
{{0, 1, 0, 1, 1, 1, 0, 0}},
{{0, 1, 0, 0, 0, 0, 1, 0}}
};
ChipSeq temp, b[N_NODES], s;
int bit[N_NODES];
time_t t;
for(i=0; iprintf("Node[%u] = ", i);
PrintChipSeq(&node[i]);
printf("\n");
ConvertToBipolar(&node[i], &b[i]);
printf("Bipolar(node[%u]) = ", i);
PrintChipSeq(&b[i]);
printf("\n");
}
for (i=0; ifor(j=i+1; j if (CheckOrthogonality(&b[i], &b[j])==IS_ORTHOGONAL)
printf("Node[%u] & node[%u] is orthogonal\n", i, j);
else {
printf("Node[%u] & node[%u] is NOT orthogonal\n", i, j);
exit(0);
}
}
}
time(&t);
srandom(t);
for (i=0; i<100; i++) {
bit[0] = GenerateRandom();
bit[1] = GenerateRandom();
bit[2] = GenerateRandom();
bit[3] = GenerateRandom();
printf("Send: A=%u B=%u C=%u D=%u\n", bit[0], bit[1], bit[2], bit[3]);
Send(N_NODES, bit, b, &s);
printf("S = !A + !B + !C + !D = ");
PrintChipSeq(&s);
printf("\n");
printf("Recover bit from A: S*A\n");
printf("Bit sent from A was: %d\n", RecoverBit(&s, &b[0]));
printf("\n");
printf("Recover bit from B: S*B\n");
printf("Bit sent from B was: %d\n", RecoverBit(&s, &b[1]));
printf("\n");
printf("Recover bit from C: S*C\n");
printf("Bit sent from C was: %d\n", RecoverBit(&s, &b[2]));
printf("\n");
printf("Recover bit from D: S*D\n");
printf("Bit sent from D was: %d\n", RecoverBit(&s, &b[3]));
printf("\n");
}
}
Sunday, October 15, 2006
CDMA (2)
CDMA
#include
#include
#define NUMBER_OF_SEQUENCES 8
#define IS_ORTHOGONAL 0
#define IS_NOT_ORTHOGONAL -1
typedef struct {
int chip[NUMBER_OF_SEQUENCES];
} ChipSeq;
int Add(ChipSeq *X, ChipSeq* Y, ChipSeq *R)
{
int i;
for (i=0; i
return 0;
}
int DotProduct(ChipSeq *X, ChipSeq *Y, ChipSeq *Res)
{
ChipSeq temp;
int i;
if (!X || !Y)
return -1;
for(i=0; i
return 0;
}
void InitChip(ChipSeq *A, int initVal)
{
int i;
for(i=0; i
}
int CheckOrthogonality(ChipSeq *X, ChipSeq *Y)
{
int i;
int sum = 0;
for (i=0; i
if (sum/NUMBER_OF_SEQUENCES == 0)
return IS_ORTHOGONAL; // it is orthogonal
else
return IS_NOT_ORTHOGONAL;
}
int RecoverBit(ChipSeq *S, ChipSeq *SenderSeq)
{
int i;
int sum=0;
for(i=0; i
return sum/NUMBER_OF_SEQUENCES;
}
int Negative(ChipSeq *A, ChipSeq *Comp)
{
int i;
for(i=0; i
}
void PrintChipSeq(ChipSeq *X)
{
int i;
printf("[ ");
for (i=0; i
printf("]");
}
void CopySeq(ChipSeq* src, ChipSeq* dest)
{
memcpy(&dest, &src, sizeof(ChipSeq));
}
void ConvertToBipolar(ChipSeq *A, ChipSeq *Bip)
{
int i;
for(i=0; i
Bip->chip[i] = 1;
if (A->chip[i] == 0)
Bip->chip[i] = -1;
}
}
int main(int argc, char *argv[])
{
ChipSeq A = { {0, 0, 0, 1, 1, 0, 1, 1}};
ChipSeq B = { {0, 0, 1, 0, 1, 1, 1, 0}};
ChipSeq C = { {0, 1, 0, 1, 1, 1, 0, 0}};
ChipSeq D = { {0, 1, 0, 0, 0, 0, 1, 0}};
ChipSeq temp, ba, bb, bc, bd, ca, cb, cc, cd, sum;
printf("A = ");
PrintChipSeq(&A);
printf("\n");
ConvertToBipolar(&A, &ba);
printf("Bipolar(A) = ");
PrintChipSeq(&ba);
printf("\n");
printf("B = ");
PrintChipSeq(&B);
printf("\n");
ConvertToBipolar(&B, &bb);
printf("C = ");
PrintChipSeq(&C);
printf("\n");
ConvertToBipolar(&C, &bc);
printf("D = ");
PrintChipSeq(&D);
printf("\n");
ConvertToBipolar(&C, &bd);
// A + B + C sends 0 bits
Negative(&ba, &ca);
printf("!A = "); PrintChipSeq(&ca); printf("\n");
Negative(&bb, &cb);
printf("!B = "); PrintChipSeq(&cb); printf("\n");
Negative(&bc, &cc);
printf("!C = "); PrintChipSeq(&cc); printf("\n");
// now add
Add(&ca, &cb, &temp);
Add(&temp, &cc, ∑);
printf("S = !A + !B + !C = ");
PrintChipSeq(∑);
printf("\n");
printf("Recover bit from A: S*A\n");
printf("Bit sent from A was: %d\n", RecoverBit(∑, &A));
printf("\n");
printf("Recover bit from B: S*B\n");
printf("Bit sent from B was: %d\n", RecoverBit(∑, &B));
printf("\n");
printf("Recover bit from C: S*C\n");
printf("Bit sent from C was: %d\n", RecoverBit(∑, &C));
printf("\n");
}
Sunday, October 1, 2006
25 Ultimate PC Tools
Disk Space Analyzer: WinDirStat at windirstat.sourceforge.net
File Shredder at www.handybits.com/shredder
Firewall: ZoneAlarm at www.zonelabs.com
Anti-Spyware: A-Squared at www.emsisoft.com/en/software/free/
Anti Virus: AVG Free Edition at free.grisoft.com
Rootkit Scanner: Blacklight at www.f-secure.com/blacklight
Anti-Malware: HijackThis at www.merijn.org
System Profiler: Blearc Advisor at www.belarc.com/free.download.html
Fan Controller: SpeedFan at www.almico.com/speedfan.php
File Monitor: Unlocker at ccollomb.free.fr/unlocker
USB Boot Management at tinyurl.com/kaytz
File Management: ExplorerXP at www.explorerxp.com
File Encryption: TrueCrypt at www.truecrypt.org
Notebook Power Management at www.pbus-167.com/nhc/nhc.htm
Windows Installer Manager: nLite at www.nliteos.com
System Recovery: BartPE at www.nu2.nu/pebuilder
Spam Filter: SpamPal www.spampal.org
LCD Maintenance: UDPixel at udpix.free.fr
Clipboard Recorder: www.lw-works.com
Saturday, September 30, 2006
Who says Google is Everything?
Thursday, September 28, 2006
Life is getting easier with these Protocols
1-WIRE is another protocol invented by Dallas Semiconductor. It is slower than I2C, but requires only one line (besides ground) to communicate. The line even can carry power too.
Another protocol is the popular USB. The newer is USB 2.0. It is standardized by IEEE with name IEEE 1284 This bus can also carry power and the speed is much higher than the two above. The speed can go upto 480 MBps (raw bits). The speed of USB 1.0 is 12 Mbps. From programming perspective, it is more diffcult to program than the other two. The protocol is mostly used in the PC world (including Apple Mac OS and Linux).
Firewire is also a good protocol, but seems is now not as popular as USB. Actually, Firewire (known also as I.LINK or IEEE 1394) was the first protocol that passed 100 Mbps rate.
Going down to internal microprocessor, there is HyperTransport from AMD and FrontSide Bus (FSB) from Intel. These protocols mostly used to communicate among modules in the same chip.
There are many other protocols, but seem they are not as popular as the above.
Why Windows Sucks
Another reason is that there is many copies of DLL files in my computer (either at home or at work). There are some common DLL files located in different folder. There is no concept of creating symbolic link in Windows. If you move the duplicate DLL from one folder to another file, the application from the folder where the DLL missing may not be working. In Linux (or Unix in general), you could just create a symbolic link, then the application will just treat the symbolic file as it is a real file.
Another reason is, it is not designed for automation. It is not common for people to write a script to do automation. Although Win2000 and up have this what so called "command shell, manytimes the Windows command shell is useless).
But, I still cannot get rid of my Windows (sigh). Many applications on my computer are windows-only. From tax reporting tool, games, to development software are still under Windows. Besides, Linux is still immature in its GUI (it is far to be a desktop GUI). I admit, from GUI perspective, Windows is much faster than Linux. This is because Windows is developed with GUI in mind from ground up, while Linux is actually a text based OS with GUI running just as another application in user level environment.