The document describes calculating the circular convolution of two functions using MATLAB. It provides the theory of circular convolution and describes a program that takes in two sequences, calculates their circular convolution using a for loop, and displays the output. The program output shows the circular convolution of the two example sequences [1 2 3 4 4 3 2 1] and [1 1 1 1].
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
437 views
Circular Convolution On Matlab
The document describes calculating the circular convolution of two functions using MATLAB. It provides the theory of circular convolution and describes a program that takes in two sequences, calculates their circular convolution using a for loop, and displays the output. The program output shows the circular convolution of the two example sequences [1 2 3 4 4 3 2 1] and [1 1 1 1].
The circular convolution, also known as cyclic convolution, of two a periodic function (i.e. Schwartz functions) occurs when one of them is convolved in the normal way with a periodic summation of the other function. That situation arises in the context of the Circular convolution theorem. The identical operation can also be expressed in terms of the periodic summations of both functions, if the infinite integration interval is reduced to just one period. That situation arises in the context of the discrete-time Fourier transform (DTFT) and is also called periodic convolution. In particular, the DTFT of the product of two discrete sequences is the periodic convolution of the DTFTs of the individual sequences. Let x be a function with a well-defined periodic summation, x T , where:
If h is any other function for which the convolution x T h exists, then the convolution x T h is periodic and identical to:
where t o is an arbitrary parameter and h T is a periodic summation of h. The second integral is called the periodic convolution of functions x T and h T and is sometimes normalized by 1/T. When x T is expressed as the periodic summation of another function, x, the same operation may also be referred to as a circular convolution of functions h and x. Similarly, for discrete sequences and period N, we can write the circular convolution of functions h and x as:
2
PROGRAM: - The program is given below. a=input('enter x(n):'); b=input('enter h(n):'); Nx=length(a); Nh=length(b); N=max(Nx,Nh); x=[a zeros(1,(N-Nx))]; h=[b zeros(1,(N-Nh))]; for i=1:N k=i for j=1:Nh H(i,j)=x(k)*b(j); k=k-1 if (k==0); k=N; end end end y=zeros (1,N); M=H'; for j=1:N for i=1:Nh y(j)=M(i,j)+y(i); end end disp('the output is'); disp(y); stem(y); title('circular convolution'); xlabel('n'); ylabel('y(n)');
PROGRAM OUTPUT:-
after execution
enter x(n):[1 2 3 4 4 3 2 1] enter h(n):[1 1 1 1]
the output is 7 6 7 10 13 14 13 10
3
PROGRAM OUTPUT PLOT:-
Fig.: Output Plot of circular convolution DOCUMENTATION OF PROGRAM:-
length Length of vector or largest array dimension Syntax Number of Elements = length(array) Description Number of Elements = length(array) finds the number of elements along the largest dimension of an array. array is an array of any MATLAB data type and any valid dimensions. Number Of Elements is a whole number of the MATLAB double class. For nonempty arrays, number Of Elements is equivalent to max(size(array)). For empty arrays, number Of Elements is zero. 1 2 3 4 5 6 7 8 0 2 4 6 8 10 12 14 circular convolution n y ( n )
4
Max Largest elements in array Syntax C = max(A) C = max(A,B) C = max(A,[],dim) [C,I] = max(...) Description C = max(A) returns the largest elements along different dimensions of an array. If A is a vector, max(A) returns the largest element in A. If A is a matrix, max(A) treats the columns of A as vectors, returning a row vector containing the maximum element from each column. If A is a multidimensional array, max(A) treats the values along the first non-singleton dimension as vectors, returning the maximum value of each vector. C = max(A,B) returns an array the same size as A and B with the largest elements taken from A or B. The dimensions of A and B must match, or they may be scalar. C = max(A,[],dim) returns the largest elements along the dimension of A specified by scalar dim. For example, max(A,[],1) produces the maximum values along the first dimension (the rows) of A. [C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.
5
for
Syntax for variable = expression statements end Description The general format is for variable = expression statement ... statement end The columns of the expression are stored one at a time in the variable while the following statements, up to the end, are executed. In practice, the expression is almost always of the form scalar : scalar, in which case its columns are simply scalars. The scope of for statement is always terminated with a matching end.
disp
Syntax
disp(X) Description
disp(X) displays an array, without printing the array name. If X contains a text string, the string is displayed. Another way to display an array on the screen is to type its name, but this prints a leading "X =," which is not always desirable. Note that disp does not display empty arrays.
RESULT:- I have calculated the circular convolution of the function.