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

Lab Report#08 DSP

This lab report focuses on circular convolution, introducing students to its concepts and implementation in Code Composer Studio. It includes objectives, required equipment, background knowledge on convolution types, and practical coding tasks for performing circular convolution with given signals. The report concludes with a summary of findings and the importance of understanding convolution in digital signal processing.

Uploaded by

AHMAD MEHMOOD
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab Report#08 DSP

This lab report focuses on circular convolution, introducing students to its concepts and implementation in Code Composer Studio. It includes objectives, required equipment, background knowledge on convolution types, and practical coding tasks for performing circular convolution with given signals. The report concludes with a summary of findings and the importance of understanding convolution in digital signal processing.

Uploaded by

AHMAD MEHMOOD
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab Report#08

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EXPERIMENT NO#08

Lab Title: CIRCULAR CONVOLUTION

Objective: Introducing students to linear and circular convolution and their implementation
in Code Composer Studio
Student Name: Ahmad Mehmood Reg. No: 212097

LAB ASSESSMENT:
Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)
Ability to conduct
experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date:11/21/2024 . Signature:

Digital Signal Processing


Lab Report#08

LABORATORY
EXPERIMENT NO. 8

CIRCULAR CONVOLUTION
Objectives:
• Introducing students to linear and circular convolution and their implementation in
Code Composer Studio

Equipment required:
• C6713 DSK
• Power Cable
• USB Cable
• Code Composer Studio v5.1.0

Background Knowledge:
Convolution:
Convolution is a mathematical operation that describes the action of a linear system on a
signal. The impulse response of a Linear Time-Invariant (LTI) system completely specifies
the system. More specifically, if the impulse response of a system is known one can compute
the system output for any input signal. The output of a system to any input signal is computed
by the convolution of the input signal with the impulse response of the system. There are two
types of convolution:
Circular Convolution:
Circular convolution is periodic convolution evaluated over only one period. Circular
convolution is exactly similar to the Linear Convolution except that the sequences x[n] and
h[n] are periodic. The shifting, inherent in the convolution sum, is actually a rotation if the
sequences are periodic (the values keep on repeating after a Time Period N). The Circular
convolution sum is given by:
𝑁−1

𝑦[𝑛] = 𝑥[𝑛] ⊛ ℎ[𝑛] = ∑ 𝑥[𝑘] ℎ[(𝑛 − 𝑘)]𝑁


𝑘= 0
Fourier Transform vs Convolution:
The Fourier transform of time domain linear convolution sum is equivalent to product of
Fourier transforms the convolved signals, such that:
𝑦[𝑛] = 𝑥 [𝑛] ∗ ℎ[𝑛] ⟹ 𝑌(𝑒 𝑗𝑤 ) = 𝑋(𝑒 𝑗𝑤 )𝐻(𝑒 𝑗𝑤 )
DTFT is naturally related with the linear convolution, as it deals with theoretically existing
aperiodic sequences that may extend from −∞ to ∞. To numerically evaluate this result, time-
domain approach can be used but the frequency-domain approach with DTFT cannot be
used. DTFT is not computationally suited for digital computer implementations since the
variable ω is a real continuous number. Thus, DTFT is uniformly sampled to obtain DFT X[k]
defined as:
𝑋 [𝑘] = 𝑋(𝑒 𝑗𝑤 )| 2𝜋𝑘
𝑤=
𝑛

Digital Signal Processing


Lab Report#08

where k=0,1…N−1, and N is the length of the DFT (for an N-point DFT). DFT of x[n] is given
by X[k] which is a periodic function, inherited from periodicity of DTFT, but only first period
from k=0 to N−1 is considered. The convolution property of DFT is stated as:
𝑥[𝑛] ⊛ ℎ[𝑛] = 𝑋 [𝑘]𝐻[𝑘]
where, x[n] and h[n] are periodic with period N. Since DFT sequences are inherently periodic,
then their convolutions will also be periodic (circular).
Linear Convolution vs Circular Convolution:
The relation between the linear convolution sum y[n] and the circular convolution sum y’[n]
is given by:

𝑦′[𝑛] = ∑ 𝑦[𝑛 − 𝑟𝑁]


