This repository has been archived by the owner on May 26, 2020. It is now read-only.
forked from kaustubhcs/Digital-Signal-Processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircular2linear.m
111 lines (67 loc) · 1.81 KB
/
circular2linear.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
%% Circular Convolution
% Linear and circular convolution are fundamentally different operations.
% However, there are conditions under which linear and circular convolution
% are equivalent. Establishing this equivalence has important implications.
% For two vectors, x and y, the circular convolution is equal to the inverse
% discrete Fourier transform (DFT) of the product of the vectors' DFTs.
% Knowing the conditions under which linear and circular convolution are
% equivalent allows you to use the DFT to efficiently compute linear
% convolutions.
%% Function Declaration
% Uncomment below text to make it operate as an independent function
%
disp('Function Declare');
% function [y] = mokau_conv(x,h)
%% System Transfer Function
h= [1,2,3,4,5,6]
%% Input variable
x=[10,20,30]
%% Index of start of input and system transfer function
nx=length(x);
nh=length(h);
m=nx;
%% Expanding Input Matrix Size
for count = 1:nh-1
x(m+1)=0;
m=m+1;
end
q=nh;
%% Expanding Transfer Function Matrix Size
for count = 1:nx-1
h(q+1)=0;
q=q+1;
end
%% Final Matrices
x
h
%% Convolution
[x_m,x_n] = size (x);
x_mat = zeros(x_m,x_n);
aux_x = x;
for count = 1:x_n-1
temp_x = circshift(x,[1,count]);
temp_x;
aux_x = [aux_x,temp_x];
end
output_matrix = zeros(x_n);
global_counter = 1;
for n = 1:x_n
for m = 1:x_n
output_matrix(m,n) = aux_x ( global_counter );
global_counter = global_counter + 1;
end
end
%% OUTPUT Matrix
output_matrix
mul_h = h';
y= output_matrix * mul_h;
y=y'
%% Function Declaration termination
% For terminating function declaration
disp('Function Declaration Ends');
%end
%% Author: Kaustubh Shivdikar
% MATLAB Lab experiment of Linear to circular convolution.
%
% <<D:\MATLAB Files\matlablogo.png>>
%