0% found this document useful (0 votes)
23 views13 pages

Digital Signal Processing Operations

The document outlines a lab focused on analyzing and comparing fundamental digital signal processing operations, including linear and circular convolution, cross correlation, and auto correlation. It details the objectives, theoretical background, and results from various tasks involving discrete-time signals. Each task includes MATLAB code for performing the operations and plotting the results to visualize the differences between the methods.

Uploaded by

tjahanjoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

Digital Signal Processing Operations

The document outlines a lab focused on analyzing and comparing fundamental digital signal processing operations, including linear and circular convolution, cross correlation, and auto correlation. It details the objectives, theoretical background, and results from various tasks involving discrete-time signals. Each task includes MATLAB code for performing the operations and plotting the results to visualize the differences between the methods.

Uploaded by

tjahanjoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Contents

1 Objective 2

2 Theory 2
2.1 Linear Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Circular Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Cross Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.4 Auto Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Tasks and Results 3


3.1 Task 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Task 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.3 Task 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Task 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.5 Task 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.6 Task 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Discussion 13

5 Conclusion 13

1
1 Objective
The objective of this lab is to analyze and compare fundamental digital signal processing
operations, including:
• Performing linear convolution between discrete-time signals.
• Performing circular convolution and comparing it with linear convolution.
• Computing cross correlation to measure the similarity between two signals.
• Computing auto correlation to investigate periodicity and energy of a signal.
• Plotting the results of each operation for given test signals.
• Observing and commenting on the differences between linear convolution, circular
convolution, and correlation methods.

2 Theory
[1]

2.1 Linear Convolution


Linear convolution is the fundamental operation of two discrete signals in the time do-
main. For two sequences x(n) and h(n), linear convolution is defined as:
X∞
y(n) = x(n) ∗ h(n) = x(k)h(n − k)
k=−∞

This operation corresponds to the multiplication of spectra in the frequency domain. It


is widely used in systems analysis, especially to determine the response of a system to an
input signal.

2.2 Circular Convolution


Circular convolution is used when signals are assumed to be periodic. For sequences of
length N , circular convolution is defined as:
N
X −1
y(n) = x(k)h((n − k))N
k=0
where the subscript N indicates modulo-N operation. Circular convolution is important
in DFT/FFT computations.

2.3 Cross Correlation


Cross correlation measures the similarity between two signals as a function of displace-
ment (lag). For signals x(n) and h(n):
X∞
rxh (m) = x(n)h(n + m)
n=−∞

It is widely used in pattern recognition, time delay estimation, and signal detection.

2
2.4 Auto Correlation
Auto correlation is the correlation of a signal with itself. It measures the signal’s similarity
with a delayed version of itself:

X
rxx (m) = x(n)x(n + m)
n=−∞

It is useful for detecting repeating patterns and periodicity within a signal.

3 Tasks and Results


3.1 Task 1
Given:
x(n) = {2, 1, 0, −1, 2, 5, 6}, h(n) = {0, 0, 2, 2, 4, 5, 6}

Code

1 % Given sequences
2 x = [2 , 1 , 0 , -1 , 2 , 5 , 6];
3 h = [0 , 0 , 2 , 2 , 4 , 5 , 6];
4

5 % % i . Linear Convolution
6 linear_conv = conv (x , h ) ;
7

8 % % ii . Circular Convolution
9 N = max ( length ( x ) , length ( h ) ) ;
10 circular_conv = ifft ( fft (x , N ) .* fft (h , N ) ) ;
11 circular_conv = real ( circular_conv ) ; % eliminate tiny imaginary
errors
12

13 % % iii . Cross - Correlation


14 cross_corr = xcorr (x , h ) ;
15

16 % % iv . Auto - Correlation
17 auto_corr = xcorr ( x ) ;
18

19 % % v . Plotting the results


20

21 figure ;
22 subplot (2 ,2 ,1) ;
23 stem (0: length ( linear_conv ) -1 , linear_conv , ’ filled ’) ;
24 title ( ’ Linear Convolution ’) ;
25 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
26

27 subplot (2 ,2 ,2) ;
28 stem (0: N -1 , circular_conv , ’ filled ’) ;
29 title ( ’ Circular Convolution ( mod N ) ’) ;
30 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;

3
31

32 subplot (2 ,2 ,3) ;
33 lags_cross = -( length ( h ) -1) :( length ( x ) -1) ;
34 stem ( lags_cross , cross_corr , ’ filled ’) ;
35 title ( ’ Cross - Correlation ’) ;
36 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
37

