DSP LAB MANUAL 2017 ODD RMK PDF
DSP LAB MANUAL 2017 ODD RMK PDF
DSP LAB MANUAL 2017 ODD RMK PDF
ENGINEERING COLLEGE
R.S.M. Nagar, Kavaraipettai – 601 206
EC6511
Prepared By
1.Ms.K.Sumathy AP/ECE
2.Mr.A.Darwin NesaKumar AP/ECE
3.Mr.P.Gunasekhar,AP/ECE
Approved By
9 Multirate Filters
14 Circular Convolution
15 Waveform generation
LIST OF EXPERIMENTS:
TOTAL= 45 PERIODS
EX.NO:1 STUDY OF MATLAB
AIM:
To study about MATLAB 7.10 (2010a)
MATLAB:
MATLAB® is a high performance language for technical computing. It integrates
computation, visualization and programming in an easy to use environment where problems and
solutions are expressed in familiar mathematical notations.
The name MATLAB stands for MATRIX LABORATORY. Today, MATLAB engines
incorporate the LAPACK and BLAS Libraries, embedding the state of the art in software
for matrix computation.
USES:
Typical uses include,
Math and computation
Algorithm development
Data acquisition
Modeling, simulation and prototyping
Data analysis, exploration and visualization
Scientific and engineering graphics
Application development, including graphical user interface building.
GRAPHICS:
MATLAB has extensive facilities for displaying vectors and matrices as groups as well as
annotating and printing these graphs.
EXPRESSIONS :
The building blocks of expressions are
Variables
Numbers
Operators
Functions
VARIABLES :
MATLAB does not require any type of declarations or dimensions when it encounters a new
variable name. It automatically creates the variable and allocates appropriate memory.
Example : num_stud = 25
NUMBERS :
MATLAB uses conventional decimal notation, with an optional decimal point. It uses
‘E’ to
specify a power of ten. Imaginary no’s used either i or j as a suffix.
Example : 3, -99, 1i, 3e5i
OPERATORS :
+ : add
- : subtract
* : multiply
/ : division
\ : left division
^ : Power
’ : complex conjugate transpose
FUNCTIONS :
MATLAB provides a large no.of standard functions including abs, sqrt, exp and stn.
SYNTAX: abs : y = abs(x)
b = sqrt(x)
y = exp(x)
c = sin(A)
TOOL BOXES :
There are a no.of tool boxes available in MATLAB some of them are:
Communication toolbox
Control system toolbox
Data acquisition toolbox
Data base toolbox
Data Feed toolbox
Filter design toolbox
Fuzzy logic toolbox
Signal processing toolbox
Image processing toolbox
OPC tool box
Wavelet toolbox
RF toolbox
COMMUNICATION TOOLBOX:
The communication toolbox extends the MATLAB technical computing environment with
functions, plot as a graphical user interface. The toolbox helps you to create algorithms for
commercial and defense wireless s/m’s.
FUNCTIONS :
Signal Sources: Sources of random signalsPerformance evaluation : analysing and
visualizing performances of a communication s/m.
Source coding :quantization, companders and other kind of source coding.
Error control coding : Block and convolution coding.
Interleaving / De interleaving:Block and convolution interleaving.
Special filters: raised cosine and Hilbert fitters
GUI: Bit error rate analysis tool.
SIMULINK :
Simulink is a software package for modeling, simulating and analysing dynamic systems. It
supports linear and non-linear s/ms, modeled in continuous time, sampled time, or a hybrid of the
two systems may also have different parts that are sampled at different rates (multirated).
RESULT:
Thus the MATLAB and MATLAB tools were studied.
EX.NO:2 GENERATION OF FUNCTIONAL AND RANDOM SEQUENCES
AIM
To write a MATLAB program to generate the following sequences and plot them.
1. Unit impulse signal
2. Unit step signal
3. Unit ramp signal
4. Exponential signal
5. Sinusoidal signal
6. Cosine signal
7. Random signals
APPARATUS REQUIRED
SOFTWARE : MATLAB 7.10 (OR) High version
MATHEMATICAL EQUATION
δ (n) = 1 for n = 0
=0 for n ≠ 0
ALGORITHM
1. Start the program
2. Get the dimension of “n”
3. Discrete output is obtained for n = 0 and zeros for all other values.
4. Output is generated in plot and stem format
5. Terminate the process
PROGRAM
%program for generation of DT impulse Signal
n=-10:1:10;
u=[zeros(1,10),ones(1,1),zeros(1,10)];
subplot(2,1,2);
stem(n,u);
xlabel('time ->');
ylabel('Amplitude ->');
title(' DT Impulse Signal ');
OUTPUT
The unit step sequence is a signal that is zero everywhere except at n >= 0 where its value
is unity. In otherwise integral of the impulse function is also a singularity function and is called
the unit step function.
MATHEMATICAL EQUATION
PROGRAM
OUTPUT:
ALGORITHM
1. Start the program
2. Get the dimension of “n”
3. Discrete output is obtained for n>=0 and zeros for all other values
4. Output is generated in stem format
5. Terminate the process
PROGRAM
% Program For Generation Of DT Ramp Signal
n=input(' Enter the Length Of Sequence');
t=0:n-1;
subplot(2,1,2);
stem(t,t);
xlabel('time->');
ylabel('Amplitude->');
title('DT Ramp Signal');
OUTPUT
When the values of a>1, the sequence grows exponentially and when the value is 0<a<1,
the sequence decay exponentially.
MATHEMATICAL EQUATION
ALGORITHM
PROGRAM
%program for generation of DT exponential signal
n=input('enter the length of sequence =');
a=input('enter a value=');
x=0:n-1;
y=exp(a*x);
subplot(2,1,2);
stem(x,y);
xlabel('n->');
ylabel('amplitude->');
title('DT exponential signal');
OUTPUT
SINUSOIDAL SEQUENCE
The sine function output is calculate by the following equation
X(t) = A sin (2 * pi * f * t)
ALGORITHM
1. Initialize input Frequency and
2. Apply the values into a general formula.
3. Next , plot the output waveform into graph window, using stem function for discrete
output. To plot more than one figure in single graph window subplot function is used.
Syntax of subplot is
i. subplot(a, b, c)
Where, a = Row, b = Column, c = no of fig
4. Use the title function to give the name to the waveform.
5. Use xlabel and ylabel to find the unit for x and y axis.
PROGRAM
%Program For Generation Of DT Sine Signal
clc;
close all;
clear all;
n=input('Enter the Length of Sequence=');
t=0:0.1:n-1;
y=sin(2*pi*t);
subplot(2,1,2);
stem(t,y);
xlabel('n>');
ylabel('Amplitude->');
title('DT Sine Signal');
OUTPUT
COSINE SEQUENCE
X(t) = cos(2 * pi * f * t)
PROGRAM
OUTPUT
Enter the Length of Sequence=3
RANDOM SEQUENCE
The concept of a random sequence is essential in probability theory and statistics. The concept
generally relies on the notion of a sequence of random variables and many statistical discussions begin
with the words "let X1,...,Xn be independent random variables...". Yet as D. H. Lehmer stated in
1951: "A random sequence is a vague notion... in which each term is unpredictable to the
uninitiated and whose digits pass a certain number of tests traditional with statisticians"
ALGORITHM
1. Initialize range and number of random numbers
3. Plot the output waveform into graph window using stem function
5. Use x label & ylabel to find the unit for x & y axis.
PROGRAM
r= 29 36 40 40 22
RESULT
Thus the MATLAB programs for unit impulse, unit step, unit ramp, exponential signals,
sinusoidal signal , cosine signal and random sequence were generated and plotted in
discrete domain successfully.
Expt No:3 LINEAR AND CIRCULAR CONVOLUTION OF TWO SEQUENCES
Aim
To perform a Linear Convolution and Circular Convolution of two sequences Using
MATLAB.
Requirements
THEORY
Convolution is a powerful way of characterizing the input-output relationship of time –
invariant linear systems. Convolution finds its application in processing signals especially
analyzing the output of the system.
The response or output y(n) of a LTI system for any arbitrary input is given by
convolution of input and the impulse response h(n) of the system.
∞
y(n) = ∑ [x(k)h(n− k]
k=∞
……… (1)
If the input has ‘L’ samples and the impulse response h(n) has ‘M’ samples then the
output sequence y(n) will be a finite duration sequence consisting of L+ M-1 samples. The
convolution results in a non-periodic sequence. Hence this convolution is also called aperiodic
convolution. The convolution relation of equation (1) can also be expressed as
If the inputs have ‘L’ samples and ‘M’ samples then the output sequence y(n) will be a
finite duration sequence consisting of maximum(L,M) samples.
y1 = 1 4 8 14 15 10 8
PROGRAM FOR CIRCULAR CONVOLUTION
clc;
close all;
clear all;
%program to perform circular convolution
N1=length(g);
N2=length(h);
N=max(N1,N2);
y1=cconv(g,h,N);
display('Convolution output');
display(y1);
subplot(3,1,1);
t1=0:N1-1;
stem(t1,g);
xlabel('time->');
ylabel('amplitude->');
title('input signal g(n)');
subplot(3,1,2);
t2=0:N2-1;
stem(t2,h);
xlabel('time->');
ylabel('amplitude->');
subplot(3,1,3);
t3=0:N-1;
stem(t3,y1);
xlabel('time->');
ylabel('amplitude->');
y1 = 16 14 16 14
RESULT
Thus the Linear convolution and circular convolution were performed using
MATLAB.
Ex.No 4 Linear convolution using circular convolution
Aim:
To perform linear using circular convolution using Matlab
Requirements:
Matlab 2007 and above
Program:
clc;
clear all;
close all;
x=input ('Enter the sequence x(n)');
h=input ('Enter the sequence h(n)');
n1=length(x);
n2=length(h);
subplot(2,2,1);
t1=0:1:n1-1;
stem (t1,x);
ylabel('x(n)');
xlabel('n');
title('input sequence');
subplot (2,2,2);
t2=0:1:n2-1;
stem (t2,h);
xlabel('n');
ylabel('h(n)');
title('i/p sequence');
N=n1+n2-1;
x1=[x,zeros(1,N-n1)];
h1=[h,zeros(1,N-n2)];
y=cconv(x1,h1,N);
display(y);
n=0:1:N-1;
subplot (2,2,3);
stem(n,y);
xlabel('n');
ylabel ('y(n)');
title('o/p seq');
% verification
y1=conv(x,h);
display (y1);
subplot (2,2,4);
stem(n,y);
xlabel('n');
ylabel('y(n)');
title ('linear convolution output');
OUTPUT:
Enter the sequence x(n)[1 2 3 4]
Enter the sequence h(n)[1 2 1 2]
y = 1.0000 4.0000 8.0000 14.0000 15.0000 10.0000 8.0000
y1 = 1 4 8 14 15 10 8
Result:
Thus the linear convolution using circular convolution was performed using
Matlab.
Ex.No 5 CONVOLUTION USING DFT AND IDFT
AIM:
To perform convolution using DFT and IDFT using MATLAB
Requirements:
Mat lab 2009 later
Program:
clc;
close all;
clear all;
x=input('enter the input sequence');
h=input('enter the input sequence');
N1=length(x);
N2=length(h);
N=max(N1,N2);
n=0:1:N-1;
x1=[x,zeros(1,N-N1)];
h1=[h,zeros(1,N-N2)];
x2=fft(x1);
h2=fft(h1);
y=x2.*h2;
y1=ifft(y);
subplot(2,1,1);
stem(n,y1);
xlabel('time-');
ylabel('Amplitude--');
title('convolution by DFT&IDFT');
subplot(2,1,2);
z=cconv(x,h,N);
stem(n,z);
xlabel('time-');
ylabel('Amplitude----');
title('circular convolution');
OUTPUT
RESULT:
Thus linear and circular convolution was performed using DFT and IDFT.
Expt No:6 SPECTRUM ANALYSIS USING DFT
AIM
To write a program for calculating Fast Fourier Transform of given input signal using MATLAB
software package.
REQUIREMENTS
THEORY
The implementation of DFT through digital computers requires the memory to store x(n)
and values of coefficients WknN. The amount of accessing and storing of data in
computation is directly proportional to the number of arithmetic operations involved.
Therefore, for direct computation of N- point DFT the amount computation and
computation time is proportional to N2. From equation (1) observe that the direct
calculation of the DFT requires N2 complex multiplications and N (N-1) complex additions.
Direct computation of DFT is basically inefficient, primarily because it does not exploit
the symmetry and periodicity properties of the twiddle or phase factor WN.
As the value of N increases, the direct computation of DFT becomes a time taking and complex
process, which also leads to very high memory capacity requirements.
The computationally efficient algorithms, known collectively as Fast Fourier Transform
(FFT) algorithms exploit the symmetry and periodicity properties of the twiddle or phase factor
WN. In particular, these two properties are:
Wk+N/2 N = -WkN
Wk+NN = WkN
The FFT is a method for computing the DFT with reduced number of calculations. The
computational efficiency is achieved if we adopt a divide and conquer approach. This approach is
based on the decomposition of an N- point DFT into smaller DFTs.
In an N-point sequence, if N can be expressed as N= rm , then the sequence can be decimated into
r- point sequences. For each r- point sequence, r- point DFT can be computed. From the results of
r-point DFT, r2-point DFTs are computed. From the results of r2-point DFTs, the r3-point
DFTs are computed and so on, until we get rm-point DFT.In computing N-point DFT by this
method a number of stages of computation will be m times. The number is called Radix
of the FFT algorithm.
RADIX –2 FFT ALGORIHM
For performing radix-2 FFT, the value of N should be such that, N=2 m. Here the decimation can
be performed m times, where m=log N. In direct computation of N-point DFT, the total number
of complex additions are N (N-1) and the total number of complex multiplications is N2. In radix-
2 FFT, the total number of complex additions are reduced to N.log 2N and total number
of complex multiplications are reduced to (N/2). log 2N.
DECIMATION IN TIME ALGORITHM
The DIT –FFT algorithm decompose the DFT by sequentially splitting x(n) in time domain into
sets of smaller and smaller subsequences and then forms a weighted combination of the DFTs of
these sequences.
DECIMATION IN FREQUENCY ALGORITHM
The DIF –FFT algorithm decomposes the DFT by recursively splitting the sequence elements X
(k) in the frequency domain into sets of smaller and smaller subsequences.
CALCULATION OF MAGNITUDE AND PHASE RESPONSE
Magnitude response of X (k)can be obtained as,
ALGORITHM
1. Initialize the variable ‘Xn’. Then find the length of the input sequence (Xn) and store
the value into variable ‘N’. It is the FFT order (4, 8, 16, ….. point fft).
2. Find the FFT for the given input sequence and use the function “fft (Xn, N)”. N refers
the order of FFT.
3. The FFT output is in complex form, so the output contains Real and Imaginary values.
Use stem (real(x)) to plot Real values and stem(imag(x)) is used to plot the imaginary
values.
4. Then use the subplot and stem function to display the input and output in a
single graph window. Else use figure( ) function to display the input & output
in separate window.
5. The title function is used to give the name to the waveform.
6. Thexlabel&ylabel is used to find the unit for x & y axis.
PROGRAM
%Program to calculate DFT of a signal
clc;
close all;
clear all;
x=input('Enter the input sequence');
N=length(x);
y=fft(x,N);
display(y);
n=0:1:N-1;
k=0:1:N-1;
subplot(3,2,1);
stem(k,x);
xlabel('n');
ylabel('amplitude');
title('input');
subplot(3,2,2);
stem(k,real(y));
xlabel('k');
ylabel('amplitude');
title('real sequence');
subplot(3,2,4);
stem(k,imag(y));
xlabel('k');
ylabel('amplitude');
title('imag sequence');
x1=ifft(y,N);
subplot(3,2,3);
stem(n,x1);
xlabel('n');
ylabel('amplitude');
title('idft sequence');
subplot(3,2,6);
stem(k,angle(y));
xlabel('k');
ylabel('angle (x(k))');
title('phase response');
OUTPUT
Columns 6 through 8
RESULT
Thus the Discrete Fourier Transform of input signal was calculated and
Magnitude and Phase response are plotted.
Expt No:7 DESIGN OF DIGITAL FIR FILTER
Aim
To perform a FIR Low pass, high pass, band pass and band stop filters
Using MATLAB.
Requirements
Matlab 2007 & above
Theory
The FIR filter design functions design linear phase filters only. The filter
coefficients, or "taps," of such filters obey either an even or odd symmetry relation.
Depending on this symmetry, and on whether the order n of the filter is even or odd,
a linear phase filter has certain inherent restrictions on its frequency response
The phase delay and group delay of linear phase FIR filters are equal and constant
over the frequency band. This property preserves the wave shape of signals
in the passband; that is, there is no phase distortion.
Windowing Method
Consider the ideal, or "brick wall," digital filter with a cutoff frequencyof ω0 rad/s.
This filter has magnitude 1 at all frequencies in pass band, and magnitude 0
at frequencies in stop band.
This filter is not implementable since its impulse response is infinite and noncausal. To
create a finite-duration impulse response, truncate it by applying a window. By retaining
the central section of impulse response in this truncation, we obtain a linear phase
FIR filter. Ringing and ripples occur in the response, especially near the band edge.
This "Gibbs effect" does not vanish as the filter length increases, but
a nonrectangular window reduces its magnitude. Multiplication by a window in the
time domain causes a convolution or smoothing in the frequency domain.
Using a Hamming window greatly reduces the ringing. This improvement is at the
expense of transition width (the windowed version takes longer to ramp from
passband to stopband) and optimality (the windowed version does not minimize the
integrated squared error).
Advantage of FIR filters
The primary disadvantage of FIR filters is that they often require a much
higher filter order than IIR filters to achieve a given level of performance.
Correspondingly, the delay of these filters is often much greater than for an
equal performance IIR filter.
FIR LPF
clc;
clear all;
close all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
whn=hanning(N);
hn=hd.*whn';
fvtool(hn);
hold on
whm=hamming(N);
hold on
hn1=hd.*whm';
fvtool(hn1);
hold on
wbm=blackman(N);
hn2=hd.*wbm';
fvtool(hn2);
FIR LPF - OUTPUT
HANNING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR LPF - OUTPUT
HAMMING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR LPF - OUTPUT
BLACKMAN WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR HPF
clc;
clear all;
close all;
wc=0.5*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));
whn=hanning(N);
hn=hd.*whn';
fvtool(hn);
hold on
whm=hamming(N);
hold on
hn1=hd.*whm';
fvtool(hn1);
hold on
wbm=blackman(N);
hn2=hd.*wbm';
fvtool(hn2);
FIR HPF – OUTPUT
HANNING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR HPF – OUTPUT
HAMMING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR HPF – OUTPUT
BLACKMAN WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR BPF
clc;
clear all;
close all;
wc1=0.5*pi;
wc2=0.6*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(n-alpha+eps));
whn=hanning(N);
hn=hd.*whn';
fvtool(hn);
hold on
whm=hamming(N);
hold on
hn1=hd.*whm';
fvtool(hn1);
hold on
wbm=blackman(N);
hn2=hd.*wbm';
fvtool(hn2);
FIR BPF – OUTPUT
HANNING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR – BPF OUTPUT
HAMMING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR BPF- OUTPUT
BLACKMAN WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR BEF
clc;
clear all;
close all;
wc1=0.5*pi;
wc2=0.6*pi;
N=25;
alpha=(N-1)/2;
eps=0.001;
n=0:1:N-1;
hd=(sin(pi*(n-alpha+eps))- sin(wc2*(n-alpha+eps))+sin(wc1*(n-
alpha+eps)))./(pi*(n-alpha+eps));
whn=hanning(N);
hn=hd.*whn';
fvtool(hn); hold
on
whm=hamming(N);
hold on
hn1=hd.*whm';
fvtool(hn1);
hold on
wbm=blackman(N);
hn2=hd.*wbm';
fvtool(hn2);
FIR BEF- OUTPUT HAMMING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR – BEF OUTPUT
BLACKMAN WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
FIR – BEF OUTPUT
HANNING WINDOW
MAGNITUDE RESPONSE
PHASE RESPONSE
RESULT
Thus the FIR Low pass, high pass, band pass and band stop filters were performed
using MATLAB.
be
Ex.No 8 DESIGN OF DIGITAL IIR FILTER
Aim
To perform a IIR Low pass, high pass, band pass and band reject filters using
MATLAB.
Requirements
Theory
The Design method involves Butterworth, Chebyshev type I, Chebyshev type II,
and elliptic filter designs.
Butterworth
The magnitude response of a Butterworth filter is maximally flat in the passband
and monotonic overall.
Chebyshev type I
The magnitude response of a Chebyshev type I filter is equiripple in the
passband and monotonic in the stopband.
Chebyshev type II
The magnitude response of a Chebyshev type II filter is monotonic in the
passband
and equiripple in the stopband.
Elliptic
The magnitude response of an elliptic filter is equiripple in both the
passband and the stopband.
The primary advantage of IIR filters over FIR filters is that they typically
meet a given set of specifications with a much lower filter order than a
corresponding FIR
filter. Although IIR filters have nonlinear phase, data processing within
MATLAB software is commonly performed "offline," that is, the entire
data sequence is available prior to filtering. This allows for a noncausal,
zero-phase filtering approach (via the filtfilt function), which eliminates the
nonlinear phase distortion of an IIR filter.
Designing IIR Filters to Frequency Domain Specifications
Butterworth
[n,Wn] = buttord(Wp,Ws,Rp,Rs)
Chebyshev Type I
Chebyshev Type II
Elliptic
PROGRAM
LOW PASS FILTER-
BUTTERWORTH:
clc;
clear all;
close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=buttord(wp,ws,ap,as);
[b,a]=butter(n,wc);
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
Chebyshev 1
clc;
clear all;
close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=cheb1ord(wp,ws,ap,as);
[b,a]=cheby1(n,ap,wc); fvtool
(b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
cheby2;
clc;
clear all;
close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=cheb2ord(wp,ws,ap,as);
[b,a]=cheby2(n,ap,wc); fvtool
(b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
HPF:
BUTTER:
clc;
clear all; close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=buttord(wp,ws,ap,as);
[b,a]=butter(n,wc,'HIGH');
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
cheb1
clc;
clear all;
close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=cheb1ord(wp,ws,ap,as);
[b,a]=cheby1(n,ap,wc,'high');
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
IIR CHEBY1 HPF
FIG1
Magnitude Response (dB)
-10
Magni
tude(d
B)
-20
-30
-40
-50
-60
FIG 2:
Magnitude Response (dB)
6
2
dB
nit
ud
ag
M
e(
-2
-4
-6
-8
-10
-12
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
FIG 3
Magnitude Response (dB)
5
0
Magni
tude(d
B)
-5
-15
-10
-20
-25
Cheb2:
clc;
clear all;
close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=cheb2ord(wp,ws,ap,as);
[b,a]=cheby2(n,ap,wc,'high');
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
-2
nitud
e(dB
Mag
-4
-6
-8
-10
-12
2
Magnitude(
dB)
-1
-2
-3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
FIG 3
0
ude(dB
Magnit
-1
-2
-3
-4
-5
-1
-2
Ma
gni
tud
e(d
B)
-3
-4
-5
-6
-7
-8
FIG2
Magnitude Response (dB)
2
Magnitude(d
1
B)
-1
-2
-3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
FIG 3
Magnitude Response (dB)
3.5
2.5
2
Magnitu
de(dB)
1.5
0.5
-0.5
-1
-1.5
BPF CHEB1
FIG 1
Magnitude Response (dB)
-2
Magnitu
de(dB)
-4
-6
-8
-10
2
gnit
(dB
ude
Ma
-1
-2
-3
Fig 3
3
Magnitu
de(dB)
-1
-2
-5
ude(dB
Magnit
-10
-15
-20
-25
-30
FIG 2
2
gnit
(dB
ude
Ma
-1
-2
-3
3
Magnitu
de(dB)
-1
-2
clc;
clear all; close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=buttord(wp,ws,ap,as);
wc=[wp,ws];
[b,a]=butter(n,wc,'stop');
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
BUTTERWORTH
FIG 1
-10
-20
Magnitude(dB) -30
-40
-50
-5
-10
-15
Ma
gni
tud
e(d
B)
-20
-25
-30
-35
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
FIG 3
-5
-10
-15
Mag
de(d
nitu
B)
-20
-25
-30
-35
clc;
clear all; close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=cheb1ord(wp,ws,ap,as);
wc=[wp,ws];
[b,a]=cheby1(n,ap,wc,'stop');
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
CHEB1
Fig 1
-10
Magnitude
(dB)
-20
-30
-40
-50
-60
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Fig 2
-10
-15
Magnitude(
dB)
-20
-25
-30
-35
-10
-15
Magnitude(
dB)
-20
-25
-30
-35
clc;
clear all;
close all;
a=input('Enter a');
b=input('Enter b');
epslan=((1/(a.*a))-1);
lambda=((1/(b.*b))-1);
ap=10*log(1+epslan);
as=10*log(1+lambda);
wp=input('Enter pass Frequency');
ws=input('Enter stop Frequency');
[n,wc]=cheb2ord(wp,ws,ap,as);
wc=[wp,ws];
[b,a]=cheby2(n,ap,wc,'stop');
fvtool (b,a);
hold on;
f=1;
[bz,az]=bilinear(b,a,f);
fvtool(bz,az)
hold on;
[bz1,az1]=impinvar(b,a,f);
fvtool(bz1,az1);
hold off
Cheb2
Fig 1
-10
Magnitude
(dB)
-20
-30
-40
-50
-60
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
FIG 2
-10
-15
Magnitude(
dB)
-20
-25
-30
-35
FIG 3
-10
-15
-20
Magnitude(dB)
-25
-30
-35
Thus the IIR Low pass, high pass, band pass and band stop filters were
performed and displayed the graph in FVTOOL using MATLAB.
EX.NO:9: MULTIRATE FILTERS
Aim
To design decimation and interpolation using matlab
Requirements
Matlab 2007 and above
Theory
There are many instances where the rate at which a signal can be
processed by a particular component or module is different from the
speed at which data enters that module.
Example: DVD and CD Audio
CD audio is encoded at 44.1K samples per second. DVD audio, by
comparison, is encoded at 48K
samples per second. In order to convert music from one to the other, the
sample rate needs to be
altered.
Upsampling
the spectrum will fold and replicate at . This image can then be
filtered out using a low-pass filter.
Inserting more than one zero between sample points will cause the
spectrum to replicate and fold accordion-style. If N zeros are inserted,
N images will be created. Again, these images can be attenuated by
applying a low-pass filter.
Downsampling
clc;
clear all;
close all;
d=input('Enter the interpolation factor');
n=0:99;
x=sin(2*pi*0.01*n);
subplot(2,1,1);
stem(x);
xlabel('Time');
ylabel('Amplitude');
title('Input Signal');
y=interp(x,d);
m=0:((100*d)-1);
subplot(2,1,2);
stem(m,y);
xlabel('Time');
ylabel('Amplitude');
title('Interpolated Signal')
OUTPUT FOR INTERPOLATION:
RESULT
Thus program for decimation and interpolation is designed using matlab.
EX.NO:10 AUTOCORRELATION & CROSS CORRELATION
Aim
To perform autocorrelation and cross correlation of function and sequences
using matlab
Requirements
Matlab 2007 and above
clc;
clear all;
clc;
clear all;
close all;
x=0:.1:10;
s1=sin(x);
subplot(3,1,1);
stem(x,s1);
xlabel('n');
ylabel('x(n)');
title('input signal x(n)');
s2=cos(x);
subplot(3,1,2);
stem(x,s2);
xlabel('n');
ylabel('y(n)');
title('input signal y(n)');
c=xcorr(s1,s2);
c1=length(c);
y=0:c1-1;
display(c);
subplot(3,1,3);
stem(y,c);
ac=max(c);
display(ac);
xlabel('n');
ylabel('rxy(n)');
title('output signal');
clc;
clear all;
close all;
x=input('enter x');
n1=length(x);
t1=0:1:n1-1;
subplot(3,1,1);
stem(t1,x);
xlabel('n');
ylabel('x(n)');
title('input signal x(n)');
y=input('enter y');
n2=length(y);
t2=0:1:n2-1;
subplot(3,1,2);
stem(t2,y);
xlabel('n');
ylabel('y(n)');
title('input signal y(n)');
c=xcorr(x,y);
n3=length(c);
t3=0:1:n3-1;
subplot(3,1,3);
stem(t3,c);
display(c);
xlabel('n');
ylabel('rxy');
title('output signal');
ac=max(c);
display(ac);
enter x[1 2 3 4]
enter y[1 2 1 2]
c = 2.0000 5.0000 10.0000 16.0000 12.0000 11.0000 4.0000
ac = 16
RESULT
Thus autocorrelation and cross correlation of function and sequences are
performed using matlab
DSP PROCESSOR
BASED
IMPLEMENTATION
EX.NO: 11 STUDY OF ARCHITECTURE OF DIGITAL SIGNAL PROCESSORS
AIM:
To study about the architecture of digital signal processors.
THEORY
Figure 28-4a shows how this seemingly simple task is done in a traditional microprocessor. This
is often called a Von Neumann architecture, after the brilliant American mathematician
John Von Neumann (1903-1957). Von Neumann guided the mathematics of many
important discoveries of the early twentieth century. His many achievements include:
developing the concept of a stored program computer, formalizing the mathematics of
quantum mechanics, and work on the atomic bomb. If it was new and exciting, Von Neumann
was there!
As shown in (a), a Von Neumann architecture contains a single memory and a single bus
for transferring data into and out of the central processing unit (CPU). Multiplying two
numbers requires at least three clock cycles, one to transfer each of the three numbers over the bus
from the memory to the CPU. We don't count the time to transfer the result back to memory,
because we assume that it remains in the CPU for additional manipulation (such as the sum of
products in an FIR filter). The Von Neumann design is quite satisfactory when you are content to
execute all of the required tasks in serial. In fact, most computers today are of the Von
Neumann design. We only need other architectures when very fast processing is required, and
we are willing to pay the price of increased complexity.
This leads us to the Harvard architecture, shown in (b). This is named for the work
done at Harvard University in the 1940s under the leadership of Howard Aiken (1900-1973). As
shown in this illustration, Aiken insisted on separate memories for data and program
instructions, with separate buses for each. Since the buses operate independently, program
instructions and data can be fetched at the same time, improving the speed over the single
bus design. Most present day DSPs use this dual bus architecture.
Figure (c) illustrates the next level of sophistication, the Super Harvard Architecture. This term
was coined by Analog Devices to describe the internal operation of their ADSP-2106x and
new ADSP-211xx families of Digital Signal Processors. These are calledSHARC® DSPs, a
contraction of the longer term, Super Harvard ARChitecture. The idea is to build upon the
Harvard architecture by adding features to improve the throughput. While the SHARC DSPs are
optimized in dozens of ways, two areas are important enough to be included in Fig. 28-
4c: an instruction cache, and an I/O controller.
First, let's look at how the instruction cache improves the performance of the Harvard
architecture. A handicap of the basic Harvard design is that the data memory bus is
busier than the program memory bus. When two numbers are multiplied, two binary
values (the numbers) must be passed over the data memory bus, while only one binary value (the
program instruction) is passed over the program memory bus. To improve upon this
situation, we start by relocating part of the "data" to program memory. For instance, we
might place the filter coefficients in program memory, while keeping the input signal in
data memory. (This relocated data is called "secondary data" in the illustration). At first
glance, this doesn't seem to help the situation; now we must transfer one value over the
data memory bus (the input signal sample), but two values over the program memory bus
(the program instruction and the coefficient). In fact, if we were executing random
instructions, this situation would be no better at all.
However, DSP algorithms generally spend most of their execution time in loops, such as
instructions 6-12 of Table 28-1. This means that the same set of program instructions will
continually pass from program memory to the CPU. The Super Harvard architecture takes
advantage of this situation by including an instruction cache in the CPU. This is a small memory
that contains about 32 of the most recent program instructions. The first time through a loop, the
program instructions must be passed over the program memory bus. This results in slower
operation because of the conflict with the coefficients that must also be fetched along this
path. However, on additional executions of the loop, the program instructions can be
pulled from the instruction cache. This means that all of the memory to CPU information
transfers can be accomplished in a single cycle: the sample from the input signal comes over the
data memory bus, the coefficient comes over the program memory bus, and the program
instruction comes from the instruction cache. In the jargon of the field, this efficient transfer of
data is called a high memory-access bandwidth.
Figure 28-5 presents a more detailed view of the SHARC architecture, showing the I/O
controller connected to data memory. This is how the signals enter and exit the system.
For instance, the SHARC DSPs provides both serial and parallel communications ports.
These are extremely high speed connections. For example, at a 40 MHz clock speed, there
are two serial ports that operate at 40 Mbits/second each, while six parallel ports each
provide a 40 Mbytes/second data transfer. When all six parallel ports are used together, the data
transfer rate is an incredible 240 Mbytes/second.
This is fast enough to transfer the entire text of this book in only 2 milliseconds! Just as
important, dedicated hardware allows these data streams to be transferred directly into
memory (Direct Memory Access, or DMA), without having to pass through the CPU's
registers. In other words, tasks 1 & 14 on our list happen independently and simultaneously with
the other tasks; no cycles are stolen from the CPU. The main buses (program memory bus and
data memory bus) are also accessible from outside the chip, providing an additional
interface to off-chip memory and peripherals. This allows the SHARC DSPs to use a four
Gigaword (16 Gbyte) memory, accessible at 40 Mwords/second (160 Mbytes/second), for 32 bit
data. Wow!
This type of high speed I/O is a key characteristic of DSPs. The overriding goal is to
move the data in, perform the math, and move the data out before the next sample is available.
Everything else is secondary. Some DSPs have on-board analog-to-digital and digital-to-analog
converters, a feature called mixed signal. However, all DSPs can interface with external
converters through serial or parallel ports.
Now let's look inside the CPU. At the top of the diagram are two blocks labeled Data
Address Generator (DAG), one for each of the two memories. These control the
addresses sent to the program and data memories, specifying where the information is to be read
from or written to. In simpler microprocessors this task is handled as an inherent part of the
program sequencer, and is quite transparent to the programmer. However, DSPs are designed
to operate with circular buffers, and benefit from the extra hardware to manage them
efficiently. This avoids needing to use precious CPU clock cycles to keep track of how
the data are stored. For instance, in the SHARC DSPs, each of the two DAGs can
control eight circular buffers. This means that each DAG holds 32 variables (4 per buffer), plus
the required logic.
The data register section of the CPU is used in the same way as in traditional microprocessors. In
the ADSP-2106x SHARC DSPs, there are 16 general purpose registers of 40 bits each. These can
hold intermediate calculations, prepare data for the math processor, serve as a buffer for
data transfer, hold flags for program control, and so on. If needed, these registers can also be used
to control loops and counters; however, the SHARC DSPs have extra hardware registers to carry
out many of these functions.
The math processing is broken into three sections, a multiplier, an arithmetic logic unit (ALU),
and a barrel shifter. The multiplier takes the values from two registers, multiplies them,
and places the result into another register. The ALU performs addition, subtraction,
absolute value, logical operations (AND, OR, XOR, NOT), conversion between fixed and
floating point formats, and similar functions. Elementary binary operations are carried out
by the barrel shifter, such as shifting, rotating, extracting and depositing segments, and so
on. A powerful feature of the SHARC family is that the multiplier and the ALU can be
accessed in parallel. In a single clock cycle, data from registers 0-7 can be passed to the
multiplier, data from registers 8-15 can be passed to the ALU, and the two results returned to
any of the 16 registers.
There are also many important features of the SHARC family architecture that aren't
shown in this simplified illustration. For instance, an 80 bit accumulator is built into the
multiplier to reduce the round-off error associated with multiple fixed-point math operations.
Another interesting
feature is the use of shadow registers for all the CPU's key registers. These are duplicate registers
that can be switched with their counterparts in a single clock cycle. They are used for fast context
switching, the ability to handle interrupts quickly. When an interrupt occurs in traditional
microprocessors, all the internal data must be saved before the interrupt can be handled.
This usually involves pushing all of the occupied registers onto the stack, one at a time. In
comparison, an interrupt in the SHARC family is handled by moving the internal data into
the shadow registers in a single clock cycle. When the interrupt routine is completed, the
registers are just as quickly restored. This feature allows step 4 on our list (managing the
sample-ready interrupt) to be handled very quickly and efficiently.
Now we come to the critical performance of the architecture, how many of the operations within the
loop (steps 6-12 of Table 28-1) can be carried out at the same time. Because of its highly
parallel nature, the SHARC DSP can simultaneously carry out all of these tasks. Specifically,
within a single clock cycle, it can perform a multiply (step 11), an addition (step 12), two
data moves (steps 7 and 9), update two circular buffer pointers (steps 8 and 10), and control the loop
(step 6). There will be extra clock cycles associated with beginning and ending the loop (steps 3,
4, 5 and 13, plus moving initial values into place); however, these tasks are also handled
very efficiently. If the loop is executed more than a few times, this overhead will be negligible. As
an example, suppose you write an efficient FIR filter program using 100 coefficients. You
can expect it to require about 105 to 110 clock cycles per sample to execute (i.e., 100 coefficient
loops plus overhead). This is very impressive; a traditional microprocessor requires many
thousands of clock cycles for this algorithm.
RESULT
Thus the architectures of digital signal processors are studied.
EX.NO:12 STUDY OF ADDRESSING MODES USING
TMS320C50 KIT
AIM:
To study about direct, indirect and immediate addressing modes in
TMS320C50 debugger.
APPARATUS REQUIRED:
1. Computer with TMS 320C50 debugger software
2. TMS 320C50 Kit.
3. RS232 cable.
PROGRAM LOGIC:
IMMEDIATE ADDRESSING MODE:
1. Initialize data pointer with 100H data.
2. Load the accumulator with first data.
3. Add the second data with accumulator content.
DIRECT ADDRESSING MODE:
1. Initialize data pointer with 100H data.
2. Load the accumulator with first data, whose address is specified in the
Instruction.
3. Add the accumulator content with second data, whose address is
specified in the instruction.
4. Store the accumulator content in specified address location.
IN-DIRECT ADDRESSING MODE: 1. Load the
auxiliary register with address location of first data.
2. The auxiliary register (AR0) is modified indirectly
as # symbol. 3. Load the second data into
accumulator and perform addition operation. 4. Store
the result.
PROGRAM:
(A) ADDITION
.MMREGS
.TEXT
start:
LDP #100H
LACC #000FH,0 ; first i/p - 000fh
SACL 0000,0
LT 0000
add #0005H ; second i/p - 0005h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;i/p are given in the program
;o/p will display in communication window at
;the address
8002 - 0048 ;
8002 - 0000
(B) SUBTRACTION
.MMREGS
.TEXT start:
LDP #100H
LACC #000FH,0 ; first i/p - 000fh
SACL 0000,0
LT 0000
sub #0005H ; second i/p - 0005h
SACL 0002 ; lower bit o/p
SACH 0003 ;higher bit o/p
hlt:
b hlt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;i/p are given in the program
;o/p will display in communication window at
;the address 8002 - 000A
; 8002 - 0000
( C) MULTIPLICATION
.MMREGS
.TEXT
start:
LDP #100H
LACC #0005H,0 ; first i/p
SACL 0000,0
LACC #0005H,0 ;second i/p
SACL 0001,0
LT 0000 ;T=0005
mpy 0001 ;P=0005*0005=0000 0019
PAC ;ACC=0000 0019
SACL 0002,0
SACH 0003,0
hlt:
b hlt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;o/p will display in 8002 - 0019 , 8003 - 0000.
start:
ldp #100h
nop
nop
lacc 0h ; first i/p at address 8000
sacl 3h ;
hlt:
b hlt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 8000 - 0002 - i/p ; 8001 -
0003 - i/p ; 8002 - 0005 - o/p ;
8003 – 0000
(B) SUBTRACTION
.MMREGS
.TEXT
start:
ldp #100h
nop
nop
lacc 0h ; first i/p at address 8000
sacl 3h ;
hlt:
b hlt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
( C) MULTIPLICATION
.MMREGS
.TEXT
start:
ldp #100h
nop
nop
lt 0h ; first i/p
mpy 1h ; second i/p
pac
hlt:
b hlt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RESULT:
Thus, the arithmetic operations using direct and indirect addressing modes in TMS320 kit was
performed successfully.
EX.NO: 13 LINEAR CONVOLUTION
AIM:
To write a program to find the linear convolution of two sequences Using TMS320C50 debugger.
APPARATUS REQUIRED:
1. System with TMS 320C50 debugger software
2. TMS 320C50 Kit.
3. RS232 cable
PROGRAM LOGIC:
RESULT:
Thus the linear convolution of two sequences is done successfully by using TMS320C50.
EX.NO: 14 CIRCULAR CONVOLUTION
AIM:
To write a program to find the Convolution of two sequences Using TMS320C50 debugger.
APPARATUS REQUIRED:
1. System with TMS 320C50 debugger software
2. TMS 320C50 Kit.
3. RS232 cable
PROGRAM LOGIC:
STM #06H,AR4
NEXT MAR *AR0+
LDM AR0,A
STLM A,AR3
LD #0H,A
STM #0A024H,AR1
STM #03H,BRC
RPTB LOOP
LD *AR1-,T
LOOP MAC *AR3+,A
STL A,*AR2+
BANZ NEXT,*AR4-
H BH
RESULT:
Thus the circular convolution of two sequences is done successfully by using TMS320C50.
EX NO: 15 WAVEFORM GENERATION
AIM:
To write a program to generate Sine Wave using TMS320C50 debugger.
APPARATUS REQUIRED:
1. System with VI debugger software
2. TMS 320C50 Kit.
3. CR0
4. RS 232 cable
PROGARAM
;****************************************************************************
TEMP .SET 0
;
.mmregs .text
START:
LDP #100H
splk #0,TEMP
CONT1:
lar AR2,#FREQ
CONT:
out TEMP,4
LACC TEMP
ADD #AMPLITUDE
SACL TEMP
MAR *,AR2
BANZ CONT,*-
LAR AR2,#FREQ
CONTx:
OUT TEMP,4
LACC TEMP
SUB #AMPLITUDE
SACL TEMP
MAR *,AR2
BANZ CONTx
B CONT1
.end
;****************************************************************************
;SAWTOOTH WAVEFORM GENERRATION
;****************************************************************************
.MMREGS
.TEXT
START:
LDP #120H
LACC #0H ;change lower amplitude
SACL 0
LOOP: LACC 0
OUT 0,04H
ADD #05h ;change frequency
SACL 0
SUB #0FFFh ;change upper amplitude
BCND LOOP,LEQ
B START
.END
;****************************************************************************;
;****************************************************************************
;square waveform generation.
;****************************************************************************
Sine Wave Generation. With these default values sine generated is 100 Hz. INCFREQ
.set 10 ;minimum value 1 - change for increasing frequency
;every count will increase frequency in steps of 100hz
DECFREQ .set 0 ;minimu value 0 - change for decreasing frequency
;every count will decrease frequency by half
LENGTH .set 360
AMPLITUDE .set 5
delay .set 7 ;change to increase/decrease frequency in
;different steps;
TEMP .set 0
TEMP1 .set 1
.mmregs
.text START:
LDP #100H
SPLK #TABLE,TEMP ;load start address of table
lar AR2,#( (LENGTH/INCFREQ)+(LENGTH*DECFREQ) )-1
lar ar3,#DECFREQ ;repeat counter for reducing frequency
CONT:
CALL DELAY
LACC TEMP ;load address of sine value
TBLR TEMP1 ;read sine data to TEMP1
LT TEMP1
MPY #AMPLITUDE
PAC
SACL TEMP1
mar *,ar3
banz repeat,*-
lar ar3,#DECFREQ ;repeat counter for reducing frequency
LACC TEMP
ADD #INCFREQ ;increase table value
repeat:
SACL TEMP ;store it
OUT TEMP1,4 ;send sine data to DAC
MAR *,AR2
BANZ CONT,*-
b START
DELAY:
lar ar7,#delay
mar *,ar7 back:
banz back,*-
ret
;
TABLE
.word 100
.word 101
.word 103
.word 105
.word 106
.word 108
.word 110
.word 112
.word 113
.word 115
.word 117
.word 119
.word 120
.word 122
.word 124
.word 125
.word 127
.word 129
.word 130
.word 132
.word 134
.word 135
.word 137
.word 139
.word 140
.word 142
.word 143
.word 145
.word 146
.word 148
.word 150
.word 151
.word 152
.word 154
.word 155
.word 157
.word 158
.word 160
.word 161
.word 162
.word 164
.word 165
.word 166
.word 168
.word 169
.word 170
.word 171
.word 173
.word 174
.word 175
.word 176
.word 177
.word 178
.word 179
.word 180
.word 181
.word 182
.word 183
.word 184
.word 185
.word 186
.word 187
.word 188
.word 189
.word 189
.word 190
.word 191
.word 192
.word 192
.word 193
.word 193
.word 194
.word 195
.word 195
.word 196
.word 196
.word 197
.word 197
.word 197
.word 198
.word 198
.word 198
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 200
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 199
.word 198
.word 198
.word 198
.word 197
.word 197
.word 197
.word 196
.word 196
.word 195
.word 195
.word 194
.word 193
.word 193
.word 192
.word 192
.word 191
.word 190
.word 189
.word 189
.word 188
.word 187
.word 186
.word 185
.word 184
.word 183
.word 182
.word 181
.word 180
.word 179
.word 178
.word 177
.word 176
.word 175
.word 174
.word 173
.word 171
.word 170
.word 169
.word 168
.word 166
.word 165
.word 164
.word 162
.word 161
.word 160
.word 158
.word 157
.word 155
.word 154
.word 152
.word 151
.word 149
.word 148
.word 146
.word 145
.word 143
.word 142
.word 140
.word 139
.word 137
.word 135
.word 134
.word 132
.word 130
.word 129
.word 127
.word 125
.word 124
.word 122
.word 120
.word 119
.word 117
.word 115
.word 113
.word 112
.word 110
.word 108
.word 106
.word 105
.word 103
.word 101
.word 99
.word 98
.word 96
.word 94
.word 93
.word 91
.word 89
.word 87
.word 86
.word 84
.word 82
.word 80
.word 79
.word 77
.word 75
.word 74
.word 72
.word 70
.word 69
.word 67
.word 65
.word 64
.word 62
.word 60
.word 59
.word 57
.word 56
.word 54
.word 53
.word 51
.word 49
.word 48
.word 47
.word 45
.word 44
.word 42
.word 41
.word 39
.word 38
.word 37
.word 35
.word 34
.word 33
.word 31
.word 30
.word 29
.word 28
.word 26
.word 25
.word 24
.word 23
.word 22
.word 21
.word 20
.word 19
.word 18
.word 17
.word 16
.word 15
.word 14
.word 13
.word 12
.word 11
.word 10
.word 10
.word 9
.word 8
.word 7
.word 7
.word 6
.word 6
.word 5
.word 4
.word 4
.word 3
.word 3
.word 2
.word 2
.word 2
.word 1
.word 1
.word 1
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 1
.word 1
.word 1
.word 2
.word 2
.word 2
.word 3
.word 3
.word 4
.word 4
.word 5
.word 6
.word 6
.word 7
.word 7
.word 8
.word 9
.word 10
.word 10
.word 11
.word 12
.word 13
.word 14
.word 15
.word 16
.word 17
.word 18
.word 19
.word 20
.word 21
.word 22
.word 23
.word 24
.word 25
.word 26
.word 28
.word 29
.word 30
.word 31
.word 33
.word 34
.word 35
.word 37
.word 38
.word 39
.word 41
.word 42
.word 44
.word 45
.word 47
.word 48
.word 50
.word 51
.word 53
.word 54
.word 56
.word 57
.word 59
.word 60
.word 62
.word 64
.word 65
.word 67
.word 69
.word 70
.word 72
.word 74
.word 75
.word 77
.word 79
.word 80
.word 82
.word 84
.word 86
.word 87
.word 89
.word 91
.word 93
.word 94
.word 96
.word 98
.word 100
.end
PROGRAM:
OUTPUT:
WAVEFORM AMPLITUDE (V) TIME PERIOD(ms)
Square
Sawtooth
Triangle
Sine
RESULT:
Thus the waveforms were generated and executed using TMS320C5X.
Ex.No 16 SAMPLING OF INPUT SIGNAL AND DISPLAY USING TMS320C5X
AIM:
To write a program to convert analog signals into digital signals using TMS320C50 debugger.
APPARATUS REQUIRED:
1. System with VI debugger software
2. TMS 320C50 Kit.
3. CR0
4. Function Generator.
PROGRAM LOGIC:
1. Initialize data pointer with 100H data
2. Give the analog signal as input
3. Introduce the time delay as per required.
4. Observe the discrete signal as output
PROGRAM:
.MMREGS
.TEXT
OUTPUT:
WAVEFORM AMPLITUDE (V) TIME PERIOD(ms)
INPUT
OUTPUT
RESULT:
Thus the sampling process is verified and executed using TMS320C5X.
CONTENT BEYOND
THE SYLLABUS
1.SAMPLING AND EFFECT OF ALIASING
AIM
To perform sampling operation and view the aliasing effect.
THEORY
A key step in any digital processing of real world analog signals is converting the analog signals
into digital form. We sample continuous data and create a discrete signal. Unfortunately,
sampling can introduce aliasing, a nonlinear process which shifts frequencies. Aliasing is
an inevitable result of both sampling and sample rate conversion.
The Nyquist sampling theorem defines the minimum sampling frequency to completely represent a
continuous signal with a discrete one. If the sampling frequency is at least twice the highest
frequency in the continuous baseband signal, the samples can be used to exactly reconstruct
the continuous signal. A sine wave can be described by at least two samples per cycle
(consider drawing two dots on a picture of a single cycle, then try and draw a single cycle
of a different frequency that passes through the same two dots). Sampling at slightly less than two
samples per cycle, however, is indistinguishable from sampling a sine wave close to but below
the original frequency. This is aliasing - the transformation of high frequency information into
false low frequencies that were not present in the original signal. The Nyquist frequency, also
called the folding frequency, is equal to half the sampling frequency f, and is the demarcation
between frequencies that are correctly sampled and those that will cause aliases. Aliases will
be 'folded' from the Nyquist frequency back into the useful frequency range.
Requirements
ALGORITHM
1. Initialize input Frequency, sampling frequency and number of sample values
(Nsamp). Sampling frequency must be twice the input frequency.
2. Then two different sinusoidal signals are sampled at the same sampling frequency. 3.
Sample the second signal at low sampling frequency. According to sampling
theorem the sampling frequency value is twice the input frequency. So aliasing will
occur in second signal.
4. Due to aliasing effect two signals are plotted in same wave.
5. The difference between these two sine wave signals is Aliasing Effect.
6. Next plot the output waveform into graph window, use the plot function which uses
the continuous function for analog output and use the stem function for
discrete output. To plot more than one figure in single graph window subplot
function is used. Syntax of subplot is
ii. subplot(a, b, c) Where, a = Row, b =
Column, c = no of fig
Result
Thus the Sampling was performed and studied the aliasing effect using MATLAB.
2.DECIMATION BY POLYPHASE DECOMPOSITION
AIM
To perform Decimation by polyphase decomposition of the given input signal using MATLAB
software package.
Requirements
THEORY
Downsampling
The process of reducing the sampling rate of a signal is called decimation (Sampling rate
compression). Decimation is also known as down sampling.
The decimated signal is given by
y (n)= x(Mn) , where M be the integer sampling rate reduction factor.
The general representation of decimation process can be
x (n) w(n) y(n)
h (n) M
F F F F1=F/M
Decimator
ALGORITHM
1. Start the program.
2. Initialize the Decimation factor value (M).
3. Use thefirdecim function to decimate the input signal using fir filter.
4. Use the sampling frequency and input frequency to generate the input signal.
5. Then apply the input signal &firdecim output to filter. This is to reduce the sampling
rate depends on decimation factor value.
Finally display the input and output signal
Program
clc;
clear all;
close all;
m=2; %decimation factor
hm=mfilt.firtdecim(m);
%use this default filter coefficient
%original sample frequency 4401 KHz
fs=44.1e3;
%10240 samples,0.232 second long signal
n=0:10239;
%original signal sinusoidal at 1 KHz
x=sin (2*pi*1e3/fs*n);
%5120 samples ,0.232 seconds
y=filter(hm,x);
%plot original sampled at 44.1KHz
stem (n(1:44)/fs,x(1:44))
hold on;
stem (n(1:22)/(fs/m),y(13:34),'r','filled');
xlabel('Time (sec)');
ylabel('signal value')
output
1
0.8
0.6
0.4
0.2
signalvalue
-0.2
-0.4
-0.6
-0.8
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (sec) -3
x 10
Result
Thus the Decimation was performed and displayed the graph using MATLAB.
VIVA QUESTIONS
9. Determine the convolution sum of two sequences x (n) = {3, 2, 1, 2} and h (n) = {1, 2, 1, 2}
y(n) = {3,8,8,12,9,4,4} 5. Find the convolution of the signals x(n) = 1 n=-2,0,1 = 2 n=-1 = 0
elsewhere. y(n) = {1,1,0,1,-2,0,-1}
10. State sampling theorem If the highest frequency contained in and analog signal Xa(t) is
Fmax = B and the signals is sampled at a rate of Fs> 2 Fmax = 2B, then Xa(t) can be exactly
recovered from its sample values without any aliasing.
13. What is meant by aliasing? How can be avoided? If the signal x(t) is sampled withg a
sampling frequency F<2 fm, then the periodic continuation of frequency response results in
spectral overlap. Here, the spectrum cannot be recovered by using a low pass filter. This effect is
known as alaising effect. To avoid aliasing, an analog low pass filter called anti-alaising filter is
used before sampler to reshape the frequency spectrum of the signal.
14. Differentiate DTFT and DFT DTFT output is continuous in time where as DFT output is
Discrete in time.
15. Differentiate between DIT and DIF program logic DIT – Time is decimated and input is bi
reversed format output in natural order DIF – Frequency is decimated and input is natural order
output is bit reversed format.
16. How many multiplication terms are required for doing DFT by expressional method and FFT
METHOD? 4. Expression –n2 FFT N /2 log N
17. What is the need for FFT? The direct evaluation of DFT using formula requires N2 complex
multiplications and N(N-1) complex additions. For large values of N, the direct evaluation of
DFT requires a large amount of computation. By using FFT program logics, the number of
computations can be reduced.
18. What are the advantages of FFT over DFT
FFT program logics reduces the computation time required to compute DFT
FFT program logics are computationally efficient
FFT program logic exploit the periodically and symmetry properties of DFT
FFT results in fast computation and save memory requirement
22. What is radix-2 FFT? The FFT program logic is most efficient in calculating N-point DFT. If
the number of output points N can be expressed as a power of 2, ie., N= 2m ,where m is an
integer then the program logic is known as radix-2 program logic
23. What is meant by bit reversal in FFT program logics? In DIT program logic, the output
sequence is a natural order but the input sequence has to be stored in bit reversed or shuffled
order. For an 8-point DIT program logic, the input sequence is
x(0),x(2),x(4),x(6),x(1),x(3),x(5),x(7). When N is power of 2 , the input sequence must be in bit
reversal order for the output to be computed in natural order.
24. Calculate the number of complex multiplications and additions needed in the calculation of a
N-point radix-2 FFT when compared to direct DFT In direct computation of DFT the number of
complex multiplications required is N2 and the number of complex additions required is N(N-10
In FFT program logic the number of complex multiplications required is N / 2 log N and the
number of complex additions required N log N So the FFT is computationally efficient than DFT
25. What is IIR system? If the unit sample response of a linear shift invariant system is of infinite
duration or infinite length, the system is said to be an infinite impulse response system
26. Specify the various structures of an IIR system Direct form I realization Direct form II
realization Cascade realization Parallel realization 3. Mention the various techniques that are
used in the conversion of continuous time analog filter into digital filter Impulse invariant
technique Bilinear transformation Approximation of derivatives 4. What are the disadvantages
of Impulse invariance method? This method is unsuccessful for implementing digital filters for
which | H(jw)| does not approaches zero for large values of w. hence it is not applicable for high
pass, band pass filter designs. 5. Define recursive realization For recursive realization the present
output y(n) is a function of past outputs, past are present input.
29. What are the steps involved in FIR filter design Choose the desired frequency response
Hd(W)
Take the inverse fourier transform and obtain Hd(n)
Convert the infinite duration sequence Hd(n) to h(n)
Take Z transform of h(n) to get H(Z)
30.What are the common methods used in the construction of FIR filters? Windowing method
Frequency sampling techniques Symmetric and anti-symmetric linear phase FIR filters