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

Signals and Systems Lab Experiment-6 Name: Chilaka Sathvik Roll Number: 19CS01049 Date: 21-10-2020

1) The document describes an experiment on convolution and Fourier series. It includes code to calculate the convolution of two sequences both manually and using the conv() function, showing they produce the same result. 2) The document also includes code to calculate the Fourier series representation of a square wave by manually calculating coefficients and using varying numbers of terms in the summation, observing the Gibbs phenomenon. 3) The conclusion is that calculating the Fourier series coefficients and convolution manually versus using built-in functions both produce the same results.

Uploaded by

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

Signals and Systems Lab Experiment-6 Name: Chilaka Sathvik Roll Number: 19CS01049 Date: 21-10-2020

1) The document describes an experiment on convolution and Fourier series. It includes code to calculate the convolution of two sequences both manually and using the conv() function, showing they produce the same result. 2) The document also includes code to calculate the Fourier series representation of a square wave by manually calculating coefficients and using varying numbers of terms in the summation, observing the Gibbs phenomenon. 3) The conclusion is that calculating the Fourier series coefficients and convolution manually versus using built-in functions both produce the same results.

Uploaded by

Sathvik Chilaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Signals and Systems Lab

Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020
Question-1:

CONVOLUTION: Write a program to find convolution of two finite length


sequences

Input: x[n] = {1, 4, 5, 7, 8}, n= 0,1, ..., 4 h[n] = {1,1, 1, 1}, n = 0,1, ..., 3
Output: Convolution of x[n] and h[n]

Write your own code/function to implement convolution andcomparethe results


with MATLAB inbuilt function conv().

Solution:
Code-
clc;
clear all;
close all;
%finding convolution using usual method
a=[1,4,5,7,8];
b=[1,1,1,1];
%total no.of non-zero computations is n.
x=length(a);
y=length(b);
n=x+y;
A=[a,zeros(1,y)];
B=[y,zeros(1,x)];
for i=1:b+a-1
Y(i)=0;
for j=1:x
if(i-j+1>0) Y(i)=Y(i)+A(j)*B(i-j+1);
else
end
end
end

Y
subplot(2,1,1)
stem(Y,'-.','m');
ylabel('Y[n]');
xlabel('n');
title('Convolution of Two Signals without conv()
function');
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020
%to find the convolution using the conv function
subplot(2,1,2)
y=conv(a,b)
stem(y,':','r')
ylabel('Y[n]');
xlabel('n'); k
title('Convolution of Two Signals with conv()
function’)

Command Window:-
Y= 1 5 10 17 24 20 15 8

y= 1 5 10 17 24 20 15 8

Conclusion:
From this one can conclude that convolution of both the ways is the
same, whether it is through the formal conventional way or by using the conv( )
function.
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020
Question-2:
FOURIER SERIES: Consider a periodic square wave and verify the formula for
its Fourier series. Calculate the Fourier coefficients and obtain the weighted
sum expression. Vary the number of terms in the summation and plot it.
Observe the Gibb’s phenomenon as you increase the number of terms.
Solution:
Derivation:-
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020

Code-1:-
By calculating the fourier series coefficients manually-
clc;
close all;
clear all;
T1=4;
T0=16;
n=input("enter the value of N for summation:\n");
t1=3*T0/2; %to consider 3 periods
t=linspace(-t1,t1,1000); %to create a square wave
X=zeros(1,1000);
X(t>=-5*T1 & t<=-3*T1)=1;
X(t>=-T1 & t<=T1)=1; %to give the specified values at
intervals
X(t>=3*T1 & t<=5*T1)=1;
y=0;
for k=0:n
for n=-k:k
if n~=0
an=(sin(2*pi*n*T1/T0)/((pi*n)));
else
an=1/2;
end
y=y+an*exp(1i*n*2*pi/T0.*t); %summation of
coefficients
end
y=real(y);
plot(t,X,t,y);
ylabel('amplitude');
xlabel('Time')
title('Gibs phenomenon for provided n')
y=0;
end

Simulation:
Enter the value of N for summation-
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020
50
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020

Enter the value of N for Summation-


15
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020

Code-2:-
By doing the intergration in the code itself
clc;
close all;
clear all;
T1=4;
T0=16;
N=input("enter the value of N for summation:\n");
t1=3*T0/2; %for 3 periods
t=linspace(-t1,t1,1000);
X=zeros(1,1000);
X(t>=-5*T1 & t<=-3*T1)=1;
X(t>=-T1 & t<=T1)=1;
X(t>=3*T1 & t<=5*T1)=1;
y=0;
for k=0:N
for n=-k:k
syms t
f=exp((-1i*n*2*pi*t)/T0);
if n~=0
coeff_int=int(f,t,-T1,T1);
an =coeff_int/T0;
else
an = 1/2;
end
t =linspace(-t1,t1,1000);
y = y + an*exp(1i*n*2*pi/T0.*t); % adding all the
coefficients
end
y=real(y);
plot(t,X,t,y);
ylabel('amplitude');
xlabel('Time')
title('Gibs phenomenon for provided n')
y=0;
end
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020
Simulation:-
Enter the value of N for summation-
15
Signals and Systems Lab
Experiment-6
Name: Chilaka Sathvik
Roll number: 19CS01049
Date: 21-10-2020
Enter the value of N for summation-
50

Conclusion:-
So, from this one can easily conclude that fourier series coefficients
would be the same in both the methods.

You might also like