This program is for implementing Walsh Matrix.
#include <stdio.h>
#include <conio.h>
#include <math.h>
int walsh[8][8]={1};
int walshnxt[8][8]={0};
void copy(int cnt)
{
int i, j, k;
for(i=0; i<cnt; i++)
{
for(j=0; j<cnt/2; j++)
{
if(i < cnt/2)
{
walshnxt[i][j]=walsh[i][j];
walshnxt[i][j+(cnt/2)]=walsh[i][j];
}
else
{
k=i-(cnt/2);
walshnxt[i][j]=walsh[k][j];
if(walsh[k][j] == 1)
walshnxt[i][j+(cnt/2)]=-1;
else
walshnxt[i][j+(cnt/2)]=1;
}
}
}
for(i=0; i<7; i++)
{
for(j=0; j<7; j++)
{
walsh[i][j]=walshnxt[i][j];
}
}
}
void main()
{
int num, i, j, cntr;
clrscr();
printf("Enter the power of 2: ");
scanf("%d", &num);
walsh[0][0]=1;
cntr=1;
for(i=2; i <= pow(2, num);i=pow(2, cntr))
{
copy(i);
cntr++;
}
printf("\n\n\n");
if(num==0)
printf("\t1");
else
for(i=0;i<pow(2,num);i++)
{
for(j=0;j<pow(2,num);j++)
{
printf("\t %d", walshnxt[i][j]);
}
printf("\n");
}
getch();
}
#include <stdio.h>
#include <conio.h>
#include <math.h>
int walsh[8][8]={1};
int walshnxt[8][8]={0};
void copy(int cnt)
{
int i, j, k;
for(i=0; i<cnt; i++)
{
for(j=0; j<cnt/2; j++)
{
if(i < cnt/2)
{
walshnxt[i][j]=walsh[i][j];
walshnxt[i][j+(cnt/2)]=walsh[i][j];
}
else
{
k=i-(cnt/2);
walshnxt[i][j]=walsh[k][j];
if(walsh[k][j] == 1)
walshnxt[i][j+(cnt/2)]=-1;
else
walshnxt[i][j+(cnt/2)]=1;
}
}
}
for(i=0; i<7; i++)
{
for(j=0; j<7; j++)
{
walsh[i][j]=walshnxt[i][j];
}
}
}
void main()
{
int num, i, j, cntr;
clrscr();
printf("Enter the power of 2: ");
scanf("%d", &num);
walsh[0][0]=1;
cntr=1;
for(i=2; i <= pow(2, num);i=pow(2, cntr))
{
copy(i);
cntr++;
}
printf("\n\n\n");
if(num==0)
printf("\t1");
else
for(i=0;i<pow(2,num);i++)
{
for(j=0;j<pow(2,num);j++)
{
printf("\t %d", walshnxt[i][j]);
}
printf("\n");
}
getch();
}