0% found this document useful (0 votes)
5 views14 pages

DSIP Lab Assignment

Digital Signal Processing

Uploaded by

Bhuvan Sharma
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)
5 views14 pages

DSIP Lab Assignment

Digital Signal Processing

Uploaded by

Bhuvan Sharma
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
You are on page 1/ 14

Department of Electronics and Communication

Engineering
Malaviya National Institute of Technology Jaipur

DSIP Lab Assignment

Submitted by: Priya Godika


College ID: 2023UEC1352

Submitted to Prof. K. K. Sharma


7th May 2025
2023UEC1352

Question 1
Create two sinusoidal signals with amplitude–frequency pairs as given below:

a) (2, 5) + (1.6, 10) + (0.3, 20)

b) (1.8, 2) + (0.8, 25)

1 clc ; % Clears the command window


2 clear ; % Removes all variables from the workspace
3 close all ; % Closes all open figure windows
4 t = 0:0.001:1; % Time vector for 1 second duration with 1 kHz
sampling rate
5

6 x1 = 2* sin (2* pi *5* t ) + 1.6* sin (2* pi *10* t ) + 0.3* sin (2* pi *20* t ) ;
7 x2 = 1.8* sin (2* pi *2* t ) + 0.8* sin (2* pi *25* t ) ;
8 figure ;
9 subplot (2 ,1 ,1) ;
10 plot (t , x1 ) ;
11 title ( ’ Signal 1 a ’) ;
12 xlabel ( ’ Time ( s ) ’) ;
13 ylabel ( ’ Amplitude ’) ;
14 subplot (2 ,1 ,2) ;
15 plot (t , x2 ) ;
16 title ( ’ Signal 1 b ’) ;
17 xlabel ( ’ Time ( s ) ’) ;
18 ylabel ( ’ Amplitude ’) ;
Listing 1: Generate sinusoids

Figure 1: Signal 1a Plot


2023UEC1352

Figure 2: Signal 1b Plot

Question 2
Convolute the two sinusoidal signals created in Question 1.
1 clc ;
2 clear ;
3 close all ;
4 t = 0:0.001:1; % Time vector for 1 second duration with 1 kHz
sampling rate
5 % Constructing Signal x1 & x2 by summing sine waves of
different frequencies and amplitudes
6 x1 = 2* sin (2* pi *5* t ) + 1.6* sin (2* pi *10* t ) + 0.3* sin (2* pi *20* t ) ;
7 x2 = 1.8* sin (2* pi *2* t ) + 0.8* sin (2* pi *25* t ) ;
8 conv_x = conv ( x1 , x2 , ’ same ’) ;
9 figure ;
10 plot (t , conv_x ) ;
11 title ( ’ Convolution of x1 and x2 ’) ;
12 xlabel ( ’ Time ( s ) ’) ;
13 ylabel ( ’ Amplitude ’) ;
Listing 2: Convolution

Figure 3: Convolution Result


2023UEC1352

Question 3
Find the correlation between the signals from Question 1. Show one figure with the
outputs of Questions 2 and 3.
1 clc ;
2 clear ;
3 close all ;
4 t = 0:0.001:1;
5 x1 = 2* sin (2* pi *5* t ) + 1.6* sin (2* pi *10* t ) + 0.3* sin (2* pi *20* t ) ;
6 x2 = 1.8* sin (2* pi *2* t ) + 0.8* sin (2* pi *25* t ) ;
7 conv_x = conv ( x1 , x2 , ’ same ’) ;
8 % Compute the normalized cross - correlation between x1 and x2
9 [ corr_x , lags ] = xcorr ( x1 , x2 , ’ normalized ’) ;
10 figure ;
11 subplot (2 ,1 ,1) ;
12 plot (t , conv_x ) ;
13 title ( ’ Convolution of x1 and x2 ’) ; xlabel ( ’ Time ( s ) ’) ;
ylabel ( ’ Amplitude ’) ;
14 subplot (2 ,1 ,2) ;
15 plot ( lags , corr_x ) ;
16 title ( ’ Correlation of x1 and x2 ’) ; xlabel ( ’ Lag ’) ;
ylabel ( ’ Normalized Correlation ’) ;
Listing 3: Correlation and Convolution

Figure 4: Convolution Output


2023UEC1352

Figure 5: Correlation Output

