0% found this document useful (0 votes)
13 views7 pages

Discrete Signal Generation and Convolution

Uploaded by

nandhiniammu1139
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views7 pages

Discrete Signal Generation and Convolution

Uploaded by

nandhiniammu1139
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM:

#include<stdio.h>
#include<math.h>
float x[100];
void main()
{
float A,fs,f;
int i,n,k;
int choice;
printf("\n generation of discrete time signals");
printf("\n enter the frequency of analog signal f=");
scanf("%f",&f);
printf("\n enter the sampling frequency fs=");
scanf("%f",&fs);
printf("\n enter the choice");
printf("\n sine waveform(enter 1)");
printf("\n cosine waveform(enter 2)");
printf("\n square waveform(enter 3)");
printf("\n exponential waveform(enter 4)");
printf("\n Random noise(enter 5)");
scanf("%d",&choice);
i=50;
A=1.0;
switch(choice)
{
case 1:
for(n=0;n<i;n++)
x[n]=A*sin(2*3.14*f*(n/fs));
break;
case 2:
for(n=0;n<i;n++)
x[n]=A*cos(2*3.14*f*(n/fs));
break;
case 3:
k=0;
do
{
for(n=((k*fs)/(2*f));n<(((k+1)*fs)/(2*f));n++)
{
x[n]=A;
if(n>i)
break;
}
for(n=(((k+1)*fs)/(2*f));n<(((k+2)*fs)/(2*f));n++)
{
x[n]=-A;
if(n>i)
break;
}
k=k+2;
}
while(n<i);
break;
case 4:
for(n=0;n<i;n++)
x[n]=A*exp(-(100*n/fs));
break;
case 5:
for(n=0;n<i;n++)
x[n]=(rand()%1000)/1000.0;
break;
}
for(n=0;n<i;n++)
printf("\n the output x[%d]=%f",n,x[n]);
}
PROGRAM:
#include<stdio.h>
#include<math.h>
void main()
{
int x[30],h[30],y[30];
int N1,N2,N,i,j;
printf("\n Computation of linear convolution");
printf("\n enter the length of the first sequence N1=");
scanf("%d",&N1);
printf("\n enter the length of the second sequence N2=");
scanf("%d",&N2);
printf("\n enter the first sequence x(n) \n");
for(i=0;i<N1;i++)
{
printf("x[%d]=",i);
scanf("%d",&x[i]);
}
printf("\n enter the second sequence h(n) \n");
for(i=0;i<N2;i++)
{
printf("h[%d]=",i);
scanf("%d",&h[i]);
}
N=N1+N2-1;
for(i=N1;i<N;i++)
x[i]=0;
for(i=N2;i<N;i++)
h[i]=0;
for(i=0;i<N;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]=y[i]+(x[j]*h[i-j]);
}
printf("the output sequence y(n)");
for(i=0;i<N;i++)
printf("\n y[%d]=%d",i,y[i]);
}
PROGRAM:
#include<stdio.h>
#include<math.h>
void main()
{
int x1[30],x2[30],x3[30];
int N1,N2,N,i,j,k;
printf("\n Computation of circular convolution");
printf("\n enter the length of the first sequence N1=");
scanf("%d",&N1);
printf("\n enter the length of the second sequence N2=");
scanf("%d",&N2);
printf("\n enter the first sequence x1(n) \n");
for(i=0;i<N1;i++)
{
printf("x1[%d]=",i);
scanf("%d",&x1[i]);
}
printf("\n enter the second sequence x2(n) \n");
for(i=0;i<N2;i++)
{
printf("x2[%d]=",i);
scanf("%d",&x2[i]);
}
if(N1>=N2)
N=N1;
else
N=N2;
for(i=N1;i<N;i++)
x1[i]=0;
for(i=N2;i<N;i++)
x2[i]=0;
for(i=0;i<N;i++)
{
x3[i]=0;
for(j=0;j<N;j++)
{
if((i-j)>=0)
k=i-j;
else
k=i-j+N;
x3[i]=x3[i]+(x1[j]*x2[k]);
}
}
printf("the output sequence x3(n)");
for(i=0;i<N;i++)
printf("\n x3[%d]=%d",i,x3[i]);
}

You might also like