Estd. 1995
Name
Reg No.
Branch
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 --->');
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)
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:
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.
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:
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)
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
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)
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
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: