DSP Lab Manual PDF
DSP Lab Manual PDF
0 -/3/- 2
Department of ECE
SVS Institute of Technology
The name MATLAB stands for matrix laboratory. It was invented in the late
1970s by Cleve Moler, then chairman of the computer science department at the University of
New Mexico. MATLAB has evolved over a period of years with input from many users. In
university environments, it is the standard instructional tool for introductory and advanced
courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for
high-productivity research, development and
analysis.
MATLAB was first adopted by control design engineers, Little's specialty, but quickly spread to
many other domains. It is now also used in education, in particular the teaching of linear algebra
and numerical analysis, and is popular amongst scientists involved with image processing.
Department of ECE
SVS Institute of Technology
1. DATA SECURITY
2. IMAGE MANIPULATIONS
3. SIGNAL PROCESSING
MATLAB Windows:
Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the MATLAB
prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color the
user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called M
files.
Input-output:
MATLAB supports interactive computation taking the input from the screen and flushing, the
output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data -type in MATLAB is the array. It encompasses several distinct
data objects- integers, real numbers, matrices, character strings, structures and cells. There is no
need to declare variables as real or complex, MATLAB automatically sets the variable to be real.
Department of ECE
SVS Institute of Technology
1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an
increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
3. T= 0:1/pi: 1
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]
5. zeros( 2,4)
Output = 0 0 0 0
0000
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
9. plot (t, x)
If x = [6 7 8 9] t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
10. stem (t,x) :- This instruction will display a figure window as shown
11. Conv
Syntax: w = conv(u,v)
12.Disp
Syntax: disp(X)
Department of ECE
SVS Institute of Technology
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed.Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable.Note that disp does not display
empty arrays.
13.xlabel
Syntax: xlabel('string')
14. ylabel
Syntax : ylabel('string')
15.Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current axes.
16.grid on
Syntax : grid on
Department of ECE
SVS Institute of Technology
Y = INTERP(X,L) resamples the sequence in vector X at L times the original sample rate. The
resulting resampled vector Y is L times longer, LENGTH(Y)= L*LENGTH(X).
Y = DECIMATE(X,M) resamples the sequence in vector X at 1/M times the original sample
rate. The resulting resampled vector Y is M times shorter, i.e., LENGTH(Y) =
CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th order Chebyshev
Type I lowpass filter with cutoff frequency .8*(Fs/2)/R, before resampling.
Department of ECE
SVS Institute of Technology
Experiment No.1
Generation of sinusoidal waveform / signal based on recursive difference equations
PROGRAM:
xlabel('Time')
ylabel('Amplitude')
Enter the value of initial condition y(-1)
I=4
Enter the frequency
f =10
Expected Waveform:
0.5
Amplitude
0
-0.5
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time
Sinusoidal Response y(n) of the given first order system
40
Amplitude
30
20
10
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 2
Histogram of White Gaussian Noise and Uniformly Distributed Noise.
Aim: Histogram of White Gaussian Noise and Uniformly Distributed Noise using MAT Lab.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:-
1) Open MATLAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Program:
clc;
clear all;
x1=randn(1,5000);
x2=randn(1,5000);
figure;
plot(x1,x2,'.')
title('scattered plot of Gaussian Distribution Random numbers');
x1=rand(1,5000);
x2=rand(1,5000);
figure;
plot(x1,x2,'.')
title('scattered plot of uniform Distribution Random numbers');
x3=rand(1,100000);
figure;
subplot(2,1,1);
hist(x3)
title('uniform Distribution ');
y=randn(1,100000);
Department of ECE
SVS Institute of Technology
subplot(2,1,2);
hist(y)
title('Gaussian Distribution');
ymu=mean(y);
ymsq=sum(y.^2)/length(y);
ysigma=std(y);
yvar=var(y);
yskew=skewness(y);
ykurt=kurtosis(y);
Expected Graph:
Department of ECE
SVS Institute of Technology
uniform Distribution
15000
10000
5000
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
4
x 10 Gaussian Distribution
4
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Result:.
Department of ECE
SVS Institute of Technology
Experiment No: 3
To find DFT / IDFT of given DT signal.
Procedure:-
1) Open MATLAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Program:
disp(X_k);
mag=abs(X_k);
phase=angle(X_k)*180/pi;
subplot(2,1,1);
stem(mag);
grid on;
xlabel('frequency index k');
ylabel('Magnitude of X[k]');
axis([0 N+1 -2 max(mag)+2]);
subplot(2,1,2);
stem(phase);
grid on;
xlabel('frequency index k');
ylabel('Phase of X[k]');
axis ([0 N+1 -180 180]);
Output:
Enter the sequence x[n]= [ ]
Enter the value N point=
N point DFT is X[k] =
Expected Graph:
Result:.
Department of ECE
SVS Institute of Technology
Experiment No.4
To find frequency response of a given system given in (Transfer Function/ Differential
equation form).
Procedure:-
1) Open MATLAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Program:
clc;
clear all;
close all;
b=[1,4]; %Numerator coefficients
a=[1,-5]; %Denominator coefficients
w=-2*pi:pi/256:2*pi;
[h]=freqz (b, a, w);
subplot(2, 1,1),
plot(w,abs(h));
xlabel('Frequency \omega');
ylabel('Magnitude');
grid on;
subplot(2, 1, 2);
plot(w, angle(h));
xlabel('Frequency \omega');
Department of ECE
SVS Institute of Technology
ylabel('Phase - Radians');
grid on;
Expected Waveform:
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 5
Implementation of FFT of given sequence.
Aim: To determine the N-point FFT of a given sequence.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:-
1) Open MATLAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Program:
clc;
clear all;
close all;
x=input ('enter the sequence='); %x[n] sequence
n=input ('enter the length='); %N points for FFT
xk=fft(x,n); %computes FFT
disp (xk);
subplot(2,2,1);
stem(x,'filled');
title('plot of input sequence');
subplot(2,2,2);
stem(real(xk),'filled');
title('plot of real xk');
subplot(2,2,3);
stem(abs(xk),'filled');
title('Magnitude spectrum');
subplot(2,2,4);
Department of ECE
SVS Institute of Technology
stem(angle(xk),'filled');
title('Phase spectrum');
Expected Waveform:
0.8090 + 2.4899i
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 6
Determination of Power Spectrum of a given signal(s).
Procedure:-
1) Open MAT LAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Program:
hold on;
pxx3=psd(y, N, fs, s)
plot (pxx3,'b');
hold on;
xlabel ('-->Frequency');
ylabel ('-->Magnitude');
title ('POWER SPECTRAL DENSITY OF A SEQUENCE');
hold off;
Output:
enter the length of the sequence=5
enter the sequence=[3 4 5 6 7]
enter sampling frequency=200
enter the value of N=5
enter the window name1=triang (N)
enter the window name2=Kaiser (N, 4.5)
enter the window name3=rectwin (N)
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 7
Implementation of LP FIR & HP FIR filters for a given sequence.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:-
1) Open MATLAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Algorithm:
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
3) Get the sampling frequency (f), beta value.
4) Calculate the analog pass band edge frequencies, w1 and w2.
w1 = 2*fp/f
w2 = 2*fs/f
5) Calculate the numerator and denominator
6) Use an If condition and ask the user to choose either Rectangular Window or Triangular
Window or Kaiser Window.
7) Use rectwin, triang, Kaiser Commands
8) Calculate the magnitude of the frequency response in decibels (dBm=20*log10(abs( h))
9) Plot the magnitude response [magnitude in neither dB Vs nor malized frequency (om/pi)]
10) Give relevant names to x and y axes and gives an appropriate ate title for the plot.
11) Plot all the responses in a single figure window. [Make use of subplot]
Department of ECE
SVS Institute of Technology
Program:
Department of ECE
SVS Institute of Technology
y=kaiser( n1,beta);
disp('Kaiser window filter response');
end
%LPF
b=fir1( n,wp,y) ;
[h,o]=freqz(b,1,256);
m=20*log10 (abs (h));
plot(o/pi, m);
title('LPF Rectangular window filter response');
ylabel('Gain in dB-->');
xlabel(' Normalized frequency-->');
Expected Output:
Rectangular window filter response
enter pass band ripple =0.02
enter the stop band ripple =0.04
enter passband freq =1000
enter stopband freq =2000
enter sampling freq =5000
enter beta value =
enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1
Rectangular window filter response
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 8
Implementation of HP FIR filters for a given sequence.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:-
1) Open MAT LAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Algorithm:
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs).
3) Get the sampling frequency (f), beta value.
4) Calculate the analog pass band edge frequencies, w1 and w2.
w1 = 2*fp/f
w2 = 2*fs/f
5) Calculate the numerator and denominator
6) Use an If condition and ask the user to choose either Rectangular Window or Triangular
Window or Kaiser Window.
7) Use rectwin, triang, Kaiser Commands
8) Calculate the magnitude of the frequency response in decibels (dBm=20*log10(abs( h))
9) Plot the magnitude response [magnitude in neither dB Vs nor malized frequency (om/pi)]
10) Give relevant names to x and y axes and gives an appropriate ate title for the plot.
11) Plot all the responses in a single figure window. [Make use of subplot]
Department of ECE
SVS Institute of Technology
Program:
%FIR HP Filter design window techniques.
clc; clear all;
close all;
rp=input('enter passband ripple =');
rs=input('enter the stopband ripple =');
fp=input('enter passband freq =');
fs=input('enter stopband freq =');
f=input('enter sampling freq =');
beta=input('enter beta value =');
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
c=input('enter your choice of window 1. rectangular 2. triangular 3.kaiser: \n ') ;
if(c==1)
y=rectwin( n1);
disp('Rectangular window filter response');
end
if(c==2)
y=triang(n1);
disp('Triangular window filter response') ;
end
if(c==3)
y=kaiser( n1,beta);
Department of ECE
SVS Institute of Technology
Expected Output:
Rectangular window filter response
enter passband ripple =0.04
enter the stopband ripple =0.05
enter passband freq =2000
enter stopband freq =2500
enter sampling freq =6000
enter beta value =
enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1
Rectangular window filter response
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 9
Implementation of LP IIR filter for a given sequence
Aim: -To Design and generate IIR Butterworth Analog LP Filter using MATLAB
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:
1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in current directory
5)Compile and Run the program
6)For the output see command window \ Figure window
Algorithm:-
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency ( fs).
3) Get the sampling frequency ( f).
4) Calculate the analog pass band edge frequencies, w1 and w2.
w1 = 2*fp/f
w2 = 2*fs/f
5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following
function] [n,wn]=buttord (w1,w2,rp,rs, s )
6) Des ign an nth order analog lowpass Butter worth filter using the following statement.
[b,a]=butter (n,wn, s )
7) F ind the complex frequency response of the filter by using , freqs( ) function
[h,om]=freqs(b,a,w) where, w = 0:.01:pi
This function retur ns complex frequency response vector „ h and frequency vector „ om in
radians /samples of the filter.
8) Calculate the magnitude of the fr equency response in decibels (dB m=20*log10(abs( h))
9) Plot the magnitude response [magnitude in dB Vs nor malized frequency (om/pi)]
Department of ECE
SVS Institute of Technology
Program:
% IIR LP filters.
clc;
clear all;
close all;
warning off;
disp('enter the IIR LP filter design specifications');
rp=input('enter the passband ripple =');
rs=input('enter the stopband ripple =');
wp=input('enter the passband freq =');
ws=input('enter the stopband freq =');
fs=input('enter the sampling freq =');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord (w1, w2, rp, rs,'s'); % Find the order n and cut-off frequency
disp ('Frequency response of IIR HPF is :');
[b,a]=butter (n, wn,'low','s'); % Find the filter co-efficients of LPF
w=0:.01:pi;
[h,om]=freqs(b,a,w); % Plot the frequency response
m=20*log10(abs( h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Low Pass filter is:');
xlabel('(a)Nor malized freq. -->');
ylabel('Gain in dB-->');
an=angle(h) ;
Department of ECE
SVS Institute of Technology
subplot(2,1,2);
plot(om/pi,an);
title('phase respons e of IIR Low Pass filter is:');
xlabel('(b)Normalized freq. -->');
ylabel('Phase in radians -->');
Expected Output:
enter the IIR LP filter design specifications
enter the passband ripple =0.5
enter the stopband ripple =60
enter the passband freq =400
enter the stopband freq =600
enter the sampling freq =1000
Frequency response of IIR LPF is :
Result:
Department of ECE
SVS Institute of Technology
Department of ECE
SVS Institute of Technology
xlabel('Normalised frequency');
ylabel('Phase in degrees');
grid;
Output:
Figure: 1
Figure: 2
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 10
Implementation of HP IIR filter for a given sequence
Aim: To Design and generate IIR Butterworth Analog HP Filter using MATLAB
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:
1)Open MATLAB
2)Open new M- file
3)Type the program
4)Save in cur rent directory
5)Compile and Run the program
6)For the output see command window \ Figure window
Algorithm:
1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency ( fp) and stop band frequency ( fs).
3) Get the sampling frequency ( f).
4) Calculate the analog pass band edge frequencies, w1 and w2.
w1 = 2*fp/f
w2 = 2*fs/f
5) Calculate the order and 3dB cutoff frequency of the analog filter. [Make use of the following
function] [n,wn]=buttord (w1, w2, rp,rs, s )
6) Des ign an nth order analog lowpass Butter worth filter using the following statement.
[b,a]=butter (n,wn, s )
7) F ind the complex frequency response of the filter by using „freqs( ) function
[h,om]=freqs(b,a,w) where, w = 0:.01:pi This function retur ns complex frequency
response vector „ h and frequency vector „ om in radians /samples of the filter.
8) Calculate the magnitude of the fr equency response in decibels (dB m=20*log10(abs( h))
Department of ECE
SVS Institute of Technology
Department of ECE
SVS Institute of Technology
subplot(2,1,2);
plot(om/pi,an);
title('phase respons e of IIR HIGH Pass filter is:');
xlabel('(b)Normalized freq. -->');
ylabel('Phase in radians -->');
Output:
enter the IIR HP filter design specifications
enter the passband ripple =0.5
enter the stopband ripple =60
enter the passband freq =400
enter the stopband freq =600
enter the sampling freq =1000
Frequency response of IIR HPF is:
Department of ECE
SVS Institute of Technology
Result:
%IIR Chebyshew type I high pass filter
Program:
% IIR Chebyshew type I high pass filter
clear all;
close all;
clc;
wp=input('Enter the passband edge Normalised frequency = ');
ws=input('Enter the stopband edge Normalised frequency = ');
Rp=input('Enter the passband attenuation level (dB) = ');
Rs=input('Enter the stopband attenuation level (dB) = ');
[N,wn]=cheb1ord(wp,ws,Rp,Rs);
[b,a]=cheby1(N,Rp,wn,'high'); %High pass filter
[h,w]=freqs(b,a);
mag=20*log10(abs(h));
phase=180*angle(h)/pi;
figure(1);
plot(w,abs(h));
title('Chebyshev Lowpass Filter');
xlabel('Normalised frequency');
ylabel('Magnitude');
grid;
figure(2);
subplot(2,1,1);
plot(w,mag);
title('Magnitude response');
xlabel('Normalised frequency');
ylabel('Magnitude in dB');
grid;
subplot(2,1,2);
Department of ECE
SVS Institute of Technology
plot(w,phase);
title('Phase response');
xlabel('Normalised frequency');
ylabel('Phase in degrees');
grid;
Expected Output:
Enter the passband edge Normalised frequency = 0.2*pi
Enter the stopband edge Normalised frequency = 0.1*pi
Enter the passband attenuation level (dB) = 1
Enter the stopband attenuation level (dB) = 15
>> 2
Figure: 1
Figure: 2
Result: .
Department of ECE
SVS Institute of Technology
Experiment No: 11
Generation of Narrow Band Signal through Filtering
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
PROGRAM:
clc;
clear all;
close all;
echo on;
t0=.2; % signal duration
ts=0.001; % sampling interval
fc=250; % carrier frequency
fs=1/ts; % sampling frequency
t=[-t0/2:ts:t0/2]; % time vector
kf=100; % deviation constant
m=cos(2*pi*10*t); % the message signal
int_m(1)=0;
for i=1:length(t)-1 % integral of m
int_m(i+1)=int_m(i)+m(i)*ts;
echo off ;
end
echo on ;
u=cos(2*pi*fc*t+2*pi*kf*int_m); % modulated signal
%now lets filter the signal
[z,p] = butter(1,2*50/fs,'low');
Department of ECE
SVS Institute of Technology
Expected Output:
Result: .
Department of ECE
SVS Institute of Technology
Experiment No: 12
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
THEORY: Introduction Analog DTMF telephone signaling is based on encoding standard
telephone. Keypad digits and symbols in two audible sinusoidal signals of frequencies FL and
FH. Thus the scheme gets its name as dual tone multi frequency (DTMF).
12 13 14 16
Hz
09 36 77 33
697 1 2 3 A
770 4 5 6 B
852 7 8 9 C
941 * 0 # D
Each digit or symbol represented in figure 1 has 2 distinct high and low frequency components.
Thus each high-low frequency pair uniquely identifies the corresponding telephone keypad digit
or symbol. Each key pressed can be represented as a discrete time signal of form
dt[n] = sin[ωLn] + sin[ωLn] , 0 ≤ n ≤ N-1 (1)
Where N is defined as number of samples taken. Typically in the sampling frequency used is
8khz. Thus if the two individual frequency components of the signal can be identified then the
number dialed can be decoded.
-- In this report I have used (dual tone and digit/symbols) interchangeably but both mean the
same. Dual tone means the encoded samples of the corresponding DTMF digits/symbols.
The DTMF encoder is implemented in MATLAB function dtmfe.m. The implementation is
based on a digital oscillator, that will generate sinusoidal tones at frequencies Fo in response to an
input signal x[n] = δ[n]. Note :Implementation of DTMF Encoder
Department of ECE
SVS Institute of Technology
PROGRAM:
%Generation of DTMF signals
Fs = 8000; % Sampling frequency
Ts = 1/Fs;
Numof_samples =input('enter the no of samples');
dialnumber=input('enter the dial number');
T = Ts*(0:Numof_samples-1)';
switch dial_num
case 0
F1 = 941;
F2 = 1336;
case 1
F1 = 697;
F2 = 1209;
case 2
F1 = 697;
F2 = 1336;
case 3
F1 = 697;
F2 = 1477;
case 'A'
F1 = 697;
F2 = 1633;
case 4
F1 = 770;
F2 = 1209;
Department of ECE
SVS Institute of Technology
case 5
F1 = 770;
F2 = 1336;
case 6
F1 = 770;
F2 = 1477;
case 'B'
F1 = 770;
F2 = 1633;
case 7
F1 = 852;
F2 = 1209;
case 8
F1 = 852;
F2 = 1336;
case 9
F1 = 852;
F2 = 1477;
case 'C'
F1 = 852;
F2 = 1633;
case '*'
F1 = 941;
F2 = 1209;
case '#'
F1 = 941;
F2 = 1477;
Department of ECE
SVS Institute of Technology
otherwise
F1 = 941;
F2 = 1633;
end;
firstsine = cos(2*pi*F1*T); % first sinusoidal signal
secondsine = cos(2*pi*F2*T); % second sinusoidal signal
d = firstsine + secondsine;
dtmfoutput = d ;
figure(1);
title('THE DTMF OUTPUT');
plot(dtmfoutput);
RESULT:
Department of ECE
SVS Institute of Technology
Experiment No: 13
Implementation of Decimation Process
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:
Theory:
Sampling rate conversion (SRC) is a process of converting a discrete-time signal at a given rate
to a different rate. This technique is encountered in many application areas such as:
Digital Audio
Communications systems
Speech Processing
Antenna Systems
Department of ECE
SVS Institute of Technology
Sampling rates may be changed upward or downward. Increasing the sampling rate is called
Interpolation and decreasing the sampling rate is called decimation. Reducing the sampling rate
by a factor of M is achieved by discarding ever y M- 1 samples, or, equivalently keeping
every M th sample. Increasing the sampling rate by a factor of L ( interpolation by factor L) is
achieved by inserting L- 1 zeros into the output stream after ever y sample from the input
stream of samples. This system can perform SRC for the following cases:
• Decimation by a factor of M
• Interpolation by a factor of L
Decimator:
To reduce the sampling rate by an integer factor M, assume a new sampling period.The re-
sampled signal is The system for performing this operation, called down- sampler, is shown
below: Down-sampling generally results in aliasing. Therefore, in order to prevent aliasing, x (n)
Should be filtered prior to down-sampling with a low-pass filter that has a cutoff frequency The
cascade of a low-pass filter with a down- sampler illustrated below and is called
Decimator.
Program:
Department of ECE
SVS Institute of Technology
subplot(2,1,1);
stem(n,x(1:N) );
title('Input Sequence') ;
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m=0:(N/M)-1;
stem(m,y(1:N /M));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude') ;
Expected Output:
Result:
Note: Observe the Output Sequence for Different values of M.
Department of ECE
SVS Institute of Technology
Experiment No: 14
Implementation of Interpolation Process.
Aim: To perform interpolation process using Mat lab.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:
1) Open MAT LAB
2) Open new M- file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window \ Figure window
Theory:
To increase the sampling rate by an integer factor L. I f xa(t) is sampled with a sampling
frequency fs = 1/Ts, then To increase the sampling rate by an integer factor L, it is necessary to
extract the samples from x(n). The samples of xi( n) for values of n that are integer multiples of
L are easily extracted from x(n) as follows:
The system per forming the operation is called up- sampler and is shown below:
After up-sampling, it is necessary to remove the frequency scaled images in xi(n), except
those that are at integer multiples of 2p. This is accomplis hed by filter ing xi(n) with a low- pass
filter that has a cutoff frequency of p /L and a gain of L. In the time domain, the low -pass filter
inter - polates between the samples at integer multiples of L as shown below and is called
interpolator.
Program:
% Illustration of Interpolation Process
clc;
close all;
clear all;
L=input('Up-sampling factor = ') ;
Department of ECE
SVS Institute of Technology
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 15
Implementation of I/D sampling rate converters.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Procedure:
Theory:
Department of ECE
SVS Institute of Technology
I f M> L, the resulting operation is a decimation process by a non- integer, and when M<L it is
Interpolation. I f M=1, the generalized system reduces to the simple integer interpolation and if
Program:
clc;
close all;
clear all;
L=input('Enter Up-sampling factor :');
M=input('Enter Down-sampling factor :');
N=input('Enter number of samples :');
n=0:N- 1;
x=sin(2*pi*0.43*n)+sin(2*pi*0.31*n);
y=resample(x,L,M) ;
subplot(2,1,1);
stem(n,x(1:N) );
axis([0 29 -2.2 2.2]);
title('Input Sequence') ;
xlabel('Time index n');
ylabel('Amplitude') ;
subplot(2,1,2);
m=0:(N*L/M)-1;
stem(m,y(1:N*L/M));
axis([0 (N*L/M)-1 -2.2 2.2]);
title('Output Sequence');
xlabel('Time index n');
Department of ECE
SVS Institute of Technology
ylabel('Amplitude') ;
Expected Output:
Enter Up-sampling factor: 6
Enter Down-sampling factor: 3
Enter number of samples: 40
Result:
Department of ECE
SVS Institute of Technology
Experiment No: 16
IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER SYSTEM
Aim: To determine the response of first order and second order systems.
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
PROGRAM:
%impulse response of a first order system
clear all;
b=[1];
a=[1,-.8];
w=0:0.1:2*pi;
[h]=freqz(b,a,w);
subplot(2,1,1);
plot(w/pi,abs(h));
xlabel('normalised frequency\omega/\pi'), ylabel('magnitude');
title('impulse response of first order system h(n)=(0.8)^n u(n)');
subplot(2,1,2);
plot(w/pi,angle(h));
xlabel('normalised frequency'), ylabel('phase angle in radians');
Expected Output:
Department of ECE
SVS Institute of Technology
RESULT:
Department of ECE