Question 4
Find the Fourier transforms of the signals from Question 1 (use fftshift; show 4 plots
in one figure).
1 clc ;
2 clear ;
3 close all ;
4 t = 0:0.001:1; % Time vector for 1 second duration with 1 kHz
sampling rate
5

6 % Defining the frequency vector for plotting


7 f = linspace ( -500 , 500 , length ( t ) ) ;
8 x1 = 2* sin (2* pi *5* t ) + 1.6* sin (2* pi *10* t ) + 0.3* sin (2* pi *20* t ) ;
9 x2 = 1.8* sin (2* pi *2* t ) + 0.8* sin (2* pi *25* t ) ;
10 % Computing the Fourier Transform of x1 and x2
11 X1 = fftshift ( fft ( x1 ) ) ; X2 = fftshift ( fft ( x2 ) ) ;
12 figure ;
13 subplot (2 ,2 ,1) ;
14 plot (f , abs ( X1 ) ) ;
15 title ( ’ Mag Spectrum of x1 ’) ;
16 subplot (2 ,2 ,2) ;
17 plot (f , angle ( X1 ) ) ;
18 title ( ’ Phase Spectrum of x1 ’) ;
19 subplot (2 ,2 ,3) ;
20 plot (f , abs ( X2 ) ) ;
21 title ( ’ Mag Spectrum of x2 ’) ;
22 subplot (2 ,2 ,4) ;
23 plot (f , angle ( X2 ) ) ;
24 title ( ’ Phase Spectrum of x2 ’) ;
Listing 4: Fourier Transform of x1 and x2
2023UEC1352

Figure 6: Figures of Q4

Question 5
Perform the following operations on the signals from Question 1a and 1b:

a) Add 1a and 1b.

b) Multiply 1a and 1b.

1 clc ;
2 clear ;
3 close all ;
4 t = 0:0.001:1;
5 x1 = 2* sin (2* pi *5* t ) + 1.6* sin (2* pi *10* t ) + 0.3* sin (2* pi *20* t ) ;
6 x2 = 1.8* sin (2* pi *2* t ) + 0.8* sin (2* pi *25* t ) ;
7 % Performing point - wise addition of x1 and x2
8 x_add = x1 + x2 ;
9 % Performing point - wise multiplication of x1 and x2
10 x_mult = x1 .* x2 ;
11 figure ;
12 subplot (2 ,1 ,1) ;
13 plot (t , x_add ) ; title ( ’ Addition of x1 and x2 ’) ;
14 subplot (2 ,1 ,2) ;
15 plot (t , x_mult ) ; title ( ’ Multiplication of x1 and x2 ’) ;
Listing 5: Addition and Multiplication
2023UEC1352

Figure 7: Addition Result Multiplication Result

Question 6
Find the Fourier transform of the signals obtained in Question 5a and 5b.
1 clc ;
2 clear ;
3 close all ;
4 t = 0:0.001:1;
5 f = linspace ( -500 , 500 , length ( t ) ) ; % Frequency vector from -500
Hz to 500 Hz
6

7 x1 = 2* sin (2* pi *5* t ) + 1.6* sin (2* pi *10* t ) + 0.3* sin (2* pi *20* t ) ;
8 x2 = 1.8* sin (2* pi *2* t ) + 0.8* sin (2* pi *25* t ) ;
9 x_add = x1 + x2 ;
10 x_mult = x1 .* x2 ;
11 % Compute the Fourier Transform of the added and multiplied
signals
12 X_add = fftshift ( fft ( x_add ) ) ; X_mult = fftshift ( fft ( x_mult ) ) ;
13 figure ;
14 subplot (2 ,1 ,1) ;
15 plot (f , abs ( X_add ) ) ; title ( ’ Mag Spectrum of Addition ’) ;
16 subplot (2 ,1 ,2) ;
17 plot (f , abs ( X_mult ) ) ;
18 title ( ’ Mag Spectrum of Multiplication ’) ;
Listing 6: Fourier Transform of Combined Signals
2023UEC1352

Figure 8: FT of Addition FT of Multiplication

Question 7
Create filters with these specs and show magnitude phase responses:

a) fp = 8 Hz, fq = 20 Hz

b) fp = 15 Hz, fq = 5 Hz

c) fp = [10, 20] Hz, fq = [5, 25] Hz

