Vous êtes sur la page 1sur 14

EXPERIMENT-1

Write a program to prove the Nyquist Sampling Theorem.


clc;close all;clear all;
t = 0:0.001:1;
fi = input('Enter the input signal frequency = ');
fs1 = input('sampling frequency < 2 X input signal
frequency = ');
fs2 = input('sampling frequency = 2 X input signal
frequency = ');
fs3 = input('sampling frequency > 2 X input signal
frequency = ');
x = sin(2*pi*fi*t);
subplot(4,2,1);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Input Sinusoidal Signal');
%Sampling at fs < 2fi
n = 0:1/fs1:1;
x1 = sin(2*pi*fi*n);
subplot(4,2,3);
stem(n,x1);
xlabel('Time');
ylabel('Amplitude');
title('Undersampled fs < 2fi Signal');
subplot(4,2,4);
plot(n,x1);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed Undersampled fs < 2 fi Signal');
%Sampling at fs = 2fi
n = 0:1/fs2:1;
x2 = sin(2*pi*fi*n);
subplot(4,2,5);
stem(n,x2);
xlabel('Time');
ylabel('Amplitude');
title('Sampled at Nyquist Rate fs = 2fi Signal');
subplot(4,2,6);
plot(n,x2);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed Nyquist Rate fs=2fm Signal');
%Sampling at fs > 2fi
n = 0:1/fs3:1;
x3 = sin(2*pi*fi*n);
subplot(4,2,7);
stem(n,x3);
xlabel('Time');
ylabel('Amplitude');
title('Oversampled fs>>2fm Signal');
subplot(4,2,8);
plot(n,x3);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed Oversampled fs>>2fm Signal');

Page | 2
EXPERIMENT-2

Write a program to generate convolution of two signals without


using convolution function.
close all; clear all;
x=[0:pi]; h=[0:pi];
n1=length(x);n2=length(h);
X=[x,zeros(1,n2)];
H=[h,zeros(1,n1)];
for i=1:n2+n1-1
Y(i)=0;
for j=1:n1
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
end
subplot(3,1,1);plot(X);
subplot(3,1,2);plot(H);
subplot(3,1,3);stem(Y);
ylabel('Y[n2]');xlabel('n2');
title('Convolution w/o using function');

Page | 3
Experiment-3(a)

Write a program to determine the Continuous Time Fourier


Transform of a signal.
close all; clear all;
n=0:100;x=cos(pi*n/4);k=-300:300;w=(pi/100)*k;
X=x*(exp(-j*pi/100)).^(n'*k);
magX=abs(X);
figure;subplot(2,1,1);
stem(n,x);axis([0 100 -1.5 1.5]);
xlabel('n');ylabel('x');
title('Rectangle Signal x(n)');
subplot(2,1,2);plot(w/pi,magX);
xlabel('Frequency in pi Units');
ylabel('Magnitude');title('Fourier Transform');

close all; clear all;


n=-2:2;x=ones(1,5);k=-400:400;w=(pi/100)*k;
X=x*(exp(-j*pi/100)).^(n'*k);
magX=abs(X);
figure;subplot(2,1,1);
stem(-8:8,[zeros(1,6) x zeros(1,6)]);
xlabel('n');ylabel('x');

Page | 4
title('Rectangle Signal x(n)');
subplot(2,1,2);
plot(w/pi,magX);
xlabel('Frequency in pi Units');
ylabel('Magnitude');title('Fourier Transform');

Page | 5
Experiment-3(b)

Write a program to take an input signal sequence and compute its


Discrete Time Fourier Transform.
clc;close all; clear all;
xn=input('Enter the sequence x(n)'); %Get the
sequence from user- input sequence given[1 2 3 4 5]
ln=length(xn); %find the length of the sequence
xk=zeros(1,ln); %initilise an array of same size as
that of input sequence
ixk=zeros(1,ln); %initilise an array of same size as
that of input sequence

%code to find the DFT of the sequence


for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-
i)*2*pi*k*n/ln));
end
end

%code to plot the input sequence


t=0:ln-1;
subplot(221);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('Input Sequence');

magnitude=abs(xk); % Find the magnitudes of


individual DFT points

%code to plot the magnitude response


t=0:ln-1;
subplot(222);
stem(t,magnitude);
ylabel ('Amplitude');
xlabel ('K');
title ('Magnitude Response');

Page | 6
phase=angle(xk); % Find the phases of individual DFT
points

%code to plot the magnitude sequence


t=0:ln-1;
subplot(223);
stem(t,phase);
ylabel ('Phase');
xlabel ('K');
title ('Phase Response');

Page | 7
Experiment-4

Write a program to check whether a given system is Linear Time


Invariant.
close all; clear all;
n=0:40;a=2;b=3;
x1=cos(0.2*pi*n);
x2=cos(0.8*pi*n);
num=[2.24 2.5 2.24];
den=[1 -0.8 0.6];
ic=[0 0];
y1=filter(num,den,x1,ic);
y2=filter(num,den,x2,ic);
yt=a*y1+b*y2;
x=a*x1+b*x2;
y=filter(num,den,x,ic);
d=yt-y

Page | 8
Ex
periment-5

Write a program to perform Circular Convolution using Fourier


Transform.
clc;close all; clear all;
i1=input('enter the first sequence');
i2=input('enter the second sequence');
N1=length(i1);N2=length(i2);
if N1>N2
i2=[i2,zeros(N2-N1)] %padding zeros to make
lengths of two sequences equal
end
if N2>N1
i1=[i1,zeros(N2-N1)]
end
subplot(2,2,1);
stem(i1);
xlabel('n');
ylabel('amplitude');
title('first sequence');

Page | 9
subplot(2,2,2);
stem(i2);
xlabel('n');
ylabel('amplitude');
title('second sequence');
N=max(N1,N2);
i1=fft(i1,N);
i2=fft(i2,N);
y=i1.*i2;
y=ifft(y);
subplot(2,2,3);
stem(y);
xlabel('n');
ylabel('amplitude');
title('circular convolution');

DIGITALBUTTERWORTHLOWPASSFILTER

MATLABCODE

>>clc;
>>clearall;
>>closeall;
>>rp=input('enterthepassbandattenuation:');
enterthepassbandattenuation:0.4

Page | 10
>>rs=input('enterthestopbandattenuation:');
enterthestopbandattenuation:30
>>wp=input('enterthepassbandfrequency:');
enterthepassbandfrequency:0.2*pi
>>ws=input('enterthestopbandfrequency:');
enterthestopbandfrequency:0.4*pi
>>[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
>>[b,a]=butter(N,wn);
>>freqz(b,a);

SAMPLEINPUT

Enterthepassbandattenuation0.4
Enterthestopbandattenuation30
Enterthepassbandfrequency0.2*pi
Enterthestopbandfrequency0.4*pi

FIGURE

Page | 11
BUTTERWORTHHIGHPASSFILTER

MATLABCODE

clc;
clearall;
closeall;
rp=input('enterthepassbandattenuation:');
rs=input('enterthestopbandattenuation:');
wp=input('enterthepassbandfrequency:');
ws=input('enterthestopbandfrequency:');

Page | 12
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn);
freqz(b,a);

SAMPLEINPUT

enterthepassbandattenuation:0.4
enterthestopbandattenuation:30
enterthepassbandfrequency:0.6*PI
enterthepassbandfrequency:0.6*pi
enterthestopbandfrequency:0.2*pi

FIGURE

Page | 13
Page | 14

Vous aimerez peut-être aussi