𝑟= −∞
As a consequence, the correspondence between the desired linear convolution sum and the
computed circular convolution sum depends on DFT length N which must be larger than the
length of desired sequence Ly of y[n], to avoid aliasing in time-domain, which happens when
N<Ly. DFT assumes the signals to be periodic, even if the sequence was not inherently
periodic. Thus, transforming using DFT permanently introduces periodicity in the signal.
In linear convolution, the input signal and impulse response may or may not be equal in
length. The length of output signal is thus given by:
𝐿𝑒𝑛𝑔𝑡ℎ(𝑦) = 𝐿𝑒𝑛𝑔𝑡ℎ(𝑥 ) + 𝐿𝑒𝑛𝑔𝑡ℎ(ℎ) − 1
In circular convolution, the input and impulse response must be of equal length, i.e., they
must have equal number of samples. If any of the two sequences has lesser number of
samples, zeros are padded to equalize the length of both signals. The output of a circular
convolution has the same number of samples as the two inputs. The output of a circular
convolution is always periodic, and its period is specified by the periods of one of its inputs.
Circular Convolution to Linear Convolution:
The response of LTI systems can be characterized by linear convolution, however, the
implementation yields circular convolution. Thus, it is imperative to use the DFT/FFT
algorithm to calculate linear convolution sum. This can be achieved if the vectors involved in
convolution are padded with zeros till the size of these vectors is equal to 𝐿 = 𝐿𝑒𝑛𝑔𝑡ℎ(𝑥 ) +
𝐿𝑒𝑛𝑔𝑡ℎ(ℎ) − 1.
Circular Convolution in Code Composer Studio:
Let 𝑥[𝑛] = [2 1 2 1]𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 3 and ℎ[𝑛] = [1 2 3 4]𝑓𝑜𝑟 0 ≤ 𝑛 ≤ 3 . To obtain y[n] by
circular convolution of x[n] with h[n], write the code for circular convolution in CCS project
main file.
Result:
After successfully building and debugging of project, the following result is displayed on
console:

These values can be graphed to visualize the results. First add x, h and y to the watch window
and then right click on x, click on graph option, and graph the sequence x[n]. Edit the display
properties in Axes section and add the name x[n] for y-axis.

Digital Signal Processing


Lab Report#08

Right click on h in the expressions window, click on graph option and graph the sequence
h[n].

Right click on y in the expressions window, click on graph option and graph the sequence
y[n].

Digital Signal Processing


Lab Report#08

Lab Task
➢ Task-01:
1. Consider the given signals:
𝒙[𝒏] = [𝟏 𝟑 𝟕 − 𝟐 ] 𝒇𝒐𝒓 𝟎 ≤ 𝒏 ≤ 𝟑
𝒉[𝒏] = [−𝟑 𝟎 𝟐 𝟒] 𝒇𝒐𝒓 𝟎 ≤ 𝒏 ≤ 𝟑
Write a code in CCS which takes length of samples and amplitude of samples as input
from user and then circularly convolves x[n] and h[n] to obtain y[n]. Display the
output on console and plot x[n], h[n] and y[n].

CODE:
#include<stdio.h>
#include<math.h>
int n1, n2;
int r, a, b, l, j, k;
int temp;
int i;
int x[10];
int h[10];
int y[10];
int t1[10];
int t2[10];

