I am getting segmentation fault. after using gdb debugger i got error at 17th line viz. printf("\nGive Amplitude for the sinusoidal signal");
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
float check(float x)
{
int d;
float f;
d=x;
f=x+0.5;
return f;
}
int main()
{
int i,l,t_1,t_2,j;
float f,v,t,n_s,t_s,delta,q_value,y,x[l],p;
printf("\nGive Amplitude for the sinusoidal signal");
scanf("%f",&v);
printf("\nGive frequency value for the signal");
scanf("%f",&f);
printf("\nThe bandwidth for the sinusoidal signal is its frequency itself since it has constant frequency\n");
n_s=2f;
printf("\nThe nyquist rate of sampling is %.2f\n",n_s);
t_s=1/n_s;
printf("\nGive the amount of levels into which you divide the amplitude range into");
scanf("%d",&l);
delta=(2v)/l;
printf("\nGive the time period between which you want to sample the signal\nt_1=");
scanf("%d",&t_1);
printf("\nt_2=");
scanf("%d",&t_2);
p=-1v/delta+delta;
for(i=0;i<l;i++)
{
x[i]=p;
p+=delta;
}
for(t=t_1;t<=t_2;t+=t_s)
{
y=vsin(2PIf*t);
printf("\nOriginal value at t=%.2f is %.2f",t);
printf("\nNormalised PAM=%.2f",y/delta);
q_value=check(y);
printf("\nNormalised Quantised value=%.2f",q_value);
for(j=0;j<l;j++)
{
if(q_value<x[j] && q_value>x[j]-delta)
break;
}
printf("\nQuantization code=%d\n\n",j);
}
return 0;
}