38 subplot (2 ,2 ,4) ;
39 lags_auto = -( length ( x ) -1) :( length ( x ) -1) ;
40 stem ( lags_auto , auto_corr , ’ filled ’) ;
41 title ( ’ Auto - Correlation ’) ;
42 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
43

44 sgtitle ( ’ Signal Operations : Convolution & Correlation ’) ;

Results

Figure 1: Task 1 results (Linear/Circular Convolution, Cross and Auto Correlation)

3.2 Task 2
Given:
x(n) = sin(n), h(n) = cos(n)

Code

1 % Define the sampled domain


2 x_vals = 0: pi /8:2* pi ; % 17 samples
3

4 % Define the signals


5 x = sin ( x_vals ) ; % x ( x ) = sin ( x )
6 h = cos ( x_vals ) ; % h ( x ) = cos ( x )
7

8 % % i . Linear Convolution
9 linear_conv = conv (x , h ) ;
10

11 % % ii . Circular Convolution ( length = length of original signals )


12 N = length ( x ) ;

4
13 circular_conv = ifft ( fft (x , N ) .* fft (h , N ) ) ;
14 circular_conv = real ( circular_conv ) ; % remove numerical noise
15

16 % % iii . Cross - Correlation


17 cross_corr = xcorr (x , h ) ;
18

19 % % iv . Auto - Correlation
20 auto_corr = xcorr ( x ) ;
21

22 % % v . Plotting all results


23

24 figure ;
25 subplot (2 ,2 ,1) ;
26 stem (0: length ( linear_conv ) -1 , linear_conv , ’ filled ’) ;
27 title ( ’ Linear Convolution : sin ( x ) * cos ( x ) ’) ;
28 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
29

30 subplot (2 ,2 ,2) ;
31 stem (0: N -1 , circular_conv , ’ filled ’) ;
32 title ( ’ Circular Convolution ( mod N ) ’) ;
33 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
34

35 subplot (2 ,2 ,3) ;
36 lags_cross = -( length ( h ) -1) :( length ( x ) -1) ;
37 stem ( lags_cross , cross_corr , ’ filled ’) ;
38 title ( ’ Cross - Correlation : sin ( x ) cos ( x ) ’) ;
39 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
40

41 subplot (2 ,2 ,4) ;
42 lags_auto = -( length ( x ) -1) :( length ( x ) -1) ;
43 stem ( lags_auto , auto_corr , ’ filled ’) ;
44 title ( ’ Auto - Correlation : sin ( x ) sin ( x ) ’) ;
45 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
46

47 sgtitle ( ’ Operations on sin ( x ) and cos ( x ) ’) ;

5
Results

Figure 2: Task 2 results

3.3 Task 3
Given:
x(3n − 2), −h(n + 2)
where x(n) and h(n) are from Task 1.

Code

1 % MATLAB Code to define signals


2 x1 = [2 , 1 , 0 , -1 , 2 , 5 , 6]; % x (3 n - 2)
3 h1 = [0 , 0 , 2 , 2 , 4 , 5 , 6]; % -h ( n + 2)
4

5 linear_conv = conv ( x1 , h1 ) ;
6

7 N = max ( length ( x1 ) , length ( h1 ) ) ;


8

9 x1_padded = [ x1 zeros (1 , N - length ( x1 ) ) ];


10 h1_padded = [ h1 zeros (1 , N - length ( h1 ) ) ];
11

12 circular_conv = cconv ( x1_padded , h1_padded , N ) ;


13 cross_corr = xcorr ( x1 , h1 ) ;
14 auto_corr = xcorr ( x1 ) ; % auto - correlation of x1 only
15

16

17 % Ploting all the graph


18 n1 = 0: length ( linear_conv ) -1;
19 n2 = 0: length ( circular_conv ) -1;
20 [ cross_corr , lag_corr ] = xcorr ( x1 , h1 ) ;
21 n4 = -( length ( x1 ) -1) :( length ( x1 ) -1) ;
22

23 subplot (3 ,2 ,1) ;
24 stem ( n1 , linear_conv ) ;
25 title ( ’ Linear Convolution ’) ;
26 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;

6
27

28 subplot (3 ,2 ,2) ;
29 stem ( n2 , circular_conv ) ;
30 title ( ’ Circular Convolution ’) ;
31 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;
32