void main(void) {
printf("Enter the length of x[n]: ");
scanf("%d", &n1);
printf("Enter the length of h[n]: ");
scanf("%d", &n2);
printf("Enter the amplitude of x[n]: \n");
for (int r = 0; r < n1; r++) {
scanf("%d", &temp);
x[r] = temp;
}
printf("Enter the amplitude of h[n]: \n");
for (int r = 0; r < n2; r++) {
scanf("%d", &temp);
h[r] = temp;
}
printf("x[n] is: ");
for (a = 0; a < n1; a++) {
printf("%d ", x[a]);
}
printf("\nh[n] is: ");
for (b = 0; b < n2; b++) {

Digital Signal Processing


Lab Report#08

printf("%d ", h[b]);


}
t1[0] = h[0];
for (l = 1; l < n2; l++) {
t1[l] = h[n2 - l];
}
y[0] = 0;
for (i = 0; i < n2; i++) {
y[0] = y[0] + (x[i] * t1[i]);
}
for (k = 1; k < n2; k++) {
y[k] = 0;
for (j = 1; j < n2; j++) {
t2[j] = t1[j - 1];
t2[0] = t1[n2 - 1];
}
for (i = 0; i < n2; i++) {
t1[i] = t2[i];
y[k] = y[k] + (x[i] * t1[i]);
}
}
printf("\ny[n] is: ");
for (i = 0; i < n2; i++) {
printf("%d ", y[i]);
}

Output:

Digital Signal Processing


Lab Report#08

Output-Plots:

Figure Plot #01 – X[n]

Figure Plot #02 – h[n]

Figure Plot #03 – Y[n]

. .

Digital Signal Processing


Lab Report#08

➢ Task-02:
Consider the given signals:
𝒙[𝒏] = [𝟒 𝟎 𝟐 𝟑 𝟓] 𝒇𝒐𝒓 𝟎 ≤ 𝒏 ≤ 𝟒
𝒉[𝒏] = [−𝟏 𝟐 𝟏] 𝒇𝒐𝒓 𝟎 ≤ 𝒏 ≤ 𝟐
Write a code in CCS which takes length of samples and amplitude of samples as input
from user. This code should circularly convolve x[n] and h[n] to obtain y[n]. Use the
concept of zero padding to equate your results with the ones obtained in last lab.
Display the output on console and plot x[n], h[n] and y[n].

CODE:

#include<stdio.h>
#include<math.h>
int n1, n2;
int r, a, b, l, j, k;
int temp;
int i;
int x[10];
int h[10];
int y[10];
int t1[10];
int t2[10];

void main(void) {
printf("Enter the length of x[n]: ");
scanf("%d", &n1);
printf("Enter the length of h[n]: ");
scanf("%d", &n2);
printf("Enter the amplitude of x[n]: \n");
for ( r = 0; r < n1; r++) {
scanf("%d", &temp);
x[r] = temp;
}
printf("Enter the amplitude of h[n]: \n");
for (int r = 0; r < n2; r++) {
scanf("%d", &temp);
h[r] = temp;
}
printf("x[n] is: ");
for (a = 0; a < n1; a++) {
printf("%d ", x[a]);
}

Digital Signal Processing


Lab Report#08

printf("\nh[n] is: ");


for (b = 0; b < n2; b++) {
printf("%d ", h[b]);
}

t1[0] = h[0];
for (l = 1; l < n2; l++) {
t1[l] = h[n2 - l];
}

y[0] = 0;
for (i = 0; i < n2; i++) {
y[0] = y[0] + (x[i] * t1[i]);
}

for (k = 1; k < n2; k++) {


y[k] = 0;
for (j = 1; j < n2; j++) {
t2[j] = t1[j - 1];
t2[0] = t1[n2 - 1];
}
for (i = 0; i < n2; i++) {
t1[i] = t2[i];
y[k] = y[k] + (x[i] * t1[i]);
}
}

printf("\ny[n] is: ");


for (i = 0; i < n2; i++) {
printf("%d ", y[i]);
}
}

Output:

Digital Signal Processing


Lab Report#08

Output-Plots:

Figure Plot #01 – X[n]

Figure Plot #02 – h[n]

Figure Plot #03 – Y[n]

. .

Task discussion:
In this task we calculate the convolution of two signals x[n], and h[n]. First
we enters input the length and amplitude values of both signals and store them in arrays, and
reverses h[n].Then it shifts h[n] step by step to match up with x[n]. At each step, it multiplies
matching values, adds them up, and we get the result y[k] by this we get y[n].

Digital Signal Processing


Lab Report#08

Conclusion:

In this lab, we learned about MATLAB software , we know how to perform circular convolution
and how it is different from linear convolution. We wrote code to calculate circular convolution,
used zero padding to handle signals of different lengths, and we analyse the results as graphs. This
lab helps us to understand how convolution works in signal processing.

. THE END .

Digital Signal Processing

You might also like