R23 DSP Lab Record
R23 DSP Lab Record
AIM: To generate and plot discrete-time unit step, impulse, ramp, exponential, and sinusoidal
signals using MATLAB.
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY
Discrete-time signals are defined only at discrete instances of time and are represented as
sequences. Some basic discrete-time signals are:
1. Unit Impulse Signal:
1, 𝑛 = 0
𝛿[𝑛] = {
0, 𝑛 ≠ 0
3. Ramp Signal:
𝑛, 𝑛 ≥ 0
𝑟[𝑛] = {
0, 𝑛 < 0
4. Exponential Signal:
𝑥[𝑛] = 𝑒 −𝑎𝑛 𝑢[𝑛]
Procedure:
1. Open MATLAB Software.
Launch MATLAB from yo
2. ur computer.
3. Create a new script file.
Go to Home → New Script (or press Ctrl + N) to open a new editor window.
4. Type the MATLAB code provided below into the editor window.
5. Save the script file.
Save it with a meaningful name, for example:
basic_discrete_signals.m
6. Run the program.
Click the Run button (or press F5). MATLAB will execute the script.
7. Observe the output.
A figure window will open, showing five subplots:
o Unit Step Signal
o Impulse Signal
o Ramp Signal
o Exponential Signal
o Sinusoidal Signal
8. Analyze each plot.
Note the discrete nature of each signal as shown by the stem plots.
9. Close the figure window and MATLAB after verification.
MATLAB Program:
clc;
clear all;
close all;
n = -10:0.1:10;
% Unit step signal
u_discrete = double(n >= 0);
% Impulse signal
impulse_discrete = double(n == 0);
% Ramp signal
r_discrete = n .* (n >= 0);
% Exponential signal
subplot(5,1,5);
stem(n, sin_discrete);
Result:
The discrete-time unit step, impulse, ramp, exponential, and sinusoidal signals were successfully generated
and plotted using MATLAB.
AIM: To implement a discrete-time system defined by its difference equation and to obtain the
output response 𝑦[𝑛]for a given input 𝑥[𝑛]using MATLAB.
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY:
A discrete-time Linear Time-Invariant (LTI) system can be represented by a difference
equation of the form:
Where:
𝑥[𝑛]→ Input signal
𝑦[𝑛]→ Output signal
𝑏𝑘 → Feedforward (numerator) coefficients
𝑎𝑙 → Feedback (denominator) coefficients
𝑀, 𝑁→ Orders of the numerator and denominator, respectively
This represents a digital filter (IIR or FIR) depending on whether feedback terms 𝑎𝑙 are present.
For example, the system difference equation is:
𝑦[𝑛] = 0.5𝑥[𝑛] + 0.3𝑥[𝑛 − 1] + 0.2𝑥[𝑛 − 2] + 0.4𝑦[𝑛 − 1] − 0.12𝑦[𝑛 − 2]
Here, coefficients b correspond to the input part, and a coefficients correspond to the output part
of the system.
Procedure:
1. Open MATLAB Software.
Launch MATLAB on your computer.
2. Create a new script file.
Click on Home → New Script (or press Ctrl + N).
3. Type the MATLAB code given below into the editor window.
4. Save the script with an appropriate name, e.g.,discrete_system_response.m
5. Run the program by clicking Run (or pressing F5).
6. Observe the output in the Figure window —
The input signal and output signal are plotted using stem plots.
MATLAB Program:
clc;
clear;
% Input signal x[n]
N = 50; % Length of signal
n = 0:N-1;
x = [ones(1,10), zeros(1,N-10)]; % Example input: step signal of length 10
% System coefficients (example)
b = [0.5 0.3 0.2]; % Numerator coefficients (input)
a = [1 -0.4 0.12]; % Denominator coefficients (output); a(1) must be 1
% Initialize output y[n]
y = zeros(1, N);
% Difference equation implementation
for i = 1:N
for j = 1:length(b)
if (i - j + 1 > 0)
y(i) = y(i) + b(j) * x(i - j + 1);
end
end
for j = 2:length(a)
if (i - j + 1 > 0)
y(i) = y(i) - a(j) * y(i - j + 1);
end
end
end
% Plot input and output signals
figure;
subplot(2,1,1);
stem(n, x, 'filled');
title('Input Signal x[n]');
xlabel('n');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
stem(n, y, 'filled');
title('Output Signal y[n]');
xlabel('n');
ylabel('Amplitude');
grid on;
Result:
The discrete-time system was successfully implemented using its difference equation, and the output
response was obtained for a given input signal using MATLAB.
AIM: To compute and plot the Magnitude and Phase Spectrum of a given discrete-time signal using the
Discrete-Time Fourier Transform (DTFT) in MATLAB.
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY:
The Discrete-Time Fourier Transform (DTFT) represents a discrete-time signal 𝑥[𝑛]in the frequency
domain and is defined as:
Here,
The magnitude and phase spectra of the DTFT are given by:
By plotting these spectra, we can analyze how different frequency components contribute to the original
signal.
Procedure:
1. Open MATLAB software.
Start MATLAB on your system.
MATLAB Program:
clc;
clear all;
close all;
% Time index
n = 0:20;
% Input discrete-time signal
x = cos(0.2*pi*n) + 0.5*sin(0.6*pi*n);
% Number of frequency samples
Nf = 1024;
% Frequency vector from -pi to pi
omega = linspace(-pi, pi, Nf);
% Initialize DTFT result
X = zeros(1, Nf);
% Compute DTFT manually
for k = 1:Nf
X(k) = sum(x .* exp(-1j * omega(k) * n));
end
% Plot Magnitude Spectrum
subplot(2,1,1);
plot(omega/pi, abs(X), 'LineWidth', 1.5);
xlabel('\omega/\pi');
ylabel('|X(e^{j\omega})|');
title('Magnitude Spectrum');
grid on;
Result:
The magnitude and phase spectra of the given discrete-time signal were successfully computed and plotted
using MATLAB.
AIM: To compute and plot the magnitude and phase response of a discrete-time system from its impulse
response using MATLAB.
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY:
The frequency response of a discrete-time LTI system characterizes how each frequency
component of an input signal is modified by the system.
If ℎ[𝑛]is the impulse response of the system, the Discrete-Time Fourier Transform (DTFT) gives the
frequency response:
Where:
This experiment calculates 𝐻(𝑒 𝑗𝜔 )numerically for a given impulse response ℎ[𝑛] = (0.9)𝑛 𝑢[𝑛]and plots
its magnitude and phase.
Procedure:
1. Open MATLAB software on your system.
2. Create a new script by clicking Home → New Script (or press Ctrl + N).
3. Type the MATLAB code (given below) into the editor.
4. Save the script with a meaningful name, e.g., system_frequency_response.m.
5. Run the program by clicking the Run button or pressing F5.
The magnitude plot shows how the system amplifies or attenuates different frequency
components.
The phase plot shows the phase shift introduced by the system at each frequency.
MATLAB Program:
clc;
clear all;
close all;
% Time index
n = 0:20;
% Impulse response of the system
h = (0.9).^n .* (n >= 0);
% Number of frequency samples
Nf = 1024;
% Frequency vector from -pi to pi
omega = linspace(-pi, pi, Nf);
% Initialize frequency response
H = zeros(1, Nf);
% Compute DTFT of h[n] to get frequency response
for k = 1:Nf
H(k) = sum(h .* exp(-1j * omega(k) * n));
end
% Plot magnitude response
subplot(2,1,1);
plot(omega/pi, abs(H), 'LineWidth', 1.5);
xlabel('\omega/\pi');
ylabel('|H(e^{j\omega})|');
title('Magnitude Response of the System');
grid on;
% Plot phase response
subplot(2,1,2);
plot(omega/pi, angle(H), 'LineWidth', 1.5);
xlabel('\omega/\pi');
ylabel('\angle H(e^{j\omega})');
title('Phase Response of the System');
grid on;
Result:
The magnitude and phase response of the discrete-time system with impulse response
AIM:
1. To compute the Discrete Fourier Transform (DFT) and Inverse DFT (IDFT) of a given
sequence using MATLAB.
2. To demonstrate the following properties of DFT:
Linearity
Circular Time Shift
Conjugate Symmetry (for real sequences)
Parseval’s Theorem
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY:
The Discrete Fourier Transform (DFT) converts a discrete-time signal 𝑥[𝑛]into its frequency domain
representation 𝑋[𝑘]:
𝑁−1
The Inverse DFT (IDFT) reconstructs the original sequence from its DFT:
𝑁−1
1
𝑥[𝑛] = ∑ 𝑋[𝑘] ⋅ 𝑒 𝑗2𝜋𝑘𝑛/𝑁 , 𝑛 = 0,1, . . . , 𝑁 − 1
𝑁
𝑘=0
Properties Demonstrated:
1. Linearity: DFT of 𝑎𝑥[𝑛] + 𝑏𝑦[𝑛]equals 𝑎𝑋[𝑘] + 𝑏𝑌[𝑘].
2. Circular Time Shift: A shift in time corresponds to a linear phase change in frequency:
𝑁−1 𝑁−1
1
2
∑ ∣ 𝑥[𝑛] ∣ = ∑ ∣ 𝑋[𝑘] ∣2
𝑁
𝑛=0 𝑘=0
Procedure:
1. Start MATLAB and open a new script.
2. Input Sequence:
Enter a sequence vector, e.g., [1 2 3 4].
3. Compute DFT:
Use the formula:
X[k] = sum(x[n]*exp(-j*2*pi*k*n/N))
4. Compute IDFT:
Reconstruct the original sequence using:
x[n] = (1/N) * sum(X[k]*exp(j*2*pi*k*n/N))
5. Plot the Results:
Plot original sequence, magnitude, and phase of DFT, and reconstructed sequence.
6. Linearity Property:
Input another sequence y[n] and scalars a and b.
Compute a*DFT(x) + b*DFT(y) and compare with DFT(a*x + b*y).
7. Circular Time Shift Property:
Enter a shift value m.
Compute DFT of shifted sequence and compare with theoretical phase shift:
𝑋[𝑘]𝑒 −𝑗2𝜋𝑘𝑚/𝑁
Result:
1. DFT transforms discrete-time sequences to the frequency domain, while IDFT reconstructs
the sequence.
2. All 4 properties of DFT were verified successfully in MATLAB.
AIM:
1. To design FIR filters (LPF, HPF, BPF, BSF) using different window techniques in MATLAB.
2. To analyze the effect of different window functions on filter characteristics.
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY:
FIR Filter Design:
A Finite Impulse Response (FIR) filter has a finite duration impulse response and is inherently stable. FIR
filters are widely used due to their linear phase property.
Window Method:
The ideal filter impulse response is truncated using a window function to make it finite.
Common window functions:
1. Rectangular Window – Simple truncation; high ripples in frequency response.
2. Triangular (Bartlett) Window – Reduces ripples; smoother transition.
3. Kaiser Window – Adjustable parameter for trade-off between mainlobe width and sidelobe
attenuation.
Filter Specifications:
𝑅𝑝 : Passband ripple
𝑅𝑠 : Stopband ripple
𝑓𝑝 : Passband frequency
𝑓𝑠 : Stopband frequency
𝑓𝑠 𝑎𝑚𝑝: Sampling frequency
Normalized Frequencies:
2𝑓𝑝 2𝑓𝑠
𝜔𝑝 = , 𝜔𝑠 =
𝑓𝑠 𝑎𝑚𝑝 𝑓𝑠 𝑎𝑚𝑝
−20log10 (√𝑅𝑝 𝑅𝑠 ) − 13
𝑁 = ceil( )
14.6 ⋅ (𝑓𝑠 − 𝑓𝑝 )/𝑓𝑠 𝑎𝑚𝑝
Procedure:
1. Start MATLAB and open a new script.
2. Input Filter Specifications:
o Passband ripple (𝑅𝑝 )
o Stopband ripple (𝑅𝑠 )
o Passband frequency (𝑓𝑝 )
o Stopband frequency (𝑓𝑠 )
o Sampling frequency (𝑓𝑠 𝑎𝑚𝑝)
3. Compute Normalized Frequencies
4. Calculate Filter Order (N)
5. Select Window Function
6. Design FIR Filters using fir1
7. Compute Frequency Response
8. Plot the Frequency Response
9. Analyze the Results:
o Observe the effect of different window functions on ripples and transition width.
o Compare LPF, HPF, BPF, BSF responses for the chosen window.
MATLAB Program:
clc; clear all; close all;
% Filter specifications
rp = input('Enter passband ripple: ');
rs = input('Enter stopband ripple: ');
fp = input('Enter passband freq: ');
fs = input('Enter stopband freq: ');
f = input('Enter sampling freq: ');
% Normalized frequencies
wp = 2*fp/f;
ws = 2*fs/f;
% Window selection
c = input('Enter your choice of window function 1. Rectangular 2. Triangular 3. Kaiser: ');
if(c==1)
y = rectwin(n1);
disp('Rectangular window filter response');
elseif(c==2)
y = triang(n1);
disp('Triangular window filter response');
elseif(c==3)
y = kaiser(n1);
disp('Kaiser window filter response');
end
% LPF
b = fir1(n, wp, y);
[h,o] = freqz(b,1,256);
m = 20*log10(abs(h));
subplot(2,2,1); plot(o/pi, m);
title('LPF'); ylabel('Gain in dB'); xlabel('Normalized frequency');
% HPF
% BPF
wn = [wp ws];
b = fir1(n, wn, y);
[h,o] = freqz(b,1,256);
m = 20*log10(abs(h));
subplot(2,2,3); plot(o/pi, m);
title('BPF'); ylabel('Gain in dB'); xlabel('Normalized frequency');
% BSF
b = fir1(n, wn, 'stop', y);
[h,o] = freqz(b,1,256);
m = 20*log10(abs(h));
subplot(2,2,4); plot(o/pi, m);
title('BSF'); ylabel('Gain in dB'); xlabel('Normalized frequency');
Result:
1. LPF, HPF, BPF, BSF responses are displayed in a single figure.
2. Rectangular window produces the highest ripple, triangular window reduces ripples, Kaiser
window allows adjustable trade-off.
3. Filter transition width and stopband attenuation vary with window choice.
AIM:
1. To design an IIR (Infinite Impulse Response) filter using Butterworth approximation.
2. To analyze the magnitude and phase response of the designed IIR filter.
SOFTWARE REQUIRED:
MATLAB R2012a or above
THEORY:
IIR Filters:
IIR filters have infinite duration impulse response and can achieve a desired frequency response
using a lower order compared to FIR filters.
They are designed using analog prototypes like Butterworth, Chebyshev, or Elliptic filters.
Butterworth Filter:
Provides a maximally flat magnitude response in the passband.
The filter order determines the sharpness of the transition band.
Design Specifications:
𝑅𝑝 : Passband ripple (dB)
𝑅𝑠 : Stopband ripple (dB)
𝑓𝑝 : Passband frequency (Hz)
𝑓𝑠 : Stopband frequency (Hz)
𝑓𝑠𝑎𝑚𝑝𝑙𝑖𝑛𝑔 : Sampling frequency (Hz)
Normalized Frequencies:
2𝑓𝑝 2𝑓𝑠
𝜔𝑝 = , 𝜔𝑠 =
𝑓𝑠 𝑓𝑠
Procedure:
1. Start MATLAB and open a new script.
2. Input Filter Specifications:
Passband ripple (𝑅𝑝 )
Stopband ripple (𝑅𝑠 )
Passband frequency (𝑓𝑝 )
Stopband frequency (𝑓𝑠 )
Sampling frequency (𝑓𝑠𝑎𝑚𝑝𝑙𝑖𝑛𝑔 )
3. Compute Normalized Frequencies
4. Determine Filter Order and Cutoff:
Use buttord to compute minimum order 𝑛and cutoff frequency wn:
5. Choose Filter Type
6. Compute Frequency Response:
Use freqs to obtain complex frequency response:
7. Plot Magnitude and Phase:
Magnitude in dB: 20*log10(abs(h))
Phase in radians: angle(h)
Use subplot to plot magnitude and phase together.
8. Analyze the Results:
Observe the flatness of passband and roll-off in stopband.
Note the phase characteristics of the filter.
MATLAB Program:
clc;
clear all;
close all;
disp('Enter the IIR filter design specifications');
rp = input('Enter passband ripple: ');
rs = input('Enter stopband ripple: ');
wp = input('Enter passband freq: ');
ws = input('Enter stopband freq: ');
fs = input('Enter the sampling freq: ');
% Normalized frequencies
w1 = 2*wp/fs;
w2 = 2*ws/fs;
% Frequency response
w = 0:0.01:pi;
[h, om] = freqs(b, a, w);
m = 20*log10(abs(h));
an = angle(h);
Result:
IIR Butterworth filters were successfully designed in MATLAB.
The filter order and cutoff were automatically computed using buttord.
Magnitude and phase responses were verified and analyzed.
Theory
1. TMS320C6478 DSK
The TMS320C6478 Digital Signal Processor (DSK) is a high-performance, multicore DSP from Texas
Instruments designed for real-time digital signal processing applications. It is part of the TMS320C6000
series, optimized for computationally intensive tasks.
Key Features:
Multicore Architecture:
o Contains 8 VLIW (Very Long Instruction Word) DSP cores, allowing parallel processing for
high throughput.
o Each core can execute multiple instructions per clock cycle, improving processing efficiency.
High Clock Speed:
o Operates at up to 1 GHz, enabling fast real-time computation.
Memory and Peripherals:
o On-chip L1 and L2 memory for each core.
o External memory interfaces for SDRAM, DDR.
o On-board GPIO, timers, serial ports, and peripheral interfaces for DSP applications.
Floating-Point Support:
o Supports both fixed-point and floating-point operations, useful for signal processing tasks
like FFT, filtering, and matrix operations.
Real-Time Processing:
o Designed for low-latency applications, making it suitable for audio/video processing, radar,
communications, and industrial control systems.
Onboard Debug Features:
o JTAG interface for debugging.
o Real-time performance monitoring and trace capabilities.
Applications of TMS320C6478 DSK:
Software/Hardware Required
TMS320C6478 DSK board
Code Composer Studio (CCS)
USB or Ethernet connection to the DSK
Power supply for the DSK board
Procedure
A. Hardware Setup
1. Connect the DSK board to the PC via USB or Ethernet.
2. Power on the DSK board.
3. Verify proper startup using on-board LEDs.
B. CCS Setup
1. Open Code Composer Studio (CCS).
2. Create a new project:
o Select TMS320C6478 as the target.
o Choose a C Project or Assembly Project template.
3. Configure debugging settings to connect CCS with the DSK.
C. Writing and Executing Code
1. Write a simple DSP program, e.g., array addition or sine wave generation.
2. Build the project using the Build option.
3. Load the compiled program onto the DSK board.
4. Run the program and monitor output using:
o On-board LEDs
o CCS console or variable watch windows
D. Debugging
1. Set breakpoints to stop execution at desired locations.
2. Step through the program using Step Into / Step Over.
3. Observe registers, variables, and memory in real-time.
4. Modify variables to test behavior dynamically.
Result:
The TMS320C6478 DSK is a versatile and powerful DSP platform, capable of real-time, high-
performance processing.
Code Composer Studio (CCS) provides an effective environment for programming, debugging, and
analyzing DSP applications.
This experiment demonstrates hardware-software integration, parallel processing capabilities, and
real-time DSP programming on a multicore DSP.
Hardware/Software Required
Hardware:
o TMS320C6478 DSK or any DSP board with DAC output
o Oscilloscope or waveform visualization tool
Software:
o Code Composer Studio (CCS)
THEORY
Sinusoidal Waveform:
A sinusoidal signal can be mathematically represented as:
𝑥(𝑛) = 𝐴sin(2𝜋𝑓0 𝑛𝑇𝑠 + 𝜙)
Where:
𝐴= amplitude
𝑓0 = frequency of the sinusoid
𝑇𝑠 = sampling period (1/𝑓𝑠 )
𝜙= phase
Digital Implementation:
The DSP generates the sinusoid digitally using discrete-time samples.
The sampling frequency 𝑓𝑠 must satisfy the Nyquist criterion (𝑓𝑠 > 2𝑓0 ) to avoid aliasing.
TMS320C6478 DSK:
Uses high-speed computation and GPIO/DAC outputs for waveform generation.
Code is written in C language and executed using Code Composer Studio (CCS).
Procedure
A. Hardware Setup
1. Connect the DSP board to the PC via USB or Ethernet.
2. Connect DAC output pins to an oscilloscope to observe the waveform.
3. Power on the DSP board.
B. CCS Setup
1. Open Code Composer Studio (CCS).
2. Create a new project targeting the DSP (e.g., TMS320C6478).
3. Configure the project for C programming and real-time execution.
C. Writing the Code
Write a C program to generate discrete samples of a sinusoidal waveform.
Use a for loop to generate N samples and output through GPIO/DAC.
Program:
#include <math.h>
#include <stdio.h>
#define PI 3.141592653589793
#define N 100 // Number of samples
#define Fs 1000 // Sampling frequency in Hz
#define FREQ 50 // Frequency of sinusoid
#define AMPL 1000 // Amplitude (for DAC output)
void main(void)
{
int n;
double x;
}
}
Output:
Result:
1. A sinusoidal waveform was successfully generated using the DSP and CCS.
2. The sampling frequency and number of samples affect waveform resolution and smoothness.
3. CCS allows real-time programming, building, and debugging for waveform generation applications.
4. The DSP can be used for real-time signal generation and further processing in DSP applications.