Anda di halaman 1dari 21

SETHU INSTITUTE OF TECHNOLOGY

Pulloor, Kariapatti 626115

Estd. 1995

Department of Electronics and Instrumentation


Engineering
Subject Code: EC 65

Communication and Digital Signal Processing Laboratory

Name

Reg No.

Branch

Year & Semester

EX. NO. 1

GENERATION OF SIGNALS

Date:
AIM:
To generate the following signals using MATLAB 10.0
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential growing signal
5. Exponential decaying signal
6. Sine signal
7. Cosine signal
APPARATUS REQUIRED:
System with MATLAB 10.0.
ALGORITHM:
1. Get the number of samples.
2. Generate the unit impulse, unit step using ones, zeros matrix command.
3. Generate ramp, sine, cosine and exponential signals using corresponding general formula.
4. Plot the graph.
PROGRAM:
1. UNIT IMPULSE SIGNAL

clc;
clear all;
close all;
disp('UNIT IMPULSE SIGNAL');
N = input('Number of Samples: ');
n = -N:1:N
x = [zeros(1,N),ones(1,1),zeros(1,N)]
subplot(2,2,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Impulse Response');
2. UNIT STEP SIGNAL
clc;
clear all;
close all;
disp('UNIT STEP SIGNAL');
N = input('Number of Samples = ');
n = - N:1:N
x = [zeros(1,N), ones(1,1), ones(1,N) ]
subplot (1,1,1);
stem( n, x);
xlabel('Time --->');
ylabel('Amplitude --->');

title('Unit Step Response');


3. UNIT RAMP SIGNAL
clc;
clear all;
close all;
disp('UNIT RAMP SIGNAL');
N = input('Number of Samples = ');
a = input('Amplitude = ');
n = -N:1:N
x = a*n
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Unit Ramp Response');
4. EXPONENTIAL DECAYING SIGNAL
clc;
clear all;
close all;
disp('EXPONENTIAL DECAYING SIGNAL');
N = input('Number of Samples = ');
a = input('Enter the Scaling Factor = ');
n = 0:.1:N;
x = exp(a*-n);
stem( n, x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Decaying Signal Response');
5. EXPONENTIAL GROWING SIGNAL
clc;
clear all;
close all;
disp('EXPONENTIAL GROWING SIGNAL');
N = input('Number of Samples = ');
a = input('Enter the Scaling Factor = ');
n = 0:.1:N;
x = exp(a*n);
stem( n, x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Growing Signal Response');
6. COSINE SIGNAL
clc;
clear all;
close all;
disp('COSINE SIGNAL');

N=input('Number of Samples = ');


n = 0:.1:N
x = cos(2*pi*n);
plot(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Cosine Signal');
7. SINE SIGNAL
clc;
clear all;
close all;
disp('SINE SIGNAL');
N=input('Number of Samples = ');
n = 0:.1:N
x = sin(2*pi*n);
plot(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Sine Signal');
RESULT:
Thus the various signals
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential growing signal
5. Exponential decaying signal
6. Sine signal
7. Cosine signal
are generated using MATLAB 10.0

EX.NO. 2

CONVOLUTION OF SIGNALS

Date:
AIM:
To write the program for finding the linear and circular convolution of two signals using
MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
LINEAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the output sequence of the given two input signals using conv command.
3. Plot the graph.
PROGRAM:
PROGRAM FOR LINEAR CONVOLUTION

clc;
clear all;
close all;
x = input( 'Enter the first sample = ') ;
N1 = length(x);
n = 0:1:N1-1;
subplot(2, 2,1);
stem (n, x);
xlabel('Time');
ylabel('Amplitude');
title('X Sequence Response');
h = input( 'Enter the second sample = ');
N2 = length(h);
n = 0:1:N2-1;
subplot(2,2,2);
stem(n, h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence Response');
Y = conv(x,h);
disp('Output of Linear Convolution is = ');
disp(Y);
N = N1+N2-1;
n = 0: 1: N-1;
subplot(2, 2,3);
stem(Y) ;
xlabel('Time');
ylabel('Amplitude');
title('Convolution of x & h Response');

CIRCULAR CONVOLUTION:
ALGORITHM:
1. Get the number of samples.
2. Generate the sequence for the given two input signals using zeros and ones matrix command.
3. Generate the convoluted output sequence of the given two input signals using conv command.
4. Plot the graph.

PROGRAM:
PROGRAM FOR CIRCULAR CONVOLUTION
clc;
clear all;
close all;
x = input( 'Enter the first sequence');
N1=length(x);
h = input( 'Enter the second sequence') ;
N2 = length(h);
n = 0:1:N1-1;
subplot(2, 2,1);
stem(n, x);
xlabel('Time');
ylabel('Amplitude');
title('X Sequence Response');
n=0:1:N2-1;
subplot(2, 2,2);
stem( n, h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence Response') ;
N=max(N1,N2);
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y( n)+x( i)*h(j);
end
end
disp('Convolution of x & h is') ;
disp(y);
subplot(2, 2,3);
stem(y) ;
xlabel('Time');
ylabel('Amplitude');
title('Convolution of x & h Response');
RESULT:
Thus the linear and circular convolutions for two signals are generated using
MATLAB

EX.NO. 3

CALCULATION OF FFT

Date:
AIM:
To write the program for calculating the N - point FFT and IFFT of given input
sequence using MATLAB.
APPARATUS REQUIRED:
System with MATLAB.
ALGORITHM:
1. Get the input sequence and its length.
2. Calculate the Fast Fourier Transform and Inver se Fast Fourier Transform of given
sequence using user defined function.
3. Plot the magnitude and phase response of FFT sequence.
4. Plot the IFFT response.
PROGRAM:
CALCULATION OF FFT AND IFFT
clc;
clear all;
close all;
x = input('x(n) = ');
N = length(x);
n = input('n = ');
y = fft(x,n);
v = 0:1:N-1;
t = 0:1:n-1;
subplot(2,2,1);
stem(v, x);
xlabel('Time');
ylabel('Amplitude');
title('Input Signal');
subplot(2,2,2);
stem(t,abs(y));
xlabel('Time');
ylabel('Amp litude');
title('Magnitude Response');
subplot(2,2,3);
stem(t,angle(y));
xlabel('Time');
ylabel('Amplitude');
title('Phase Response');
disp('fft x(n)') ;
disp(y);
y1=ifft(y,n);
subplot(2,2,4);
stem(t,y1);
xlabel('Time');

ylabel('Amplitude');
title('IFFT Response') ;
disp('ifft X(K)');
disp(y1);

RESULT:
Thus the program for N - point FFT and IFFT of given input sequence using
MATLAB is calculated.

EX.NO. 4 (a)

DESIGN OF FIR FILTER USING KAISER WINDOW

Date:
AIM:
To design the FIR filter using Kaiser Window with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band attenuation and frequency.
2. Get the sampling frequency.
3. Find transition width and center frequency (cut-off frequency).
4. Design the low pass, high pass, band pass and band stop filter.
5. Plot the magnitude response of all filters.
PROGRAM:

% Program to design a FIR filter using KAISER windows.


close all;
clear all;
clc;
fp=input('Enter the pass band frequency = ');
fs=input('Enter the stop band frequency = ');
rp=input(' Enter the pass band attenuation = ');
rs=input('Enter the stop band attenuation = ');
f=input(' Enter the sampling frequency = ');
% Calculating filter order
num = -20*log10(sqrt(rp*rs))-13;
dem = 14.6*(fs-fp)/f;
n = ceil(num/dem);
n = abs(n);
% Normalizing the frequencies
wp = 2 * fp/f;
ws = 2 * fs/f;
wn = (ws + wp)/2;
% Adjusting the filter order. The order of window must be an odd number
% and the order of filter must be one less than that of the window
if (rem(n,2)==0)
m = n+1;
else
m = n;
n = n-1;
end
% Window sequence calculation

w = kaiser(m);
% Calculation of filter coefficients
% LOW PASS FILTER
b = fir1(n,wn,'low',w);
freqz(b,1,500,3000);
title('Kaiser LPF Magnitude and Phase response');
% Plotting the filter response
% HIGH PASS FILTER
b = fir1(n,wn,'high',w);
figure(2);
freqz(b,1,500,3000);
title('Kaiser HPF Magnitude and Phase response');
% Plotting the filter response
% BAND PASS FILTER
b = fir1(n,wn,'band',w);
figure(3);
freqz(b,1,500,3000);
title('Kaiser BPF Magnitude and Phase response');
% Plotting the filter response
% STOP PASS FILTER
b = fir1(n,wn,'stop',w);
figure(4);
freqz(b,1,500,3000);
title('Kaiser SPF Magnitude and Phase response');
% Plotting the filter response

RESULT:
Thus the FIR filter using Kaiser window is programmed.

EX.NO.4 (b) DESIGN OF FIR FILTER USING RECTANGULAR WINDOW


Date:
AIM:
To design a FIR filter using Rectangular window with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the low pass, high pass, band pass and band stop filter.
5. Plot the magnitude response of all filters.
PROGRAM:
clc;
clear all;
close all;
rp=input('Pass band r ipp le=');
rs=input('Stop band ripple=') ;
fs=input('Stop band frequency in rad/sec=');
fp=input('Pass band frequency in rad/sec=');
f=input('Sampling frequency in rad/sec=');
wp=2* fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*( fs-fp)/f;
n=ceil(num/dem)
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n- 1;
end
y=boxcar(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2, 2,1);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');

xlabel('Normalized frequency---->');
title('LOW PASS FI LTER')
%HIGH PASS FILTER
b=fir1(n,wp,'high', y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2, 2);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('HIGH PASS FILTER')
%BAND PASS FILTER
wn=[wp,ws];
x=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
subplot(2,2,3);
plot(o/pi,m,'k ');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('BAND PASS FILTER')
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2, 2,4);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('BAND STOP FILTER')
OUTPUT:
RESULT:

EX.NO. 4 (c) DESIGN OF FIR FILTER USING HAMMING WINDOW


Date:
AIM:
To design a FIR filter using Hamming window with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0
ALGORITHM:
1. Get the pass band and stop band ripple and frequency.
2. Get the sampling frequency.
3. Find the order of filter N.
4. Design the low pass, High pass, Band pass and Band stop filter.
5. Plot the magnitude response of all the filter s.
PROGRAM:
clc;
clear all;
close all;
rp=input('Pass band r ipp le=');
rs=input('Stop band ripple=') ;
fs=input('Stop band frequency in rad/sec=');
fp=input('Pass band frequency in rad/sec=');
f=input('Sampling frequency in rad/sec=');
wp=2* fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*( fs-fp)/f;
n=ceil(num/dem)
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n- 1;
end
y=hamming(n1);
%LOW PASS FILTER
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2, 2,1);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');

xlabel('Normalized frequency---->');
title('LOW PASS FI LTER')
%HIGH PASS FILTER
b=fir1(n,wp,'high', y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2, 2,2);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('HIGH PASS FILTER')
%BAND PASS FILTER
wn=[wp,ws] ;
x=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
subplot(2, 2,3);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('BAND PASS FILTER')
%BAND STOP FILTER
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2, 2,4);
plot(o/pi,m, 'k');
ylabel('Gain in db---->');
xlabel('Normalized frequency---->');
title('BAND STOP FILTER')
OUTPUT:
RESULT:

EX.NO. 5 (a)

BUTTERWORTH DIGITAL IIR FILTER

Date:
AIM:
To design a Butterworth digital IIR filter using MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using

5. Find the filter co -efficient.


6. Draw the magnitude and phase response.
PROGRAM:
clear all;
clc;
close all;
format long
rp=input(enter the pass band ripp le);
rs=input(enter the stop band ripple);
wp=input(enter the pass band frequency );
ws=input(enter the sto p band frequency );
fs=input(enter the sampling frequency );
w1=2*wp/fs;
w2=2*ws/fs;
%LOW PASS FILTER
[n,wn]=buttord(w1,w2,rp, rs];
[b,a]=butter(n,wn);
%[b,a]=zp2tf(z,p,k);
[b,a]= butter(n,wn);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
%figure( 1);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;

Ylabel(gain in db>) ;
Xlabel((a)nor malized frequency>);
%figure( 1);
Subplot( 2,1, 2);
Plot(o m/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in r adians>);
%HIGH PASS FILTER
[n,wn]=buttord(w1,w2,rp, rs];
[b,a]=butter(n,wn,high);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
figure(2);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
Ylabel(gain in db>) ;
Xlabel((a)nor malized frequency>);
figure(2);
Subplot( 2,1, 2);
Plot(o m/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in r adians>);
%BAND PASS FILTER
[n]=buttord(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=butter(n,wn,band pass);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
figure(3);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
Ylabel(gain in db>) ;
Xlabel((a)normalized frequency>);
figure(3);
Subplot( 2,1, 2);
Plot(o m/pi,an);
Xlabel((b)normalized frequency>);

Ylabel(phase in radians>);
%BAND STOP FILTER
[n]=butto rd(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=butter(n,wn,band stop);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
figure(4);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
ylabel(gain in db>) ;
xlabel((a)normalized frequency>);
figure(4);
Subplot( 2,1, 2);
Plot(om/pi,an);
xlabel((b)normalized frequency>);
ylabel(phase in radians>);
OUTPUT:
RESULT
:

EX.NO. 5 (b)

CHEBYSHEV DIGITAL IIR FILTER

Date:
AIM:
To design a digital IIR filter using Chebyshev filter with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band fr equencies.
3. Get the sampling frequency.
4. Calculate the order o f the filter using

5. Find the filter co -efficient.


6. Draw the magnitude and phase response.
PROGRAM:
clear all;
clc;
close all;
rp=input(enter the pass band ripple);
rs=input(enter the stop band ripple);
wp=input(enter the pass band frequency );
ws=input(enter the sto p band frequency );
fs=input(enter the sampling frequency );
w1=2*wp/fs;
w2=2*ws/fs;
%LOW PASS FILTER
[n,wn]=cheb ord(w1,w2, rp,rs];
[b,a]=cheby 1(n,wn);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
Ylabel(gain in db>) ;
Xlabel((a)nor malized frequency>);
Subplot( 2,1, 2);
Plot(o m/pi,an);

Xlabel((b)normalized frequency>) ;
Ylabel(phase in r adians>);
%HIGH PASS FILTER
[n,wn]= cheb1 ord(w1,w2,rp,rs];
[b,a]=cheby 1(n,rp,wn, hig h);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
figure(2);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
Ylabel(gain in db>) ;
Xlabel((a)nor malized frequency>);
figure(2);
Subplot( 2,1, 2);
Plot(o m/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in r adians>);
%BAND PASS FILTER
[n]=cheb1 o rd(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=cheby 1(n,rs, wn,band pass);
W=0:0.01:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
figure(3);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
Ylabel(gain in db>) ;
Xlabel((a)nor malized frequency>);
figure(3);
Subplot( 2,1, 2);
Plot(o m/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in r adians>);
%BAND STOP FILTER
[n]=cheb 1 or d(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=cheby 1(n,rp,wn, band stop);

W=0:0.1/pi:pi;
[h,om]=freqz(b, a,w);
m=20*log10(abs(h));
an=ang le(h);
figure(4);
Subplot( 2,1, 1);
Plot(o m/pi,m) ;
Ylabel(gain in db>) ;
Xlabel((a)normalized frequency>);
figure(4);
Subplot( 2,1, 2);
Plot(o m/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
OUTPUT:
RESULT:

Anda mungkin juga menyukai