33 subplot (3 ,2 ,3) ;
34 stem ( lag_corr , cross_corr ) ;
35 title ( ’ Cross Correlation ’) ;
36 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;
37

38 subplot (3 ,2 ,4) ;
39 stem ( n4 , auto_corr ) ;
40 title ( ’ Auto Correlation ’) ;
41 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;
42

43 subplot (3 ,2 ,[5 6]) ;


44 stem (0: length ( h1 ) -1 , h1 , ’r ’) ; hold on ;
45 stem (0: length ( x1 ) -1 , x1 , ’b ’) ;
46 legend ( ’h ( n ) ’ , ’x ( n ) ’) ;
47 title ( ’ Input Signals ’) ;
48 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;

Results

Figure 3: Task 3 results

7
3.4 Task 4
Given:
x(−n + 4), h(−n − 3)
where x(n) and h(n) are from Task 1.

Code

1 % Original signals
2 x_orig = [2 , 1 , 0 , -1 , 2 , 5 , 6];
3 h_orig = [0 , 0 , 2 , 2 , 4 , 5 , 6];
4

5 % x ( - n + 4) = x (4 - n )
6 x1 = fliplr ( x_orig ) ;
7

8 % h ( - n - 3) = shift and reverse h ( n )


9 h_rev = fliplr ( h_orig ) ; % h(-n)
10 h1 = [ zeros (1 ,3) , h_rev ]; % h ( - n - 3)
11 linear_conv = conv ( x1 , h1 ) ;
12

13 N = max ( length ( x1 ) , length ( h1 ) ) ;


14

15 x1_padded = [ x1 zeros (1 , N - length ( x1 ) ) ];


16 h1_padded = [ h1 zeros (1 , N - length ( h1 ) ) ];
17 circular_conv = cconv ( x1_padded , h1_padded , N ) ;
18 [ cross_corr , lag_corr ] = xcorr ( x1 , h1 ) ;
19 [ auto_corr , lag_auto ] = xcorr ( x1 ) ;
20 n1 = 0: length ( linear_conv ) -1;
21 n2 = 0: length ( circular_conv ) -1;
22

23 figure ;
24 subplot (3 ,2 ,1) ;
25 stem ( n1 , linear_conv ) ;
26 title ( ’ Linear Convolution ’) ;
27 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;
28

29 subplot (3 ,2 ,2) ;
30 stem ( n2 , circular_conv ) ;
31 title ( ’ Circular Convolution ’) ;
32 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;
33

34 subplot (3 ,2 ,3) ;
35 stem ( lag_corr , cross_corr ) ;
36 title ( ’ Cross Correlation ’) ;
37 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ;
38

39 subplot (3 ,2 ,4) ;
40 stem ( lag_auto , auto_corr ) ;
41 title ( ’ Auto Correlation ’) ;
42 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ;
43

8
44 subplot (3 ,2 ,[5 6]) ;
45 stem (0: length ( x1 ) -1 , x1 , ’b ’) ; hold on ;
46 stem (0: length ( h1 ) -1 , h1 , ’r ’) ;
47 legend ( ’x ( - n +4) ’ , ’h ( -n -3) ’) ;
48 title ( ’ Input Signals ’) ;
49 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ;

Results

Figure 4: Task 4 results

3.5 Task 5
Given:
x(3n − 2), −h(n + 2)
where x(n) and h(n) are from Task 1.

Code

1 clc ;
2 clear ;
3

4 % Define range of n
5 n = 0:20;
6

7 % Define signals
8 x = sin (3* n - 2) ;
9 h = - cos ( n + 2) ;
10

11 % ------------------------------
12 % i . Linear Convolution
13 lin_conv = conv (x , h ) ;
14

15 % ------------------------------
16 % ii . Circular Convolution ( same length as linear convolution )
17 N = length ( x ) + length ( h ) - 1;

9
18 circ_conv = cconv (x , h , N ) ; % Circular convolution with same
length
19

20 % ------------------------------
21 % iii . Cross Correlation
22 cross_corr = xcorr (x , h ) ;
23

24 % ------------------------------
25 % iv . Auto Correlation
26 auto_corr = xcorr (x , x ) ;
27

28 % ------------------------------
29 % v . Plot all
30 n1 = 0: length ( lin_conv ) -1;
31 n2 = 0: length ( circ_conv ) -1;
32 n3 = - length ( x ) +1: length ( x ) -1;
33

34 figure ;
35

