GENERATION OF SIGNALS
Ex No: 1
Date :
AIM:
To write a program to generate unit impulse, unit step, ramp,
exponential signals, sine and cosine sequences.
ALGORITHM:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Start the program
Input length of the sequence
Generate the time axis
Assign the sample values.
Plot the Waveform
Stop.
PROGRAM:
% Program for Unit impulse signal
clc;
clear all;
close all;
t=-[Link];
y=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(2,2,1);
stem(t,y);
xlabel(Time);
ylabel('Amplitude');
title(UNIT IMPULSE SIGNAL');
% Program for Unit step signal
clc;
clear all;
close all;
n=input(Enter the N value);
t=0:n-1;
y=ones(1,n);
subplot(2,2,2);
stem(t,y);
xlabel(Time);
ylabel(Amplitude);
title(UNIT STEP SIGNAL');
FLOWCHART
START
INPUT LENGTH OF
THE SEQUENCE
GENERATE THE TIME AXIS
ASSIGN THE SAMPLE
VALUES
PLOT THE WAVEFORM
STOP
INPUTS:
For Unit Step Sequence:
Enter the N value = 7
For Exponential Sequence:
Enter the length of exponential sequence = 5
Enter the a value = 1
For Ramp Sequence:
Enter the length of Ramp = 7
% Ramp signal
clc;
clear all;
close all;
n1=input('enter the length of ramp sequence');
t=0:n1;
subplot(2,2,3);
stem(t,t);
xlabel('Time');
ylabel('Amplitude');
title('RAMP SIGNAL');
% Exponential signal
clc;
clear all;
close all;
n=input('Enter the length of exponential sequence');
t=0:n;
a=input('Enter the a value');
y=exp(a*t);
subplot(2,2,4);
stem(t,y);
ylabel('Amplitude');
xlabel('Time');
title('EXPONENTIAL SIGNALS');
% Sine sequence
clc;
clear all;
close all;
t=0:0.01:pi;
y=sin(2*pi*t)
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('SINE SEQUENCE');
% Cosine sequence
clc;
clear all;
close all;
t=0:0.01:pi;
y=cos(2*pi*t)
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('COSINE SEQUENCE');
OUTPUTS:
MATLAB FUNCTIONS:
Zeros(m,n)
zeros array
It creates an M-by-N matrix of zeros
Ones(m,n)
ones array
It creates an M-by-N matrix of ones
Plot(x,y)
linear plot
It plots vector y versus vector x
Stem(x,y)
Discrete sequence orstemplot
It plots the data sequence y at the values specified in x
RESULT:
Thus the representation of signals unit impulse, unit step, ramp,
exponential, sine & cosine sequence was generated using MATLAB.
Ex No: 2
Date :
CONVOLUTION
AIM:
To write a MATLAB program for convolution of two sequences.
LINEAR CONVOLUTION
ALGORITHM:
Step 1:
Step 2:
Step 3:
Get the signals x(n) and h(n) in matrix form.
The co0volved signal is denoted by y(n)
The transformed signals is given by
Y(n)=
x(k) h(n-k) where k=0 to N-1
k=-
PROGRAM:
% Program for Linear convolution
clc;
clear all;
close all;
x=input('Enter the first sequence');
h=input('Enter the second sequence');
y=conv(x,h);
subplot(3,3,1);
stem(x);
xlabel('time');
ylabel('amplitude');
title('First Sequence');
subplot(3,3,2);
stem(h);
xlabel('time');
ylabel('amplitude');
title('Second Sequence');
subplot(3,3,3);
stem(y);
xlabel('time');
ylabel('amplitude');
title('LINEAR CONVOLUTION');
FLOWCHART:
START
INPUT THE REQUIRED
SEQUENCE
PERFORM CONVOLUTION
USING MATLAB
FUNCTIONS
FIND THE LENGTH OF
SEQUENCE
GENERATE THE TIME AXIS
PLOT THE WAVEFORM
STOP
INPUTS:
Linear convolution
Enter the first sequence
=[1
Enter the second sequence = [ 1
2
2]
4]
2
2
4
0
Circular convolution
Enter the first sequence
=[1
Enter the second sequence = [ 1
0]
0]
Circular convolution
ALGORITHM:
step 1: Start the program
step 2: The convolved signals is y(n)
step 3: The y(n) is given by formula
y(n)=y(n)+g(i)*h(j);
PROGRAM:
% program for circular convolution
clc;
clear all;
close all;
% get the input sequence
g=input('Enter the first sequence');
h=input('Enter the second sequence');
% calculate the circularly convolved sequence
N1=length(g);
N2=length(h);
% generate the circularly convolved sequence
N=max(N1,N2);
N3=N1-N2;
if(N3>=0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
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)+[g(i)*h(j)]
end
end
OUTPUTS:
Linear convolution
Circular convolution
% plot the signals
subplot(2,3,1);
stem(g);
xlabel('Time');
ylabel('Amplitude');
title('First Sequence');
subplot(2,3,2);
stem(h);
xlabel('Time');
ylabel('Amplitude');
title('Second Sequence');
subplot(2,3,3);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('CIRCULAR CONVOLUTION');
MATLAB FUNCTIONS:
1) subplot(m,n,p) --- creates axes in tiled positions
It breaks the figure window into an m by n matrix of small axes,
select the p-th axes for the current plot. The axes are counted along the top
row of the figure window, then second row, etc.,
RESULT:
Thus the convolution of two sequences was convolved using Linear
and Circular convolution methods.
FLOWCHART:
START
INPUT THE REQUIRED
SEQUENCE
PERFORM FFT USING
MATLAB FUNCTIONS
FIND THE LENGTH OF
SEQUENCE
GENERATE THE TIME AXIS
PLOT THE WAVEFORM
STOP
INPUT:
FFT
Enter the sequence = [ 1 0
1
Enter the length of sequence = 8
0]
0]
IFFT
Enter the sequence = [ 4 0
0
Enter the length of sequence = 8
Ex No: 3
Date :
CALCULATION OF FFT SIGNALS
AIM:
To write a MATLAB program for the calculation of FFT signals
ALGORITHM:
Step 1:
Step 2:
Step 3:
Get the signals x(n) of the length N in matrix form
Get the N values.
The transformed signals is denoted as
N-1
X(K)= x(n) e-j2kn/N where k=0 to N-1
n=0
PROGRAM:
% Program for calculation of FFT
clc;
clear all;
close all;
x=input('Enter the sequence');
n=input('Enter the length of sequence');
y=length(x);
s=fft(x);
stem(s);
xlabel('Time');
ylabel('Amplitude');
title('FFT');
% Program for calculation of IFFT
clc;
clear all;
close all;
x=input('Enter the sequence');
n=input('Enter the length of sequence');
y=length(x);
s=ifft(x);
stem(s);
xlabel('Time');
ylabel('Amplitude');
title('IFFT');
OUTPUT:
FFT
IFFT
MATLAB FUNCTIONS:
1) subplot(m,n,p) It breaks the figure window into an m-by-n
matrix of small axes,selects the pth axes of rthe current plkot
the axes are counted along the top row figure window ,then
the second row,etc.,
2) disp(x) displays the array,without print\ing the name
If X is a string,the text is displayed
RESULT:
Thus the calculation of FFT signals using MATLAB program was
generated.
Ex No: 4
Date :
FIR FILTER DESIGN USING WINDOWS
AIM:
To write the MATLAB program for designing FIR filters using
windows
ALGORITHM:
Step 1: Enter the order of the filter
Step 2: Enter the cutoff frequency
Step 3: Enter the beta value for Kaiser Window
Step 4: Generate window for length N+1
Step 5: Generate filter co-efficients
Step 6: Plot the magnitude response
PROGRAM:
% Program for Rectangular window
clc;
clear all;
close all;
rs=input('Enter the Stopband ripple');
rp=input('Enter the Passband ripple');
fp=input('Enter the Passband frequency');
fs=input('Enter the Stopband frequency');
f=input('Enter the Sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=abs(-20*log10(sqrt(rp*rs))-13);
den=14.6*(fs-fp)/f;
n=ceil(num/den);
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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('LPF');
FLOWCHART
START
INPUT ORDER OF THE
FILTER
INPUT THE CUTOFF
FREQUENCY
INPUT THE BETA
VALUE FOR KAISER
WINDOW
GENERATE THE LENGTH
N+1
GENERATE FILTER COEFFICIENT
PLOT THE RESPONSE
STOP
INPUTS:
Enter the Stopband ripple = 0.04
Enter the Passband ripple = 0.05
Enter the Passband frequency = 1500
Enter the Stopband frequency = 2000
Enter the Sampling frequency = 9000
Enter the Beta value = 5.8
% 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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('HPF');
% Band pass filter
wn=[wp,ws]
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=(20*log10(abs(h)));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BPF');
% Band stop filter
wn=[wp,ws]
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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BSF');
OUTPUTS:
RECTANGULAR WINDOW
HAMMING WINDOW
% Program for Hamming window
clc;
clear all;
close all;
rs=input('Enter the stopband ripple');
rp=input('Enter the passband ripple');
fp=input('Enter the passband frequency');
fs=input('Enter the stopband frequency');
f=input('Enter the sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=abs(-20*log10(sqrt(rp*rs))-13);
den=14.6*(fs-fp)/f;
n=ceil(num/den);
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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('LPF');
% 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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('HPF');
HANNING WINDOW
KAISER WINDOW
% Band pass filter
wn=[wp,ws]
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=(20*log10(abs(h)));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BPF');
% Band stop filter
wn=[wp,ws]
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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BSF');
% Program for Hanning window
clc;
clear all;
close all;
rs=input('Enter the Stopband ripple');
rp=input('Enter the Passband ripple');
fp=input('Enter the Passband frequency');
fs=input('Enter the Stopband frequency');
f=input('Enter the Sampling frequency');
wp=2*fp/f;
ws=2*fs/f;
num=abs(-20*log10(sqrt(rp*rs))-13);
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=hanning(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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('LPF');
% 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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('HPF');
% Band pass filter
wn=[wp,ws]
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=(20*log10(abs(h)));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BPF');
% Band stop filter
wn=[wp,ws]
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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BSF');
% Program for Kaiser window
clc;
clear all;
close all;
rs=input('Enter the Stopband ripple');
rp=input('Enter the Passband ripple');
fp=input('Enter the Passband frequency');
fs=input('Enter the Stopband frequency');
f=input('Enter the Sampling frequency');
beta=input('Enter the Beta value');
wp=2*fp/f;
ws=2*fs/f;
num=abs(-20*log10(sqrt(rp*rs))-13);
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=kaiser(n1, beta);
% 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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('LPF');
% 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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('HPF');
% Band pass filter
wn=[wp,ws]
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=(20*log10(abs(h)));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BPF');
% Band stop filter
wn=[wp,ws]
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);
xlabel('Normalized freq');
ylabel('Gain in db');
title('BSF');
MATLAB FUNCTIONS:
1)boxcar- returns the N-point rectangular window
hamming(N) returns the N-point hamming window
hanning(N) returns the N-point hanning window in a
column vector
Kaiser(N,beta) returns the beta-valued N-point Kaiser
window
2)b=fir1(n,wn) designs an Nth order lowpass FIR filter and
returns the filter co-efficients in length N+1 vector b the cutoff
frequency wn must be between 0<wn<1.0
If wn is a two-element vector wn=[w1,w2] Fir1 returns an
order Bbandpass filter with passband w1<w<w2
B=fir1(N,wn,high) designs a highpass filter
B=fir1(N,wn,stop) is a band pass filter if wn=[w1,w2]
RESULT:
Thus the MATLAB program of FIR filter using windows was
written and executed.
FLOWCHART
START
ENTER THE RIPPLE,
EDGE, SAMPLING
FREQUENCIES
CALCULATE THE ORDER
OF THE COEFFICIENT
PLOT THE RESPONSE OF
LOWPASS, HIGHPASS,
BANDPASS & BANDSTOP
FILTER
STOP
Ex No: 5
Date :
IIR FILTER DESIGN
AIM:
To write a MATLAB program for IIR filter design using
1)
Butterworth filter
a) Bilinear transformation
b) Impulse invariant
2)
Chebyshev type-I
ALGORITHM:
Step 1 : Get the passband and stopband ripple
Step 2 : Get the sampling freq
Step 3 : Calculate the order of filter
Step 4 : Find the window co-efficient
Step 5 : To draw the magnitude response.
PROGRAM:
BUTTERWORTH FILTER
clc;
clear all;
close all;
rp=input('Enter the Passband ripple');
rs=input('Enter the Stopband ripple');
wp=input('Enter the Passband edge frequency');
ws=input('Enter the Stopband edge frequency');
fs=input('Enter the Sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
% filter order
[N,wn]=buttord(w1,w2,rp,rs);
% Low pass filter
[B,A]=butter(N,wn);
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,1);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
INPUTS
BUTTERWORTH /CHEBYSHEV
Enter the Passband ripple = 5
Enter the Stopband ripple = 10
Enter the Passband edge frequency = 1200
Enter the Stopband edge frequency = 2000
Enter the Sampling frequency = 7800
BILINEAR
Enter the Passband ripple = 3
Enter the Stopband ripple = 15
Enter the Passband edge frequency = 1256.63
Enter the Stopband edge frequency = 2513.17
Enter the Sampling frequency = 2000
IMPULSE INVARIANT
Enter the Passband ripple = 5
Enter the Stopband ripple = 10
Enter the Passband edge frequency = 1200
Enter the Stopband edge frequency = 2000
Enter the Sampling frequency = 7800
title('LPF');
% High pass filter
[B,A]=butter(N,wn,'high');
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,2);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('HPF');
% Band pass filter
[B,A]=butter(N,[w1,w2]);
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,3);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('BPF');
% Band stop filter
[B,A]=butter(N,[w1,w2],'stop');
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,4);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('BSF');
OUTPUTS
BUTTERWORTH
BILINEAR
IMPULSE INVARIANT
BILINEAR TRANSFORMATION
clc;
clear all;
close all;
rp=input('Enter the Passband ripple');
rs=input('Enter the Stopband ripple');
wp=input('Enter the Passband edge frequency');
ws=input('Enter the Stopband edge frequency');
fs=input('Enter the Sampling frequency');
% Filter order
[N,wn]=buttord(wp,ws,rp,rs,'s');
disp(N);
[num,den]=butter(N,wn,'s');
[b,a]=bilinear(num,den,fs);
freqz(b,a,512,fs);
xlabel('Frequency in Hertz');
ylabel('Gain in dB');
title('Bilinear');
IMPULSE INVARIANT
clc;
clear all;
close all;
rp=input('Enter the Passband ripple');
rs=input('Enter the Stopband ripple');
wp=input('Enter the Passband edge frequency');
ws=input('Enter the Stopband edge frequency');
fs=input('Enter the Sampling frequency');
% Filter order
[N,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(N,wn,'s');
[bz,az]=impinvar(b,a,fs);
freqz(bz,az,512,fs);
xlabel('Frequency in Hertz');
ylabel('Gain in dB');
title('Impulse Invariant');
CHEBYSHEV
PROGRAM:
CHEBYSHEV FILTER
clc;
clear all;
close all;
rp=input('Enter the Passband ripple');
rs=input('Enter the Stopband ripple');
wp=input('Enter the Passband edge frequency');
ws=input('Enter the Stopband edge frequency');
fs=input('Enter the Sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
% filter order
[N,wn]=buttord(w1,w2,rp,rs);
% Low pass filter
[B,A]=butter(N,wn);
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,1);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('LPF');
% High pass filter
[B,A]=butter(N,wn,'high');
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,2);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('HPF');
% Band pass filter
[B,A]=butter(N,[w1,w2]);
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,3);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('BPF');
% Band stop filter
[B,A]=butter(N,[w1,w2],'stop');
[h,w]=freqz(B,A,100);
T=0.001;
hertz=w/(2*pi*T);
subplot(2,2,4);
plot(hertz,abs(h));
xlabel('Hertz');
ylabel('ABS(h)');
title('BSF');
MATLAB FUNCTIONS:
1)BUTTER Butterworth digital & analog filter design
[b,a]=butter(N,wn) designs an Nth order lowpass digital butterworth
filter and returns the filter co=efficient in length N+1
vectors B and A the cutt-off frequency wn must be 0.0<wn<1.0 with
1.0 corresponding to half the sample rate
If wn is a 2-elemented vector, wn=[w1,w2],butter returns an
order 2N bandpass filter with passband w1<w<w2
[b,a]=butter(N,wn,high) designs a highpass filter
[b,a]=butter(N,wn,stop) is a bandstop filter if wn=[w1,w2]
buttord butterworth filter order selection
[N,wn]=buttord filter order returns the order N of the lowest order
digital butterworth filter that loses no more than rp db in the
passband and has atleast rs db of attenuation in the stopband wp and
ws are the passband and stopband edge frequencies.
RESULT:
Thus the MATLAB program for IIR filter using butterworth
filter was designed and executed.
INPUT
Enter the sampling frequency: 1200
OUTPUT
Ex No: 6
Date :
POLYPHASE DECOMPOSITION
AIM:
To write a program to compute Convolution and m-fold decimation by
Polyphase decomposition.
ALGORITHM:
Step 1: Get the input sequence.
Step 2: Get the filter coefficients and also the decimation factor. Find the
response by using convolution.
Step 3: Plot the graph.
PROGRAM:
%Analog signal
t=-0.005:0.00005:0.005; xa=exp(-1000*abs(t));
%Discrete time signal
Fs=input('Enter the sampling frequency(Fs)= '); Ts=1/Fs;
n=-[Link];
xn=exp(-1000*abs(n*Ts));
%Discrete time Fourier transform
N=500;
k=[Link] N;
w=(2*pi*k/N);
X=xn*exp(-j*n'*w); X=abs(X);
%omega range from -Wmax to Wmax
W=[-fliplr(w),w(2:N+1)];
%X over -Wmax to Wmax interval
X=[fliplr(X),X(2:N+1)]; subplot(2,1,1);
plot(t*1000,xa,'k'); grid;
hold on;
stem(n*Ts*1000,xn,'k');
xlabel('time in sec');ylabel('x(n)');
title('discrete time signal');
gtext('Ts=1msec');
hold off;
RESULT:
Thus
the
MATLAB
program
for
DECOMPOSITION was designed and executed.
POLYPHASE
INPUT:
Enter the frequency f1=2.5
Enter the frequency f2=0.32
Enter the cut-off frequency =2.51
OUTPUTS:
SAMPLING OF ANALOG SIGNAL
Ex No: 7
Date :
SAMPLING THEOREM
AIM:
To verify the sampling theorem using MATLAB.
ALGORITHM:
Step 1: Get the input frequency f1 and f2. Assign the value for n.
Step 2: Get the cutoff frequency f c. Calculate the value of x.
Step 3: Calculate the value of x a and x amp.
Step 4: Plot the graph for input sequence X (n),X
a(n),
and X
PROGRAM:
f1=input('Enter the frequency:');
f2=input('Enter the frequency:');
n=0:255;
fc=input('Enter the cut-off frequency');
x=cos(2*pi*f1*n)+cos(2*pi*f2*n);
xa=cos(2*pi*fc*n);
xamp=x.*xa;
subplot(2,2,1);
plot(n,x);
title('x(n)');
xlabel('n');
ylabel('amp');
subplot(2,2,2);
plot(n,xa);
title('xa(n)');
xlabel('n');
ylabel('amp');
subplot(2,2,3);
plot(n,xamp);
title('xamp(n)');
xlabel('n');
ylabel('amp');
RESULT:
Thus sampling theorem was verified by using MATLAB.
amp(n).
Ex No: 7a
Date :
SAMPLING THEOREM
AIM:
To verify the sampling theorem using MATLAB.
ALGORITHM:
Step 1: Sampling frequency and time period is mentioned.
Step 2: Message signal is given as addition of two signals..
Step 3: Calculate FFT of x .
Step 4: Plot the graph for output sequence.
PROGRAM:
Nyquist Rate Sampling
clc;
clear all;
close all;
fs =1400;
t=0:1/fs: 13/fs;
x=cos(2*pi*400*t)+cos(2*pi*100*t);
xm=abs (fft(x));
disp (xm);
k=0: length (xm)-1;
figure (1);
stem (100*k, xm);
xlabel (HZ);
ylabel (Magnitude);
title (NR Sampling);
Under Sampling
clc;
clear all;
close all;
fs =1000;
t=0:1/fs: 10/fs;
x=cos(2*pi*400*t)+cos(2*pi*100*t);
xm=abs (fft(x));
disp (xm);
k=0: length (xm)-1;
figure (1);
stem (100*k, xm);
xlabel (HZ);
ylabel (Magnitude);
title (NR Sampling);
OUTPUTS:
NYQUIST SAMPLING
UNDER SAMPLING
OVER SAMPLING
Over Sampling
clc;
clear all;
close all;
fs =2000;
t=0:1/fs: 20/fs;
x=cos(2*pi*400*t)+cos(2*pi*100*t);
xm=abs (fft(x));
disp (xm);
k=0: length (xm)-1;
figure (1);
stem (100*k, xm);
xlabel (HZ);
ylabel (Magnitude);
title (NR Sampling);
RESULT:
Thus nyquist ,under & over sampling was verified by using
MATLAB.
INPUT:
Enter the input sequence=[0 1 2 3 4 5 6 7 8]
OUTPUT:
Ex No: 8
Date:
DISCRETE FOURIER TRANSFORM
AIM:
To find the DFT of the given sequence using MATLAB.
ALGORITHM:
Step 1: Get the sequence and length of sequence.
Step 2: Perform DFT function.
Step 3: Find absolute value and Phase of DFT sequence X(K).
Step 4: Plot the input sequence and magnitude and phase of DFT
PROGRAM:
x=input('Enter the input sequence');
N=length(x);
for k=1:N
sum=0;
for n=1:N
sum=sum+(x(n)*exp(-j*2*pi*(n-1)*(k-1)/N));
end
y(k)=sum;
end
subplot(2, 2, 1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2, 2, 2);
stem(real(y));
xlabel('n');
ylabel('y(n)');
title('real(y)');
subplot(2, 2, 3);
stem(imag(y));
xlabel('n');
ylabel('y(n)');
title('imag(y)');
disp(x);
disp(real(y));
disp(imag(y));
RESULT:
Thus the DFT of the given sequence was generated using MATLAB.
INPUT:
Enter the input sequence=[0 1 2 3 4]
OUTPUT:
Ex No: 8a
Date :
INVERSE DISCRETE FOURIER TRANSFORM
AIM:
To find the IDFT of the given sequence using MATLAB.
ALGORITHM:
Step 1: Get the sequence.
Step 2: Get the length of the sequence.
Step 3: Initialise the scale for k and n.
Step 4: Use the appropriate function to generate the required transform.
add title to the transform.
PROGRAM
x=input ('Enter the input sequence');
N=length(x);
for n=1:N
Sum=0;
for k=1:N
sum=sum+(x(k)*exp(j*2*pi*(n-1)*(k-1)/N));
end
y(n)=sum/N;
end
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('inputsequence');
subplot(2,2,2);
stem(real(y));
xlabel('n');
ylabel('y(n)');
title('real(y)');
subplot(2, 2, 3);
stem(imag(y));
xlabel('n');
ylabel('y(n)');
title('imag(y)');
disp(x);
disp(real(y));
disp(imag(y));
RESULT:
Thus the IDFT of the given sequence was generated using MATLAB.
IMAGE PROCESSING USING
INPUT TOOL BOX
Ex No: 9
Date :
AIM:
To write MATLAB programs for image processing using
input tool box.
ALGORITHM:
STEP 1: Input the image
STEP 2: Process the image
STEP 3: Display the processed image
PROGRAM:
% Reading an image
clc;
clear all;
close all;
x=imread('[Link]');
imshow(x);
% Reading an Indexed image
clc;
clear all;
close all;
[x,map]=imread('[Link]');
imshow(x,map);
% Resizing an image
clc;
clear all;
close all;
x=imread('[Link]');
y=imresize(x,0.5,'bilinear');
imshow(x)
figure,imshow(y)
% Rotating an image
clc;
clear all;
close all;
x=imread('[Link]');
y=imrotate(x,20,'bilinear');
imshow(x);
figure,imshow(y)
OUTPUTS:
Reading an image
Reading an Indexed image
Resized Image
% Filtering the noise affected image
clc;
clear all;
close all;
x=imread('[Link]');
y=imnoise(x,'salt and pepper',0.02);
z=medfiltz(x);
imshow(x),title('original image')
figure,imshow(y),title('image corrupted by noise');
figure,imshow(z),title('filtered image');
% Filtering the noise affected image
clc;
clear all;
close all;
x=imread('[Link]');
y=imnoise(x,'gaussian',0,0.01);
z=ordflt2(x,5,ones(3,3));
imshow(x),title('original image')
figure,imshow(y),title('image corrupted by noise');
figure,imshow(z),title('filtered image');
% Adjusting the intensity of an image
clc;
clear all;
close all;
i=imread('[Link]');
j=imadjust(i,[0 1],[1 0]);
imshow(i),figure,imshow(j)
RESULT:
Thus the MATLAB program image processing using image
processing tool box was executed.
Rotating Image
Filtering the Noise affected Image
Filtering the Noise affected Image
Adjusting the Intensity of the Image
Ex No: 10
Date :
STUDY OF VARIOUS ADRESSING MODES
AIM:
To study about addressing modes in TMS320C5X debugger.
APPARATUS REQUIRED:
1. System with TMS 320C50 debugger software
2. TMS 320C50 Kit.
3. RS232 cable.
ADDITION
PROGRAM:
INP1
.SET 0H
INP2
.SET 1H
OUT
.SET 2H
.mmregs
.text
START:
LD #140H, DP
RSBX CPL
NOP
NOP
NOP
NOP
LD
INP1, A
ADD INP2, A
STL A, OUT
HLT: B
HLT
SUBTRACTION
PROGRAM:
INP1
.SET 0H
INP2
.SET 1H
OUT
.SET 2H
.mmregs
.text
START:
LD #140H, DP
RSBX CPL
NOP
NOP
NOP
ADDITION
INPUT:
Data Memory:
A000h
A001h
0004h
0004h
OUTPUT:
Data Memory:
A002h
0008h
SUBTRACTION
INPUT:
Data Memory:
A000h
A001h
0004h
0002h
OUTPUT:
Data Memory:
A002h
0002h
MULTIPLICATION
OUTPUT:
A002H 2H
DIVISION
INPUT:
DATA MEMORY
A000H
000AH
A001H
0002H
OUTPUT:
A002H
0005H
NOP
LD
INP1, A
SUB INP2, A
STL A, OUT
HLT: B
HLT
MULTIPLICATION
PROGRAM:
.mmregs
.text
START:
STM #0140H, ST0
STM #40H, PMST
STM #0A000H, AR0
ST
#1H,*AR0
LD *AR0+, T
ST
#2H,*AR0
MPY *AR0+, A
STL A,*AR0
HLT: B
HLT
DIVISION
PROGRAM:
DIVID
DIVIS
OUT
.SET 0H
.SET 1H
.SET 2H
.mmregs
.text
START:
STM #140H, ST0
RSBX CPL
RSBX FRCT
NOP
NOP
NOP
NOP
LD
DIVID, A
RPT #0FH
SUBC DIVIS, A
STL A, OUT
HLT: B
HLT
RESULT:
Thus, the arithmetic operations using TMS320C5x was performed
successfully.
CIRCULAR AND LINEAR CONVOLUTION
Ex No: 11
Date :
AIM:
To implement circular and linear convolution in TMS320C5x debugger.
APPARATUS REQUIRED:
1. System with TMS 320C5x debugger software
2. TMS 320C5x Kit.
3. RS232 cable.
CIRCULAR CONVOLUTION FOR FOUR INPUTS
PROGRAM:
.mmregs
.text
START:
STM #0140H,ST0
RSBX CPL
RSBX FRCT
NOP
NOP
NOP
NOP
STM #0A020H,AR2
RPT #4H
ST #0H,*AR2+
STM #0A000H,AR0
STM #0A010H,AR1
STM #0A020H,AR2
STM #0A030H,AR3
STM #3H,AR4
CALL ROT1
CALL CONV
NEXTY: CALL ROT2
CALL CONV
BANZ NEXTY,*AR4HLT: B HLT
ROT1:
STM #0A011H,AR0
STM #0A013H,AR1
LD *AR0,A
LD *AR1,B
STL A,*AR1
STL B,*AR0
RET
ROT2:
STM #0A013H,AR0
STM #0A012H,AR1
LD *AR0,A
STM #2H,BRC
RPTB ROT
LD *AR1-,B
ROT:
STL B,*AR0STM #0A010H,AR0
STL A,*AR0
STM #0H,BRC
RET
CONV:
STM #0A000H,AR0
STM #0A010H,AR1
LD #0H,A
STM #3H,BRC
RPTB CON
LD *AR0+,T
CON:
MAC *AR1+,A
STL A,*AR3+
RET
CONVOLUTION FOR FOUR INPUTS
PROGRAM:
.mmregs
.text
START:
STM #40H,ST0
RSBX CPL
RSBX FRCT
NOP
NOP
NOP
NOP
STM #0A000H,AR0
STM #00100H,AR1
STM #0A020H,AR2
LD #0H,A
RPT #4H
STL A,*AR2+
STM #0A004H,AR0
CIRCULAR CONVOLUTION FOR FOUR INPUTS
INPUT:
X1(n) DATA MEMORY
0A000
0A001
0A002
0A003
INPUT:
0A010
0A011
0A012
0A013
OUTPUT
0002
0001
0002
0001
X2(n) DATA MEMORY
0001
0002
0003
0004
: Y(n) DATA MEMORY
0A030
0A031
0A032
0A033
000E
0010
000E
0010
CONVOLUTION FOR FOUR INPUTS
INPUT:
0A000
0A001
0A002
0A003
INPUT:
00100
00101
00102
00103
OUTPUT:
0A030
0A031
0A032
0A034
0A035
X(n)
DATA MEMORY
0001H
0003H
0001H
0003H
H(n)
PROGRAM MEMORY
0000H
0001H
0002H
0001H
Y(n)
0001
0005
0008
0008
0007
;h(n)
DATA MEMORY
LD #0H,A
RPT #5H
STL A,*AR0+
STM #0A000H,AR0
STM #0A020H,AR2
STM #0A030H,AR3
STM #6H,BRC
RPTB CONV
LD *AR0+,A
STM #0A020H,AR2
STL A,*AR2
STM #0A023H,AR2
LD #0H,A
RPT #3H
MACD *AR2-,0100H,A
CONV STL A,*AR3+
HLT:
B HLT
RESULT:
Thus the linear and circular convolution of two sequences is done
successfully by using TMS320C5x.
Ex No: 12
Date :
SAMPLING OF ANALOG SIGNALS
AIM:
To implement sampling of analog signal in TMS320C5xdebugger.
APPARATUS REQUIRED:
1. System with TMS 320C5x debugger software
2. TMS 320C5x Kit.
3. RS232 cable.
SAMPLING
PROGRAM:
.mmregs
.text
START:
STM # 01h, ST0
RSBX CPL
RSBX FRCT
NOP
NOP
NOP
NOP
*****loop to make x(n) zero initially*****
STM # 150H,AR1
LD
# 0H,A
RPT # 34H
STL A,*AR1+
STM # 3H,AR3
LOOP:
LD
# 0H,A
BANZ DEL0,*AR3PORTR 04,0
LD
0,A
AND # 0FFFH,A
XOR # 0800H,A
SUB # 800H,A
PORTR 06,0
STM # 3H,AR3
B
STORE
DEL0:
RPT # 10
NOP
*****filtering operation*****
STORE:
STM # 150H,AR1
STL A,*AR1
STM # 183H,AR2
LD
# 0H,A
*****loop for convolution process*****
RPT # 33H
MACD *AR2-,TABLE,A
STH A,1,0H
MPY 0H,# 4H,A
LD
0H,A
ADD # 800H,A
STL A,1H
PORTW 1H,04H
B
LOOP
TABLE:
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
65H
0FF97H
0FED1H
0FE48H
0FE24H
0FE78H
0FF3CH
46H
15EH
23BH
29FH
25FH
174H
0H
0FE4CH
0FCBAH
0FBB9H
0FBAAH
0FCCFH
0FF37H
2BAH
6F9H
0B6FH
0F7FH
1297H
1443H
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
1443H
1297H
0F7FH
0B6FH
6F9H
2BAH
0FF37H
0FCCFH
0FBAAH
0FBB9H
0FCBAH
0FE4CH
0H
174H
25FH
29FH
23BH
15EH
46H
0FF3CH
0FE78H
0FE24H
0FE48H
0FED1H
0FF97H
65H
RESULT:
Thus the sampling process is verified and executed using TMS320C5X.
WAVEFORM GENERATION
Ex No: 13
Date :
AIM:
To implement different waveforms in TMS320C5X debugger.
APPARATUS REQUIRED:
1. System with TMS 320C5X debugger software
2. TMS 320C5X Kit.
3. RS232 cable.
4. Function generator.
SAWTOOTH WAVE GENERATION
PROGRAM:
DATA
.SET 0H
.mmregs
.text
START:
STM #140H, ST0
RSBX CPL
NOP
NOP
NOP
NOP
REP:
ST
#0H, DATA
INC:
LD
DATA, A
ADD #1H, A
STL A, DATA
PORTW DATA, 04H
CMPM DATA, #0FFFH
BC
INC, NTC
B
REP
SQUARE WAVE GENERATION
PROGRAM:
DATA
.SET 0H
.mmregs
.text
START:
STM #140H,ST0
RSBX CPL
NOP
NOP
NOP
NOP
REP:
ST
#0H,DATA
CALL DELAY
ST
#0FFFH,DATA
CALL DELAY
B
REP
DELAY:
STM #0FFFH,AR1
DEL1:
PORTW DATA,04H
BANZ DEL1,*AR1RET
TRIANGULAR WAVE GENERATION
PROGRAM:
DATA
.SET 0H
.mmregs
.text
START:
STM #140H,ST0
RSBX CPL
NOP
NOP
NOP
NOP
REP:
ST
#0H,DATA
INC:
LD
DATA,A
ADD #1H,A
STL A,DATA
PORTW DATA,04H
CMPM DATA,#0FFFH
BC
INC,NTC
DEC:
LD
DATA,A
SUB #1H,A
STL A,DATA
PORTW DATA,04H
CMPM DATA,#0H
BC
DEC,NTC
B
REP
RESULT:
Thus the waveforms were generated and executed using TMS320C5X.
Ex No: 14
Date :
FIR FILTER
AIM:
To implement FIR band pass filter in TMS320C5x debugger.
APPARATUS REQUIRED:
1. System with TMS 320C5x debugger software
2. TMS 320C5x Kit.
3. RS232 cable.
4. Function generator.
BAND PASS FIR FILTER
PROGRAM:
.mmregs
.text
START:
STM #01h,ST0
RSBX CPL
RSBX FRCT
NOP
NOP
*****loop to make all x(n) zero initially*****
STM #150H,AR1
LD #0H,A
RPT #34H
STL A,*AR1+
*****to read the adc data and store it in x(0)*****
LOOP:
PORTR 06,0
CHK_BUSY:
;PORTR 07,0
; BITF 0,#20H
; BC
CHK_BUSY,TC
PORTR 04,0
LD 0,A
AND #0FFFH,A
XOR #0800H,A
SUB #800H,A
STM #150H,AR1
STL A,*AR1
STM #183H,AR2
*****start of convolution*****
LD #0H,A
RPT #33H
MACD *AR2-,TABLE,A
STH A,1,0H
LD 0H,A
ADD #800H,A
STL A,1H
PORTW 1H,04H
B
LOOP
TABLE:
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
.word
208H
257H
218H
143H
0H
0FE9EH
0FD7AH
0FCE7H
0FD08H
0FDD1H
0FEECH
0FFE4H
3DH
0FFA1H
0FDFCH
0FB8FH
0F8ECH
0F6D4H
0F608H
0F713H
0FA21H
0FEE6H
4A7H
0A60H
0EF8H
1187H
1187H
0EF8H
0A60H
4A7H
0FEE6H
0FA21H
0F713H
0F608H
0F6D4H
0F8ECH
0FB8FH
0FDFCH
0FFA1H
3DH
0FFE4H
0FEECH
0FDD1H
0FD08H
.word
.word
.word
.word
.word
.word
.word
.word
0FCE7H
0FD7AH
0FE9EH
0H
143H
218H
257H
208H
RESULT:
Thus the FIR band pass filter was executed successfully.