0% found this document useful (0 votes)
57 views

Convolucion Circular MATLAB

The document describes code for circular convolution in C. It defines a conv function that takes in two vectors and their dimensions and performs a circular convolution to produce a resulting vector. The main function prompts the user for input vector dimensions, initializes the vectors, calls the conv function, and prints out the results. It handles cases where the first vector dimension is less than or greater than the second.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Convolucion Circular MATLAB

The document describes code for circular convolution in C. It defines a conv function that takes in two vectors and their dimensions and performs a circular convolution to produce a resulting vector. The main function prompts the user for input vector dimensions, initializes the vectors, calls the conv function, and prints out the results. It handles cases where the first vector dimension is less than or greater than the second.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Convolución Circular

Código

/*Declaración de funciones*/

void conv(int dim1,int x[],int dim2,int h[],int y[]);

/*Funcion main*/

int main()

int i;

printf("Introduzca la dimension del vector de entrada: ");

scanf("%d",&dim1);

xn = malloc(dim1 * sizeof (int));

printf("Introduce los valores del primer vector:\n");

for (i=0; i<dim1; i++) {

printf("\nElemento %d: ", i+1);

scanf("%d", &aux);

*(xn+i)= aux;

printf("\n");

printf("Introduzca la dimension del segundo vector: ");

scanf("%d",&dim2);

hn = malloc(dim2 * sizeof (int));

printf("Introduce los valores del segundo vector:\n");

for (i=0; i<dim2; i++) {

printf("\nElemento %d: ", i+1);

scanf("%d", &aux);

*(hn+i)=aux;

yn = malloc((dim1+dim2-1) * sizeof (int));

if(dim1<=dim2)

{
int dimcirc=dim2;

conv(dim1,xn,dim2,hn,yn);

printf("Dimension de la Convolucion Circular=%d \n" , dimcirc);

zn = malloc(dimcirc * sizeof (int));

zi=0

wn = malloc(dimcirc * sizeof (int));

k=dim2-dim1-2;

q=dim1+dim2-2;

for(j=dimcirc-1;j>=0;j--)

*(zn+j)=0;

*(wn+j)=0;

*(wn+j)=*((yn+(q%dimcirc))+j);

*(zn+j)=*((yn+(k%dimcirc))-j);

for(zi=0;zi<dimcirc;zi++)

printf("zn:[%d]=%d \n",zi,(*(zn-zi)+*(wn-zi)));

else

int dimcirc=dim1;

paux = xn;

xn = hn;

hn = paux;

conv(dim2,xn,dim1,hn,yn);

printf("Dimension de la Convolucion Circular=%d \n" , dimcirc);

zn = malloc(dimcirc * sizeof (int));

zi=0;

wn = malloc(dimcirc * sizeof (int));


k=dim1-dim2-2;

q=dim1+dim2-2;

for(j=dimcirc-1;j>=0;j--)

*(zn+j)=0;

*(wn+j)=0;

*(wn+j)=*((yn+(q%dimcirc))+j);

*(zn+j)=*((yn+(k%dimcirc))-j);

for(zi=0;zi<dimcirc;zi++)

printf("zn:[%d]=%d \n",zi,(*(zn-zi)+*(wn-zi)));

void conv(int dim1,int x[],int dim2,int h[],int y[])

/*Declaro e Inicializo las variables contador de los vectores*/

int xi=0,yi=0,hi=0;

int dimres=dim1+dim2-1;

printf("Dimensión de la Convolución Lineal=%d \n",dimres);

for(xi=0;xi<dim1;xi++)

for(hi=0;hi<dim2;hi++)

y[xi+hi]=(y[xi+hi]+x[xi]*h[hi]);

for(yi=0;yi<dimres;yi++)

{ printf("yn:[%d]=%d \n",yi,y[yi]);

}
}

MATLAB

You might also like