DSP Lab Manual
DSP Lab Manual
KOTHAMANGALAM
ECL 333
DIGITAL SIGNAL PROCESSING LABORATORY
MANUAL
FIFTH SEMESTER,
B. TECH -2019
APJAKTU
LIST OF EXPERIMENTS
1. Simulation of Signals
b. Circular Convolution.
c. Parseval’s Theorem
8. FFT of signals
AIM
To simulate the following signals using Python
1. Unit impulse signal
2. Unit pulse signal
3. Unit ramp signal
4. Bipolar pulse
5. Triangular signal
THEORY
/* Write Notes on Python basics and Numpy */
/*Define the given signals*/
CODE
Refer Appendix A and write the code in lab record
OBSERVATION
/*Paste the obtained plots on the left side of lab record*/
RESULT
Exp 2: Verification of the Properties of DFT
AIM
a) Generate and appreciate a DFT matrix using python
b) Write a python function that returns the circular convolution of an N1 point sequence
and an N2 point sequence given at the input
c) Prove Parseval’s Theorem using two random complex sequences
METHODOLOGY
1. Generate and appreciate a DFT matrix
a. Write a function that returns the N point DFT matrix for a given N.
b. Plot its real and imaginary parts of VN as images using matshow or imshow
command (in Python) for N = 16, N = 64 and N = 1024
c. Compute the DFTs of 16 point, 64 point and 1024 point random sequences using
the above matrices.
d. Observe the time required for computations for N = 2γ for various values of γ
and plot the time required for computation of DFT via fft function and DFT
matrix and appreciate the computational saving with FFT.
2. Write a python script to perform linear convolution of two sequences and then using
linear convolution, compute circular convolution
3. Verify Parseval’s theorem using two complex sequences each of length 5000.
THEORY
/*Give a brief description on DFT, FFT, Circular convolution and Parseval’s theorem */
CODE
Refer Appendix A and write the code in lab record
OBSERVATION
/* Paste the plots on the left side of Lab Record and write down your observations */
RESULT
Exp 3: Familiarization of DSP Hardware: LED Blinking and
Waveform Generation
AIM
a) To familiarize with DSP board and to write a C code to Blink a LED in LPC1769 Board.
b) To control turning on of a LED using a switch.
c) To generate a sinusoidal waveform and a square waveform using LPC1769 and observe
the waveform in a DSO
THEORY
/*Give a brief description on LPC 1769 Board */
ALGORITHM
1. Write the Algorithm to Blink a LED.
2. Write the Algorithm to control the turning on of a LED based on the status of a switch.
3. Write the Algorithm to generate a sinusoidal waveform using LPC1769 board.
CODE
Refer Appendix A and write the code in lab record.
OBSERVATION
/*Draw the observed waveforms on graph paper and paste them on the left side of Lab
Record. Also, mention the time period and frequency of the waveform and the delay settings
used to generate the waveform.*/
Sine Wave
Delay Value Frequency Vmax Vmin
Square Wave
Delay Value Frequency Vmax Vmin
RESULT
Exp 4: Familiarization of DSP Hardware: Sampling and
Reproducing an Analog Waveform
AIM
a) To convert an input analog signal into discreet samples and output the same samples
via DAC using LPC1769 board.
b) To study the effect of sampling rate and aliasing.
THEORY
/*Give a brief description on Nyquist Sampling theorem and aliasing. With the help of
a diagram, explain what happens if a co-sinusoid of frequency 5 kHz is sampled at
a. 14 KHz
b. 8 KHz
*/
PROCEDURE
a) Make a connection between the ground pins of two different LPC1769 boards using a
breadboard.
b) Generate a sinusoid at around 9KHz using the first LPC1769 board and output the
waveform through DAC. This sinusoid will be the input signal for the second
LPC1769 board.
c) Load the second board with the program to sample an input analog signal and
reconstruct it via DAC.
d) Connect the DAC output from board 1 to the ADC of board 2 using a breadboard.
e) Change the delay in the second board to vary the ADC sampling rate and measure the
resulting sampling rate by toggling a GPIO pin.
f) Initially adjust the delay such that the sampling rate satisfies the Nyquist sampling
theorem and measure the frequency of the reconstructed waveform.
g) Now adjust the delay such that the sampling rate doesn’t satisfy the Nyquist sampling
theorem and measure the frequency of the reconstructed waveform.
ALGORITHM
Write the algorithm to sample an input analog signal and reconstruct it via DAC. Also
mention how to determine sampling rate.
CODE
Refer to Appendix A and write the code in lab record.
OBSERVATION
Input Sinusoid Value of ADC ADC Sampling Frequency of
Sl No
Frequency Delay variable Rate Output Sinusoid
1
2
3
4
Draw the input and output waveforms on graph paper and paste them on the left side
of Lab Record. Also mention the time period and frequency of the waveform and the delay
settings used to generate the waveform.
RESULT
Exp 5 : Linear Convolution
AIM
To perform linear and circular convolution on given samples of data using LPC
trainer board.
THEORY
/*Write the theory regarding convolution and DAC output voltage*/
ALGORITHM
/*Write the algorithm after reading the code*/
CODE
Refer to Appendix A and write the code in lab record.
OBSERVATION
Signal Sample Values
x(n)
h(n)
y(n) = x(n) ∗ h(n)
RESULT
Exp 6 : FIR Low Pass Filter
AIM
To design a low pass filter with normalized cut off frequency 𝑣𝑐 = 0.1 and implement
the low pass filter in LPC trainer board. Also plot the frequency response of FIR Filter.
THEORY
/*Write the theory regarding FIR filter and Windowing. */
/*Refer Section 4.4 and 4.5 of the text book: DSP Applications Using C and the TMS320C6x
DSK by Rulph Chassaing */
PROCEDURE
a) Make a connection between the ground pins of two different LPC1769 boards.
b) Generate a sinusoid using the first LPC1769 board and connect it to the ADC of
second LPC1769 board.
c) Design the LPF and generate FIR filter coefficients using python code. Use the
generated filter coefficients for FIR filter implementation in LPC board.
d) Load the second board with FIR filtering program.
e) Input sinusoid after passing to the FIR filter, is observed from the DAC output of
second board.
f) Plot the frequency response of the FIR filter by changing the frequency of input
sinusoid and measuring the amplitude of FIR filter output.
g) Measure the ADC sampling rate by toggling a port pin as in experiment 4.
h) If 𝐹𝑆 is the measured sampling rate, then the frequency corresponding to normalized
frequency 𝑣𝑐 is :
𝐹𝑆
𝑓 = 𝑣𝐶 . Hz
2
Note:
For normalized frequency 𝑣, digital frequency(𝜔) is given by: 𝜔 = 𝑣. 𝜋 rad/sec.
𝐹
𝜔 = 𝜋 𝑟𝑎𝑑/𝑠𝑒𝑐 Corresponds to a frequency 𝑓 = 2𝑆 Hz.
𝐹
∴ 𝜔 = 𝑣. 𝜋 𝑟𝑎𝑑/𝑠𝑒𝑐 Corresponds to a frequency 𝑓 = 𝑣. 2𝑠 Hz.
DESIGN
Let number of FIR filter taps: N = 25 and normalized frequency 𝑣𝑐 = 0.1.
𝑁
Q = ⌊ 2 ⌋ = 12
𝑠𝑖𝑛 (𝑣𝑐 𝑛𝜋)
LPF Impulse response coefficients: ℎ𝑠 = 𝐶𝑛 = , where 𝑛 = 0, ±1, ±2 . . . ±𝑄 and
𝑛𝜋
𝐶0 = 𝑣𝑐 .
Choose window function 𝑤(𝑛) to be a Kaiser window or a Hamming window of length N.
Then FIR filter coefficients h(n) is given by
ℎ(𝑛) = ℎ𝑠 (𝑛). 𝑤(𝑛)
ALGORITHM
/*Write the algorithm after reading the code*/
CODE
Refer to Appendix A and write the code in lab record.
OBSERVATION
ADC Sampling Frequency 𝐹𝑠 :
Normalized cutoff of frequency 𝑣𝑐 :
Designed Cutoff frequency of LPF (in Hz) :
Peak to Amplitude
Input signal
peak voltage of output
Sl No Frequency
of output signal
(Hz)
signal (V) (V)
1
2
3
4
/* Plot the frequency response of the FIR filter in a graph paper and compute the observed cut
off frequency*/
RESULT
Exp 7 : IFFT with FFT
AIM
To compute IFFT of a signal using FFT routine in LPC trainer board.
THEORY
N point FFT of discreet samples x(n) is given by
𝑁−1
𝑗2𝜋𝑘𝑛
−
𝑋(𝑘) = ∑ 𝑥(𝑛) 𝑒 𝑁 𝑤ℎ𝑒𝑟𝑒 𝑘 = 0 𝑡𝑜 𝑁 − 1 (1)
𝑛=0
N point FFT takes N samples of x(n) (treated as time domain samples) and outputs N samples
in frequency domain.
Corresponding formula for IFFT is :
𝑁−1
1 +
𝑗2𝜋𝑘𝑛
𝑥(𝑛) = ∑ 𝑋(𝑘) 𝑒 𝑁 𝑤ℎ𝑒𝑟𝑒 𝑛 = 0 𝑡𝑜 𝑁 − 1 (2)
𝑁
𝑘=0
𝑁−1 ∗
∗(
1 +
𝑗2𝜋𝑘𝑛
𝑥 𝑛) = [∑ 𝑋(𝑘) 𝑒 𝑁 ]
𝑁
𝑘=0
As (𝑎𝑏)∗ = 𝑎∗ . 𝑏 ∗
𝑁−1
∗( )
1 𝑗2𝜋𝑘𝑛
∗( ) − 𝑁
𝑥 𝑛 = ∑𝑋 𝑘 𝑒
𝑁
𝑘=0
𝑁−1
1 𝑗2𝜋𝑘𝑛
∗( ) − 𝑁
∴ ∑𝑋 𝑘 𝑒 = 𝑥 ∗ (𝑛)
𝑁
𝑘=0
Taking conjugate on both sides
𝑁−1 ∗
1 −
𝑗2𝜋𝑘𝑛
[ ∑ 𝑋 ∗ (𝑘) 𝑒 𝑁 ] = 𝑥(𝑛) (3)
𝑁
𝑘=0
But from eqn (2), IFFT of X(k) is x(n).
Below steps details the procedure to obtain IFFT of FFT output X(k) using eqn. (3).
Algorithm to obtain IFFT of X(k) using FFT routine
Step 1: Take conjugate of FFT output samples 𝑋(𝑘) to obtain 𝑋 ∗ (𝑘) and pass it to FFT routine.
Step 2: The output of FFT routine is then divided by a factor N.
Step 3: Take the conjugate of the obtained result to obtain the samples x(n), which is the IFFT
of X(k).
PROCEDURE
Load the program for computing IFFT using FFT into LPC trainer board and observe
the input signal, FFT output and the also the signal obtained after taking IFFT of FFT samples.
CODE
Refer to Appendix A and write the code in lab record.
OBSERVATION
Plot the input signal, FFT output and signal after IFFT in a graph sheet.
RESULT
APPENDIX A
APPENDIX A : Python and C codes
Exp 1: Simulation of Signals: Python Code
Exp 2: Verify of the properties of DFT computationally: Python Code
2.a. Python code to generate DFT matrix and compare the time elapsed for computing
DFT via FFT function and DFT matrix method
2.b. Circular Convolution and Parseval’s Theorem : Python Code
Exp 3: Familiarization of LPC1769 Board : LED Blinking and Waveform
Generation
3.a: Code to control a LED using a switch
LPC1769 Microcontroller
LPC1769 is an ARM core based microcontroller from NXP Semiconductors. It is
commonly used for embedded applications requiring low power dissipation.
MANUAL
PART - B
DEPARTMENT OF ECE
MACE
LPC1769 Board Schematic
LPC1769 – Register Details
I) Port pin function
PINSEL0
PINSEL1
Pin Function Function Function Function Reset
Bit
name when 00 when 01 when 10 when 11 value
1:0 P0.16 GPIO Port 0.16 RXD1 SSEL0 SSEL 00
3:2 P0.17 GPIO Port 0.17 CTS1 MISO0 MISO 00
5:4 P0.18 GPIO Port 0.18 DCD1 MOSI0 MOSI 00
7:6 P0.19 GPIO Port 0.19 DSR1 Reserved SDA1 00
9:8 P0.20 GPIO Port 0.20 DTR1 Reserved SCL1 00
11:10 P0.21 GPIO Port 0.21 RI1 Reserved RD1 00
13:12 P0.22 GPIO Port 0.22 RTS1 Reserved TD1 00
15:14 P0.23 GPIO Port 0.23 AD0.0 I2SRX_CLK CAP3.0 00
17:16 P0.24 GPIO Port 0.24 AD0.1 I2SRX_WS CAP3.1 00
19:18 P0.25 GPIO Port 0.25 AD0.2 I2SRX_SDA TXD3 00
21:20 P0.26 GPIO Port 0.26 AD0.3 AOUT RXD3 00
23:22 P0.27 GPIO Port 0.27 SDA0 USB_SDA Reserved 00
25:24 P0.28 GPIO Port 0.28 SCL0 USB_SCL Reserved 00
27:26 P0.29 GPIO Port 0.29 USB_D+ Reserved Reserved 00
29:28 P0.30 GPIO Port 0.30 USB_D- Reserved Reserved 00
31:30 - Reserved Reserved Reserved Reserved 00
arm_cfft_radix4_instance_f32 x;
2. arm_cfft_radix4_init_f32 :
It is a function to initialise the parameters for computing FFT/IFFT.
Function Prototype:
arm_cfft_radix4_init_f32 (arm_cfft_radix4_instance_f32 * ptr, uint16_t fftLen,
uint8_t ifftFlag, uint8_t bitReverseFlag );
4. arm_cmplx_mag_f32:
C function used to compute magnitude of FFT/IFFT output.
Function Prototype:
arm_cmplx_mag_f32 (float *FFTBuff, float *MagnitudeBuff, uint32_t NFFT);
4 Port 0.1
5 Port 0.0
J1 22 GND
23 GND
24 GND
1 LED Connected
J3
2 LED Connected
1 GND
2 GND
3 P0.26 / AOUT (DAC Out)
J26
6 P0.23 / AD0.0 (ADC Channel 0 Input)
11 GND
12 GND
1 VDD (+3.3 V)
2 VDD (+3.3 V)
J27
3 VDD (+3.3 V)
4 VDD (+3.3 V)