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 pathlinear2circular.m
147 lines (83 loc) · 2.43 KB
/
linear2circular.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%% Linear Convolution
% This example shows how to establish an equivalence between linear and
% 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.
% The linear convolution of an N-point vector, x, and a L-point vector,
% y, has length N+L-1.
% For the circular convolution of x and y to be equivalent, you must
% pad the vectors with zeros to length at least N+L-1 before you take
% the DFT. After you invert the product of the DFTs, retain only the
% first N+L-1 elements.
%% Formula
% <<D:\MATLAB Files\l2c.png>>
%% Function Declaration
% Uncomment below text to make it operate as an independent function
%
disp('Function Declare');
% function [ op_matrix ] = lincirc_convolve_simply( x,nx,h,nh)
%% 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
nh=0
nx=0
%% Length of each variable
tx = length(x)
th = length(h)
%% Origin for output
ny = nx + nh
%% Length of output
% Direct Formula
ty = tx + th - 1
%% OUTPUT Matrix
m = ty;
n = th;
output_matrix = zeros(n,m);
%% Iterative addition
for count_h = 1:th
for count_x = 1:tx
output_matrix(count_h,m + 1 - count_x - count_h + 1) = x(tx - count_x + 1) * h(th - count_h + 1);
end
end
%% Iterattive ouput computation
for c = 1:ty
y(c) = 0;
end
%% Adding columns
for i = 1:m
for j = 1:n
y(i) = y(i) + output_matrix(j,i);
end
end
output_matrix
l=max(tx,th);
q=ty-l;
m=1;
for count = ty-q+1:ty
y(m)= y(m)+y(count);
m=m+1;
end
%% Generating OUTPUT
for count1 = 1:l
op_matrix(count1)=y(count1);
end
%%
% OUPUT
op_matrix
%% 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>>
%