Lab Report#08 DSP
Lab Report#08 DSP
AIR UNIVERSITY
EXPERIMENT NO#08
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
Data presentation
Experimental results
Conclusion
Date:11/21/2024 . Signature:
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
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:
∞
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.
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].
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++) {
Output:
Output-Plots:
. .
➢ 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]);
}
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]);
}
Output:
Output-Plots:
. .
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].
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 .