[go: up one dir, main page]

0% found this document useful (0 votes)
16 views30 pages

R23 DSP Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views30 pages

R23 DSP Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Digital Signal Processing Department of ECE

Experiment No.: Date:

Generation of discrete time signals in time domain.

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

2. Unit Step Signal:


1, 𝑛 ≥ 0
𝑢[𝑛] = {
0, 𝑛 < 0

3. Ramp Signal:
𝑛, 𝑛 ≥ 0
𝑟[𝑛] = {
0, 𝑛 < 0

4. Exponential Signal:
𝑥[𝑛] = 𝑒 −𝑎𝑛 𝑢[𝑛]

where 𝑎 > 0determines the rate of decay.


5. Sinusoidal Signal:
𝑥[𝑛] = sin⁡(𝜔0 𝑛)

where 𝜔0 is the angular frequency in radians per sample.


These signals are fundamental in the study of discrete-time systems and digital signal processing
(DSP).

1|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

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

2|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

exp_discrete = exp(-n) .* (n >= 0);


% Sinusoidal signal
sin_discrete = sin((pi/2) * n);
% Plotting all signals
figure;
subplot(5,1,1);
stem(n, u_discrete);
title('Discrete-Time Unit Step Signal: u[n]');
xlabel('n (discrete time index)');
ylabel('Amplitude');
grid on;
subplot(5,1,2);
stem(n, impulse_discrete);
title('Discrete-Time Impulse Signal: δ[n]');
xlabel('n (discrete time index)');
ylabel('Amplitude');
grid on;
subplot(5,1,3);
stem(n, r_discrete);
title('Discrete-Time Ramp Signal: r[n]');
xlabel('n (discrete time index)');
ylabel('Amplitude');
grid on;
subplot(5,1,4);
stem(n, exp_discrete);
title('Discrete-Time Exponential Signal: e^{-n}');
xlabel('n (discrete time index)');
ylabel('Amplitude');
grid on;

subplot(5,1,5);
stem(n, sin_discrete);

3|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

title('Discrete-Time Sinusoidal Signal: sin[n]');


xlabel('n (discrete time index)');
ylabel('Amplitude');
grid on;

Result:
The discrete-time unit step, impulse, ramp, exponential, and sinusoidal signals were successfully generated
and plotted using MATLAB.

4|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

Implementation of discrete time systems in time domain.

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.

5|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

7. Analyze the system behavior.


Observe how the system modifies the input signal according to the difference equation.

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.

6|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

Frequency analysis of discrete time signals using DTFT.

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,

 𝑥[𝑛]→ Discrete-time signal

 𝑋(𝑒 𝑗𝜔 )→ Frequency-domain (DTFT) representation

 𝜔→ Digital frequency in radians/sample

The magnitude and phase spectra of the DTFT are given by:

∣ 𝑋(𝑒 𝑗𝜔 ) ∣= magnitude of 𝑋(𝑒 𝑗𝜔 )


∠𝑋(𝑒 𝑗𝜔 ) = phase angle of 𝑋(𝑒 𝑗𝜔 )

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.

2. Create a new script file.


Click Home → New Script (or press Ctrl + N).

7|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

3. Enter the given MATLAB code in the script editor.

4. Save the script with a suitable filename, such as:


dtft_spectrum.m

5. Run the program using the Run button or press F5.

6. Observe the outputs:

o The first plot shows the Magnitude Spectrum.

o The second plot shows the Phase Spectrum.

7. Analyze how the magnitude and phase vary with frequency 𝜔.

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;

8|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

% Plot Phase Spectrum


subplot(2,1,2);
plot(omega/pi, angle(X), 'LineWidth', 1.5);
xlabel('\omega/\pi');
ylabel('\angle X(e^{j\omega})');
title('Phase Spectrum');
grid on;

Result:
The magnitude and phase spectra of the given discrete-time signal were successfully computed and plotted
using MATLAB.

9|P ag e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

Frequency analysis of discrete time systems using DTFT

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:

 𝐻(𝑒 𝑗𝜔 )→ Frequency response of the system

 ∣ 𝐻(𝑒 𝑗𝜔 ) ∣→ Magnitude response

 ∠𝐻(𝑒 𝑗𝜔 )→ Phase response

 𝜔→ Digital frequency (radians/sample)

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.

10 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

6. Observe the outputs in the figure window:

 The first subplot shows the magnitude response of the system.

 The second subplot shows the phase response of the system.

7. Analyze the plots:

 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;

11 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Result:
The magnitude and phase response of the discrete-time system with impulse response

ℎ[𝑛] = (0.9)𝑛 𝑢[𝑛]were successfully computed and plotted using MATLAB.

12 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

Discrete Fourier transform (DFT) and properties

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

𝑋[𝑘] = ∑ 𝑥[𝑛] ⋅ 𝑒 −𝑗2𝜋𝑘𝑛/𝑁 , 𝑘 = 0,1, . . . , 𝑁 − 1


𝑛=0

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:

𝑥[(𝑛 − 𝑚) 𝑚𝑜𝑑 𝑁] ↔ 𝑋[𝑘]𝑒 −𝑗2𝜋𝑘𝑚/𝑁

3. Conjugate Symmetry: For real sequences, 𝑋[𝑁 − 𝑘] = conj(𝑋[𝑘]).


4. Parseval’s Theorem: Energy in time domain equals energy in frequency domain:

13 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

𝑁−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𝜋𝑘𝑚/𝑁

8. Conjugate Symmetry Property:


 For real sequences, check 𝑋[𝑁 − 𝑘] = conj(𝑋[𝑘]).
9. Parseval’s Theorem:
 Compute energy in time domain: sum(abs(x).^2)
 Compute energy in frequency domain: sum(abs(X).^2)/N
 Compare both to verify equality.
10. Observe and Analyze:
 Examine plots and numerical results to confirm all properties.
MATLAB Program:

clc; clear all; close all;

14 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

x = input('Enter the sequence as a vector: ');


N = length(x);
% DFT
X = zeros(1,N);
for k=0:N-1
for n=0:N-1
X(k+1) = X(k+1) + x(n+1)*exp(-1j*2*pi*k*n/N);
end
end
% IDFT
x_reconstructed = zeros(1,N);
for n=0:N-1
for k=0:N-1
x_reconstructed(n+1) = x_reconstructed(n+1) + X(k+1)*exp(1j*2*pi*k*n/N);
end
x_reconstructed(n+1) = x_reconstructed(n+1)/N;
end
disp('DFT X[k]:'); disp(X);
disp('Reconstructed x[n] using IDFT:'); disp(x_reconstructed);
% Plots
figure;
subplot(3,1,1); stem(0:N-1,x,'filled'); title('x[n]'); xlabel('n'); ylabel('x[n]'); grid on;
subplot(3,1,2); stem(0:N-1,abs(X),'filled'); title('|X[k]|'); xlabel('k'); ylabel('|X[k]|'); grid on;
subplot(3,1,3); stem(0:N-1,real(x_reconstructed),'filled'); title('IDFT of x[n]'); xlabel('n'); ylabel('x[n]'); grid
on;
% Property 1: Linearity
y = input('Enter another sequence of same length: ');
a = input('Enter scalar a: ');
b = input('Enter scalar b: ');
DFT_linear = a*X + b*fft(y);
DFT_combined = fft(a*x + b*y);
disp('Linearity Check:'); disp(DFT_linear); disp(DFT_combined);
% Property 2: Circular Time Shift

15 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

m = input('Enter circular shift m: ');


X_shifted = X.*exp(-1j*2*pi*(0:N-1)*m/N);
x_shifted = circshift(x,[0 m]);
DFT_shifted = fft(x_shifted);
disp('Circular Time Shift:'); disp(DFT_shifted); disp(X_shifted);
% Property 3: Conjugate Symmetry
if isreal(x)
disp('Conjugate Symmetry Check:');
for k=1:N-1
fprintf('X[%d] = %f + %fi, X[%d] = %f + %fi\n', k, real(X(k+1)), imag(X(k+1)), N-k, real(X(N-k+1)),
imag(X(N-k+1)));
end
end
% Property 4: Parseval's Theorem
time_energy = sum(abs(x).^2);
freq_energy = sum(abs(X).^2)/N;
disp('Parseval''s Theorem:'); disp(time_energy); disp(freq_energy);

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.

16 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

FIR filter design.

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𝑓𝑠
𝜔𝑝 = , 𝜔𝑠 =
𝑓𝑠 𝑎𝑚𝑝 𝑓𝑠 𝑎𝑚𝑝

Filter Order Calculation:

17 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

−20log⁡10 (√𝑅𝑝 𝑅𝑠 ) − 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;

18 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

ws = 2*fs/f;

% Filter order calculation


num = -20*log10(sqrt(rp*rs)) - 13;
dem = 14.6*(fs-fp)/f;
n = ceil(num/dem);
n1 = n+1;
if(rem(n,2)~=0)
n1 = n; n = n-1;
end

% 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

19 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

b = fir1(n, wp, 'high', y);


[h,o] = freqz(b,1,256);
m = 20*log10(abs(h));
subplot(2,2,2); plot(o/pi, m);
title('HPF'); ylabel('Gain in dB'); xlabel('Normalized frequency');

% 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.

20 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

IIR filter design.

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𝑓𝑠
𝜔𝑝 = , 𝜔𝑠 =
𝑓𝑠 𝑓𝑠

Filter Design Steps:


1. Determine the minimum filter order 𝑛using buttord.
2. Design the Butterworth filter using butter.

21 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

3. Compute the frequency response using freqs.


4. Plot magnitude (in dB) and phase (in radians).

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: ');

22 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

% Normalized frequencies
w1 = 2*wp/fs;
w2 = 2*ws/fs;

% Filter order and cutoff


[n, wn] = buttord(w1, w2, rp, rs, 's');

% Filter type selection


c = input('Enter choice of filter 1. LPF 2. HPF: ');
if(c == 1)
disp('Frequency response of IIR LPF is:');
[b, a] = butter(n, wn, 'low', 's');
elseif(c == 2)
disp('Frequency response of IIR HPF is:');
[b, a] = butter(n, wn, 'high', 's');
end

% Frequency response
w = 0:0.01:pi;
[h, om] = freqs(b, a, w);
m = 20*log10(abs(h));
an = angle(h);

% Plot magnitude and phase


figure;
subplot(2,1,1); plot(om/pi, m);
title('Magnitude Response of IIR Filter');
xlabel('Normalized Frequency'); ylabel('Gain in dB');

subplot(2,1,2); plot(om/pi, an);


title('Phase Response of IIR Filter');
xlabel('Normalized Frequency'); ylabel('Phase in Radians');

23 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

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.

24 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

Study of TMS320C6478 DSK and code composer studio.


AIM:
 To study the architecture and features of the TMS320C6478 Digital Signal Processor (DSK).
 To understand the functionality of its multicore architecture and peripheral interfaces.
 To familiarize with real-time processing capabilities and practical applications of the DSK.

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:

25 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

 Audio and video processing systems


 Software-defined radio (SDR) and communication systems
 Image processing and radar signal processing
 Embedded control in industrial automation
 Scientific and engineering computations requiring high-speed DSP
Architecture Overview:
 VLIW cores: Each core executes multiple instructions in parallel.
 Shared memory: Efficient data transfer between cores.
 Peripheral support: Easy interface with ADC/DACs, sensors, and external memory.

2. Code Composer Studio (CCS)


Code Composer Studio (CCS) is an integrated development environment (IDE) for Texas Instruments DSPs.
It provides tools for writing, building, debugging, and optimizing DSP applications.
Features:
 Code editor with syntax highlighting and auto-completion
 Project management and build system
 Debugging tools: breakpoints, step execution, real-time variable monitoring
 Memory and register inspection
 Profiling and performance optimization tools
Workflow:
1. Write DSP code in C or Assembly.
2. Compile and build the project.
3. Load the program to the TMS320C6478 DSK.
4. Execute and debug programs in real-time.
5. Monitor outputs, memory, and processor activity.

Software/Hardware Required
 TMS320C6478 DSK board
 Code Composer Studio (CCS)
 USB or Ethernet connection to the DSK
 Power supply for the DSK board

26 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

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.

27 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

Experiment No.: Date:

Sinusoidal waveform generation.


AIM:
 To generate a sinusoidal waveform using a digital signal processor.
 To familiarize with Code Composer Studio (CCS) for DSP programming.
 To observe the waveform output and understand sampling and frequency generation using 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

28 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

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;

for(n = 0; n < N; n++)


{
x = AMPL * sin(2 * PI * FREQ * n / Fs); // Discrete sinusoid
// Output x to DAC or GPIO
printf("Sample %d: %f\n", n, x);

29 | P a g e Avanthi’s Research and Technological Academy


Digital Signal Processing Department of ECE

}
}

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.

30 | P a g e Avanthi’s Research and Technological Academy

You might also like