DSPLAB
DSPLAB
LIST OF EXPERIMENTS
VHDL EXPERMENTS:
AIM:
Write a MATLAB program for the generation of unit impulse, unit step,
ramp, exponential and Sinusoidal sequences.
PROGRAM:
%program for the generation of unit impulse sequence [δ (n)]
RESULT:
Given sequences are generated and plotted using MATLAB.
VIVA QUESTIONS:
1. What is the use of stem command?
2. What is the use of xlabel command?
3. What is the use of ylabel command?
4. What is the use of subplot command?
5. What is the use of title command?
AIM:
Write a MATLAB program to find the linear convolution of two
sequences x (n) and h (n)
PROGRAM:
%program for the generation of first sequence [x (n)]
N=input ('enter length of the first sequence :');
n=-N: 1: N;
x=input ('enter the first sequence :');
subplot (3,1,1);
stem (n,x);
xlabel('time index');
ylabel('x(n)');
title ('1stinputsequence');
RESULT:
Linear convolution of two sequences x (n) and h (n) are determined using MATLAB.
DISCRETE-TIME SYSTEMS
AIM:
Write MATLAB program to plot the frequency response of systems.
PROGRAM:
1. To plot the frequency response of the first order system
y (n)-0.8y (n-1) =x (n)
Clear all;
b= [1];
a= [1, -0.8];
w = - (2*pi): 0.001 :( 2*pi);
[h]=freqz (b, a, w);
subplot (2,1,1);
plot (w/pi,abs(h));
title ('frequency response in pi');
xlabel('normalised frequency');
ylabel('magnitude response');
subplot (2,1,2);
plot (w/pi,angle(h));
xlabel ('normalised frequency');
ylabel ('phase response');
RESULT:
Frequency response of discrete time systems are determined and plotted
using MATLAB.
VIVA QUESTIONS:
1. What is the use of ‘clear all’ command?
2. What is the use of ‘freqz’ function?
3. What is the use of ‘abs’ function?
4. What is the use of ‘angle’ function?
5. What is the use of ‘grid’ command?
PROGRAM:
n=-10:10;
x= (-0.9). ^n;
k=-200:200;
w= (pi/100)*k;
x=x*(exp (-j*(pi/100)*(n'*k)));
magx =abs(x);
angx =angle(x);
subplot (2,1,1);
plot (w/pi,magx);grid;
xlabel ('frequency in pi');
ylabel('modx');
title ('magnitude part');
subplot (2,1,2);
plot (w/pi,angx/pi);grid;
xlabel ('frequency in pi');
ylabel ('phase part');
RESULT:
DTFT of the given sequence is determined and plotted using MATLAB.
VIVA QUESTIONS:
1. What is the use of ‘freqspace’ function?
2. What is the use of ‘impz’ function?
3. What is the use of ‘phasez’ function?
4. What is the use of ‘stepz’ function?
5. What is the use of ‘phasedelay’function?
AIM:
Write a MATLAB program to compute the DFT of the given sequence
and plot the magnitude and phase response.
PROGRAM:
%DFT using FFT
Clear all;
N=input ('enter length of FFT :');
k=0: N-1;
x=input ('enter length of sequence :');
XK=fft(x, N);
magxk=abs(XK);
angxk=angle(XK);
subplot (2,1,1);
stem (k,magxk);
xlabel ('k');
ylabel ('real part of XK');
title ('magnitude part');
subplot (2,1,2);
stem (k,angxk);
xlabel ('k');
ylabel ('imaginary part of XK');
title ('phase part');
RESULT:
DFT of the given sequence is determined and plotted using MATLAB.
AIM:
Write a MATLAB program to design a Butterworth low pass digital filter
for the given specifications
%To design a Butterworth low pass filter for the given specifications
clear all;
alphap=4; % Pass band attenuation in dB
alphas=30; % Stop band attenuation in dB
fp=400; % pass band frequency in Hz
fs=800; % stop band frequency in Hz
F=2000; % Sampling frequency in Hz
omp=2*fp/F; oms=2*fs/F;
%To find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas)
% system function of the filter
[b,a]=butter (n, wn)
w=0:.01:pi;
[h,om]=freqz (b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);plot(om/pi,m);grid;
ylabel('Gain in dB');
xlabel('Normalised frequency');
title('magnitude response');
subplot(2,1,2);plot (om/pi,an);grid
ylabel('Phase in radians');
xlabel('Normalised frequency');
title('phase response');
VIVA QUESTION:
1. What is the use of ‘buttord’ function?
2. What is the use of ‘butter’ function?
3. What is the use of ‘freqz’ function?
4. What is the use of ‘residuez’ function?
5. What is the use of ‘ zplane’ function?
AIM:
Write a MATLAB program to design a Butterworth High pass digital
filter
for the given specifications
%To design a Butterworth high pass filter for the given specifications
clear all;
alphap=4; %Pass band attenuation in dB
alphas=30; %Stop band attenuation in dB
fs=400; %pass band frequency in Hz
fp=800; %stop band frequency in Hz
F=2000; %Sampling frequency in Hz
omp=2*fp/F; oms=2*fs/F;
%To find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas)
% system function of the filter
[b,a]=butter(n,wn,'high')
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);plot(om/pi,m);grid;
ylabel('Gain in dB');
xlabel('Normalised frequency');
subplot(2,1,2);plot(om/pi,an);grid;
ylabel('Phase in radians');
xlabel('Normalised frequency');
VIVA QUESTIONS:
AIM:
Write a MATLAB program to design a Butterworth Band pass digital
filter for the given specifications
RESULT:
Butterworth Band pass digital filter is designed with the given
specifications using MATLAB.
AIM:
Write a MATLAB program to design a Chebyshev low pass digital filter
for the given specifications
%To design a chebyshev type I lowpass filter for the given specifications
clear all;
alphap=1; %Passband attenuation in dB
alphas=15; %Stopband attenuation in dB
wp=.2*pi; %passband frequency in radians
ws=.3*pi; %stopband frequency in radians
%To find cutoff freency and order of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas)
% system function of the filter
[b,a]=cheby1(n,alphap,wn)
w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('Normalised frequency');
subplot(2,1,2);plot(ph/pi,an);grid
ylabel('Phase in radians');xlabel('Normalised freuency');
RESULT:
chebyshev low pass digital filter is designed with the given specifications
using MATLAB.
AIM:
Write a MATLAB program to design a Chebyshev Band pass digital
filter for the given specifications
%To design a chebyshev type I band pass filter for the given
specifications
clear all;
alphap=2; %Passband attenuation in dB
alphas=20; %Stopband attenuation in dB
wp=[.2*pi,.4*pi]; %passband frequency in radians
ws=[.1*pi,.5*pi]; %stopband frequency in radians
%To find cutoff freency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas)
% system function of the filter
[b,a]=cheby1(n,alphap,wn)
w=0:.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);plot(ph/pi,m);grid;
ylabel('Gain in dB');xlabel('Normalised frequency');
subplot(2,1,2);plot(ph/pi,an);grid;
ylabel('Phase in radians');xlabel('Normalised freuency');
RESULT:
chebyshev band pass digital filter is designed with the given
specifications using MATLAB.
AIM:
Write a MATLAB program to design a Low pass FIR filter using
Rectangular and Hamming windows.
%To design a 25-tap lowpass filter with cutoff frequency of 0.5pi radians using
% rectangular and Hamming windows and plot their frequency response
clear all;
wc=.5*pi;
N=25;alpha=(N-1)/2;eps=.001;
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);%Rectangular window sequence
hn=hd.*wr';%Filter coeffcients
w=0:.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wh=hamming(N);%Hamming window sequence
hn=hd.*wh';%filter coefficients
w=0:.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');grid;
xlabel('normalised frequency\omega/\pi');
ylabel('Magnitude');hold off
RESULT:
Low pass FIR filter is designed using Rectangular and Hamming
windows in MATLAB.
AIM:
Write a MATLAB program to design a Band pass FIR filter using
Rectangular and Hamming windows.
RESULT:
Band pass FIR filter is designed using Rectangular and Hamming
windows in MATLAB.
AIM:
Write VHDL source code to simulate DECODER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity decoder4 is
Port ( a : in std_logic_vector(1 downto 0);
d : out std_logic_vector(3 downto 0));
end decoder4;
begin
process (a)
begin
case a is
when "00" =>
d<="0001";
when "01" =>
d<="0010";
when "10" =>
d<="0100";
when "11" =>
d<="1000";
when others =>
d<="ZZZZ";
end case;
end process;
end decoder4;
RESULT:
AIM:
Write VHDL source code to simulate ENCODER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity encoder4 is
Port ( d : in std_logic_vector(3 downto 0);
a : out std_logic_vector(1 downto 0));
end encoder4;
begin
end encoder4;
RESULT:
ENCODER is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate MULTIPLEXER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux4 is
Port (i: in std_logic_vector (3 downto 0);
a, b: in std_logic;
y : out std_logic);
end mux4;
end Behavioral;
RESULT:
Multiplexer is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate DEMULTIPLEXER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity demux4 is
Port (e,a,b : in std_logic;
y : out std_logic_vector(3 downto 0));
end demux4;
begin
process (e,a,b)
begin
if e='1' then
if a='0' and b='0' then
y<= "0001";
elsif a='0' and b='1' then
y<= "0010";
elsif a='1' and b='0' then
y<= "0100";
elsif a='1' and b='1' then
y<= "1000";
end if;
else
y <="0000";
end if;
end process;
end demux4;
RESULT:
Demultiplexer is simulated using VHDL source code.
1. What is VHDL?
2. What are the advantages of VHDL?
3. What are the applications of VHDL?
4. What is an Entity?
5. What are ports?
6. What is an Architecture body?
7. What are the differences between signal assignment and variable assignment
statements?
8. What are the differences between inertial delay and transport delay?
9. What is the sensitivity list of process statement?
10. What is the difference between ‘std_logic” and ‘bit ‘type?
11. What are the different types of identifiers used in VHDL? Give examples?
AIM:
Write VHDL source code to simulate PARALLEL ADDER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity PAFOR is
Port (a: in std_logic_vector (3 downto 0);
b : in std_logic_vector(3 downto 0);
cin: in std_logic;
sm : out std_logic_vector (3 downto 0);
cout: out std_logic);
end PAFOR;
component FA is
port (a, b, cin: in std_logic; sum, carry: out std_logic);
end component;
signal cy: std_logic_vector (4 downto 0);
begin
end Behavioral;
RESULT:
PARALLELADDER is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate BCD ADDER.
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bcd_add is
Port ( a,b : in std_logic_vector(3 downto 0);
Cin : in std_logic;
sum: out std_logic_vector(3 downto 0);
cout :out std_logic);
end bcd_add;
end bcd_add;
RESULT:
BCD ADDER is simulated using VHDL source code.
VIVA QUESTIONS:
AIM:
write VHDL source code to simulate BCD to SEVEN SEGMENT DECODER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bcd_7seg is
Port ( a, b, c, d : in std_logic;
x : out std_logic_vector(6 downto 0));
end bcd_7seg;
begin
process (a, b, c, d)
begin
s := a& b& c& d;
if (s="0000") then
x<= "1111110";
elsif (s="0001") then
x<= "0110000";
elsif (s="0010") then
x<= "1101101";
elsif (s="0011") then
x<= "1111001";
elsif (s="0100") then
x<= "0110011";
elsif (s="0101") then
x<= "1011011";
elsif (s<="0110") then
x<= "1011111";
elsif (s="0111") then
x<= "1110000";
elsif (s="1000") then
x<= "1111111";
end process;
end bcd_7seg;
RESULT:
BCD to SEVEN SEGMENT DECODER is simulated using VHDL source
code.
AIM:
Write VHDL source code to simulate BINARY TO GRAY CODE
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity binarytogrey is
Port (b: in std_logic_vector (3 downto 0) ;
g: out std_logic_vector (3 downto 0));
end binarytogrey;
begin
g (3) <= b(3);
g (2) <= b (3) xor b (2);
g (1) <= b (2) xor b (1);
g (0) <= b (1) xor b(0);
end Behavioral;
RESULT:
BINARY TO GRAYCODE CONVERTER is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate GRAY TO BINARY CODE
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity greytobinary is
Port (g: in std_logic_vector (3 downto 0) ;
b: out std_logic_vector (3 downto 0));
end greytobinary;
begin
b (3) <=g (3);
b (2) <=g (3) xor g(2);
b (1) <=(g (3) xor g (2)) xor g (1);
b (0) <=(g (3) xor g (2)) xor (g (1) xor g (0));
end dataflow;
RESULT:
GRAY TO BINARY CODE CONVERTER is simulated using VHDL source code.
VIVA QUESTIONS:
AIM:
Write VHDL source code to simulate SIMULATION OF SR FLIP-FLOP.
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity sr_ff is
Port ( s,r,p,c,clk : in std_logic;
q: out std_logic;
nq: out std_logic );
end sr_ff;
architecture Behavioral of sr_ff is
begin
process(s,r,p,c,clk)
variable tq: std_logic : ='0';
begin
if p='0' and c=’1’ then
tq :='1';
elsif c='0' and p=’1’ then
tq := '0';
elsif p='1' and c='1' then
if clk ='0' and clk'event then
if(s='0' and r='0') then
tq: = tq;
elsif(s='0' and r='1') then
tq: ='0';
elsif(s='1' and r='0') then
tq: ='1';
elsif(s='1' and r='1') then
tq: =’X’;
end if;
end if;
else
null;
end if;
q<=tq;
nq<=not tq;
end process;
end Behavioral;
RESULT:
SR FLIP-FLOP is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate JK FLIP-FLOP
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity JKFF is
Port (j, k, p, c, clk : in std_logic;
q: out std_logic;
nq: out std_logic );
end JKFF;
RESULT:
JK FLIP- FLOP is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate D FLIP-FLOP.
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity d_ff is
Port ( d, p, c, clk : in std_logic;
q : out std_logic;
nq : out std_logic);
end d_ff;
begin
begin
if p='1' and c='0' then
tq:= '0';
elsif p='0' and c='1' then
tq:= '1';
elsif p='1' and c='1' then
if clk ='0' and clk'event then
tq:= d;
end if;
else
null;
end if;
q<=tq;
nq<=not tq;
end process;
end d_ff;
RESULT:
D FLIP-FLOP is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate JK Flip-Flop
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity t_ff is
Port ( t, p, c, clk : in std_logic;
q: out std_logic;
nq :out std_logic);
end t_ff;
begin
if p='1' and c='0' then
s1:= '0';
elsif p='0' and c='1' then
s1:= '1';
elsif p='1' and c='1' then
if clk ='0' and clk'event then
if(t='0') then
s1:=s1;
elsif(t='1') then
s1:=not s1;
end if;
end if;
else
null;
end if;
q<=s1;
nq<=not s1;
end process;
end Behavioral;
RESULT:
T Flip-Flop is simulated using VHDL Source code.
AIM:
Write VHDL source code to simulate Synchronous up/down counter
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity updnsyn is
Port (clk,m : in std_logic;
q : out std_logic_vector(2 downto 0);
nq : out std_logic_vector(2 downto 0));
end updn_syn;
end updn_syn;
RESULT:
Synchronous up/down counter is simulated using VHDL Source code.
AIM:
Write VHDL source code to simulate SYNCHRONOUS BCD COUNTER.
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bcd_syn is
Port ( clk : in std_logic;
q : out std_logic_vector(3 downto 0);
nq : out std_logic_vector(3 downto 0));
end bcd_syn;
end bcd_syn;
RESULT:
SYNCHRONOUS BCD COUNTER is simulated using VHDL source code.
VIVA QUESTIONS:
1.What are the differences between signals and variables?
2.How do you declare a constant in VHDL?
3.Simulate the function f=∑(1,3,5,7) in dataflow model
4.Simulate the function f=∑(1,3,5,7) in behavioral model
5.Simulate the function f=∑(1,3,5,7) in structural model
AIM:
Write VHDL source code to simulate BIDIRECTIONAL SHIFT REGISTER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity shrg is
Port ( x, m, clk : in std_logic;
q : out std_logic_vector(3 downto 0);
nq : out std_logic_vector(3 downto 0));
end shrg;
q<= tq;
nq<= not tq;
end process;
end br_design;
RESULT:
BIDIRECTIONAL SHIFT REGISTER is simulated using VHDL source code.
AIM:
Write VHDL source code to simulate BARREL SHIFT REGISTER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity brlshr is
generic(n:positive:=8);
Port ( data : in std_logic_vector(n-1 downto 0);
s : in integer range 0 to n-1;
Barr_out : out std_logic_vector(n-1 downto 0) );
end brlshr;
begin
process(data,s)
variable temp:std_logic_vector(n-1 downto 0);
begin
temp:= data;
for i in 1 to s loop
temp:=temp(n-2 downto 0) & temp( n-1);
end loop;
barr_out<= temp;
end process;
end Behavioral;
RESULT:
BARREL SHIFT REGISTER is simulated using VHDL source code.
VIVA QUESTIONS:
1. Give the syntax for GENERATE statement.
2. RTL stands for?
3. what are the differences among IN, OUT and INOUT types
4. Give syntax for ‘with select’ statement.
5. Give syntax for ‘when else’ statement.
AIM:
Write VHDL source code to simulate FSM GRAY CODE COUNTER
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fsmgray is
Port ( ck : in std_logic;
q : out std_logic_vector(2 downto 0):=”000”);
end fsmgray;
RESULT:
FSM GRAY CODE COUNTER is simulated using VHDL source code.
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fsmdet is
Port ( x,ck,resetn : in std_logic;
q : out std_logic);
end fsmdet;
RESULT:
FSM SEQUENCE DETECTOR is simulated using VHDL source code.