36 subplot (3 ,2 ,1) ;
37 stem (n , x ) ;
38 title ( ’x ( n ) = sin (3 n - 2) ’) ;
39 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
40

41 subplot (3 ,2 ,2) ;
42 stem (n , h ) ;
43 title ( ’h ( n ) = - cos ( n + 2) ’) ;
44 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
45

46 subplot (3 ,2 ,3) ;
47 stem ( n1 , lin_conv ) ;
48 title ( ’ Linear Convolution ’) ;
49 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
50

51 subplot (3 ,2 ,4) ;
52 stem ( n2 , circ_conv ) ;
53 title ( ’ Circular Convolution ’) ;
54 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
55

56 subplot (3 ,2 ,5) ;
57 stem ( n3 , cross_corr ) ;
58 title ( ’ Cross Correlation ’) ;
59 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
60

61 subplot (3 ,2 ,6) ;
62 stem ( n3 , auto_corr ) ;
63 title ( ’ Auto Correlation of x ( n ) ’) ;
64 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;

10
Results

Figure 5: Task 5 results

3.6 Task 6
Given:
x(−n + 4), h(−n − 3)
where x(n) and h(n) are from Task 1.

Code

1 clc ;
2 clear ;
3

4 % Define n
5 n = 0:20;
6

7 % Define signals with time reversal and shifting


8 x = sin ( - n + 4) ;
9 h = cos ( - n - 3) ;
10

11 % ------------------------------
12 % i . Linear Convolution
13 lin_conv = conv (x , h ) ;
14

15 % ------------------------------
16 % ii . Circular Convolution
17 N = length ( x ) + length ( h ) - 1; % Choose N same as linear for
comparison
18 circ_conv = cconv (x , h , N ) ;
19

20 % ------------------------------
21 % iii . Cross Correlation
22 cross_corr = xcorr (x , h ) ;
23

24 % ------------------------------
25 % iv . Auto Correlation
26 auto_corr = xcorr (x , x ) ;

11
27

28 % ------------------------------
29 % v . Plot All
30 n1 = 0: length ( lin_conv ) -1;
31 n2 = 0: length ( circ_conv ) -1;
32 n3 = - length ( x ) +1: length ( x ) -1;
33

34 figure ;
35

36 subplot (3 ,2 ,1) ;
37 stem (n , x ) ;
38 title ( ’x ( n ) = sin ( - n + 4) ’) ;
39 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
40

41 subplot (3 ,2 ,2) ;
42 stem (n , h ) ;
43 title ( ’h ( n ) = cos ( - n - 3) ’) ;
44 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
45

46 subplot (3 ,2 ,3) ;
47 stem ( n1 , lin_conv ) ;
48 title ( ’ Linear Convolution ’) ;
49 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
50

51 subplot (3 ,2 ,4) ;
52 stem ( n2 , circ_conv ) ;
53 title ( ’ Circular Convolution ’) ;
54 xlabel ( ’n ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
55

56 subplot (3 ,2 ,5) ;
57 stem ( n3 , cross_corr ) ;
58 title ( ’ Cross Correlation ’) ;
59 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;
60

61 subplot (3 ,2 ,6) ;
62 stem ( n3 , auto_corr ) ;
63 title ( ’ Auto Correlation of x ( n ) ’) ;
64 xlabel ( ’ Lag ’) ; ylabel ( ’ Amplitude ’) ; grid on ;

12
Results

Figure 6: Task 6 results

4 Discussion
From the experiments, it is observed that:

• Linear convolution produces a longer sequence length equal to (N + M − 1), while


circular convolution wraps around the signal, leading to aliasing unless the signal
length is extended using zero-padding.

• Cross correlation highlights the similarity between x(n) and shifted versions of h(n),
whereas auto correlation demonstrates periodicity and energy distribution of x(n).

• The plots for linear and circular convolution differ when no zero-padding is applied,
but they match when circular convolution is performed with sufficient padding.

5 Conclusion
In this lab, we explored fundamental signal operations such as convolution (linear and
circular) and correlation (cross and auto). The experiments demonstrate how these tools
are essential for analyzing system behavior, periodicity, and similarity in signals. The
theoretical and graphical analysis also highlight the practical differences between linear
and circular convolution.

References
[1] J. G. Proakis and D. K. Manolakis, Digital Signal Processing: Principles, Algorithms,
and Applications, 4th ed. Pearson, 2007.

13

You might also like