1 clc ;
2 clear ;
3 close all ;
4 fs = 1000; % Sampling frequency in Hz
5 [ b1 , a1 ] = butter (4 , 8/( fs /2) , ’ low ’) ; % Normalized cutoff
frequency = 8 / ( fs /2)
6 [ h1 , w1 ] = freqz ( b1 , a1 ,1024 , fs ) ;
7 [ b2 , a2 ] = butter (4 , 15/( fs /2) , ’ low ’) ; % Normalized cutoff
frequency = 15 / ( fs /2) [ h2 , w2 ] = freqz ( b2 , a2 ,1024 , fs ) ;
8 [ b3 , a3 ] = butter (4 , [10 20]/( fs /2) , ’ bandpass ’) ; % Normalized
passband = [10 20] / ( fs /2)
9 [ h3 , w3 ] = freqz ( b3 , a3 ,1024 , fs ) ;
10 % Plotting the magnitude and phase response of the first filter
11 figure ;
12 subplot (2 ,1 ,1) ;
13 plot ( w1 , abs ( h1 ) ) ; title ( ’ Filter1 Mag (8 Hz ) ’) ;
14 subplot (2 ,1 ,2) ;
15 plot ( w1 , angle ( h1 ) ) ; title ( ’ Filter1 Phase ’) ;
2023UEC1352

16 figure ;
17 subplot (2 ,1 ,1) ;
18 plot ( w2 , abs ( h2 ) ) ; title ( ’ Filter2 Mag (15 Hz ) ’) ;
19 subplot (2 ,1 ,2) ;
20 plot ( w2 , angle ( h2 ) ) ; title ( ’ Filter2 Phase ’) ;
21 figure ;
22 subplot (2 ,1 ,1) ;
23 plot ( w3 , abs ( h3 ) ) ; title ( ’ Filter3 Mag (10 20Hz ) ’) ;
24 subplot (2 ,1 ,2) ;
25 plot ( w3 , angle ( h3 ) ) ; title ( ’ Filter3 Phase ’) ;
Listing 7: Filter Design and Responses

Figure 9: Filter Response 1

Question 8
Pass signals from Q1a, Q1b, Q2, Q5a, Q5b through the three filters; show time-domain
FFT.
1 clc ;
2 clear ;
3 close all ;
4 % Signal Generation
5 fs = 1000;
6 t = 0:1/ fs :1;
7 N = length ( t ) ;
2023UEC1352

Figure 10: Filter Response 2

8 f = linspace ( - fs /2 , fs /2 , N ) ;
9 % Signal Definitions
10 x1 = 2* sin (2* pi *5* t ) +1.6* sin (2* pi *10* t ) +0.3* sin (2* pi *20* t ) ;
11 x2 = 1.8* sin (2* pi *2* t ) +0.8* sin (2* pi *25* t ) ;
12 % Signal Operations
13 conv_x = conv ( x1 , x2 , ’ same ’) ; x_add = x1 + x2 ; x_mult = x1 .* x2 ;
14 % Butterworth Filter Design
15 [ b1 , a1 ] = butter (4 ,8/( fs /2) , ’ low ’) ;
16 [ b2 , a2 ] = butter (4 ,15/( fs /2) , ’ low ’) ;
17 [ b3 , a3 ] = butter (4 ,[10 20]/( fs /2) , ’ bandpass ’) ;
18 % Signal Processing
19 signals = { x1 , x2 , conv_x , x_add , x_mult };
20 names = { ’ x1 ’ , ’ x2 ’ , ’ conv ’ , ’ add ’ , ’ mult ’ };
21 for i =1: length ( signals )
22 for j =1:3
23 b = eval ([ ’b ’ , num2str ( j ) ]) ; a = eval ([ ’a ’ , num2str ( j ) ]) ;
24 y = filter (b ,a , signals { i }) ; Y = fftshift ( fft ( y ) ) ;
25 figure ;
26 subplot (2 ,1 ,1) ; plot (t , y ) ; title ([ names { i } , ’ filt ’ ,
num2str ( j ) ]) ;
27 subplot (2 ,1 ,2) ; plot (f , abs ( Y ) ) ; title ([ ’ FFT of ’ , names { i } ,
’ filt ’ , num2str ( j ) ]) ;
28 end
29 end
Listing 8: Filtering and FFT of All Signals
2023UEC1352

Figure 11: Filter Response 3

Figure 12: Filtered Signal Diagram


2023UEC1352

Figure 13: Filtered Signal Diagram

Figure 14: Filtered Signal Diagram


2023UEC1352

Figure 15: Filtered Signal Diagram


2023UEC1352

Figure 16: Filtered Signal Diagram

You might also like