DSPlab 1&2
DSPlab 1&2
Sr.
List of Experiments
No
a) Program for computing auto correlation of two finite length sequences and obtain the
energy of the input sequence.
3 b) Program for computing cross correlation of two finite length sequences and using it to
find the delay between signals.
Using C/ Python and MATLAB
a) Implementation of Low Pass and High Pass FIR filter for a given sequence
5 b) Implementation of Low Pass and High Pass IIR filter for a given sequence
Using C/ Python and MATLAB
Noise removal: Add noise above 3kHz and then remove; Interference Suppression using
12
400 Hz Tone using TMS320 C6748 DSP Processor.
EXPERIMENT 1(a)
Software: MATLAB
Code:
n = 0:20;
f= 0.1;
x_sine = sin(2*pi*f*n);
n_impulse = -10:10;
x_impulse = (n_impulse == 0);
a = 0.8;
x_exp = a.^n;
n_unit = -10:10;
x_unit = (n_unit >= 0);
T = 5;
x_sawtooth = mod(n, T);
figure;
subplot(3,2,1);
stem(n, x_sine);
xlabel('n');
ylabel('Amplitude');
title('Discrete Sine Signal');
grid on;
subplot(3,2,2);
stem(n_impulse, x_impulse);
xlabel('n');
ylabel('Amplitude');
title('Discrete Impulse Signal');
grid on;
subplot(3,2,3);
stem(n, x_exp);
xlabel('n');
ylabel('Amplitude');
title('Discrete Exponential Signal');
grid on;
subplot(3,2,4);
stem(n_unit, x_unit);
xlabel('n');
ylabel('Amplitude');
title('Discrete Unit Step Signal');
grid on;
subplot(3,2,5);
stem(n, x_sawtooth);
xlabel('n');
ylabel('Amplitude');
title('Discrete Sawtooth Signal');
grid on;
sgtitle('Basic Discrete Signals');
Output:
Observation:
Upon generating the signals:
1. Discrete Sine Signal: The sine signal oscillates periodically with a specific frequency, displaying
smooth periodic behavior.
2. Discrete Impulse Signal: The impulse signal has a value of 1 at n=0n = 0n=0 and 0 elsewhere,
acting as a basic building block in signal processing.
3. Discrete Exponential Signal: The exponential signal grows or decays depending on the
exponential rate aaa, demonstrating either an increasing or decreasing trend.
4. Discrete Unit Step Signal: The unit step signal stays at 0 for n<0n < 0n<0 and steps to 1 at n=0n
= 0n=0 and beyond, commonly used in control systems.
5. Discrete Sawtooth Signal: The sawtooth signal increases linearly and resets periodically,
representing a non-sinusoidal waveform used in various applications.
Conclusion:
The discrete signals were successfully generated and visualized, highlighting their distinct behaviors. These
signals are fundamental in various engineering fields, including signal processing and digital
communication.
EXPERIMENT 1(b)
Software: MATLAB
Code:
A = 1;
f = 5;
T = 1;
t = 0:0.001:T;
y = A * sin(2 * pi * f * t);
figure;
subplot(4, 1, 1);
plot(t, y, 'b');
title('Continuous Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4, 1, 2);
stem(t_sampled1, y_sampled1, 'r');
title('Sampled Sine Wave (fs > 2 * f)');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4, 1, 3);
stem(t_sampled2, y_sampled2, 'g');
title('Sampled Sine Wave (fs = 2 * f)');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4, 1, 4);
stem(t_sampled3, y_sampled3, 'm');
title('Sampled Sine Wave (fs < 2 * f)');
xlabel('Time (s)');
ylabel('Amplitude');
Output:
Observation:
When the sampling frequency is much higher than twice the signal frequency (fs > 2 * f), the sampled signal
closely follows the original wave, ensuring accurate representation. At the Nyquist rate (fs = 2 * f), the
signal is still accurately captured with minimal data points. However, when the sampling frequency is less
than twice the signal frequency (fs < 2 * f), aliasing occurs, leading to a distorted and inaccurate
representation of the original signal.
Conclusion:
We need to choose an appropriate sampling rate to avoid errors and preserve the quality of the signal.
EXPERIMENT 2(a)
AIM: Obtain Linear Convolution of two finite length sequences and verify the properties of linear
convolution
Software: MATLAB
Code:
%LINEAR CONVOLUTION
%WITHOUT USING FUNCTION
x = [7, 5, 6, 1];
h = [8, 4, 1, 6];
g = [2, 3, 5, 0];
Nx = length(x);
Nh = length(h);
Ny = Nx + Nh - 1;
y = zeros(1, Ny);
for n = 1:Ny
for k = 1:Nx
if (n - k + 1 > 0) && (n - k + 1 <= Nh)
y(n) = y(n) + x(k) * h(n - k + 1);
end
end
end
%WITH CONVOLUTION FUNCTION
z = conv(x,h);
%ASSOCIATIVE PROPERTY
xh = conv(x,h);
y1 = conv(xh,g);
hg = conv(h,g);
y2 = conv(hg,x);
disp('(x[n] * h[n]) * g[n]=');
disp(y1);
disp('x[n] * (h[n] * g[n])=');
disp(y2);
if isequal(y1, y2)
disp('Associative property is proved');
else
disp('Associative property is not proved.');
end
%COMMUTATIVE PROPERTY
hx = conv(h,x);
disp('x[n] * h[n]=');
disp(xh);
disp('h[n] * x[n]=');
disp(hx);
if isequal(xh, hx)
disp('Commutative property is proved');
else
disp('Commutative property is not proved.');
end
%DISTRIBUTIVE PROPERTY
hg = h + g;
y3 = conv(x, hg);
xg = conv(x, g);
y4 = xh + xg;
disp('Result of x[n] * (h[n] + g[n])=');
disp(y3);
disp('Result of x[n] * h[n] + x[n] * g[n]=');
disp(y4);
if isequal(y3, y4)
disp('Distributive property is proved: x[n] * (h[n] + g[n]) = x[n] * h[n] + x[n] * g[n]');
else
disp('Distributive property is not proved.');
end
Output:
(x[n] * h[n]) * g[n]=
112 304 634 723 692 589 323 203 30 0
h[n] * x[n]=
56 68 75 79 40 37 6
Observation:
The convolution of x[n] and h[n] using MATLAB's conv function produces a sequence that represents the
linear combination of the input sequences. The result is consistent with the expected length, Nx + Nh - 1,
and correctly represents the overlapping and shifting of the two sequences.
Conclusion:
MATLAB's conv function accurately performs linear convolution and upholds the associative,
commutative, and distributive properties.
EXPERIMENT 2(b)
AIM: Obtain Circular Convolution of two finite length sequences using FFT method
Software: MATLAB
Code:
x = [7, 5, 6, 1];
h = [8, 4, 1, 6];
N = max(length(x), length(h));
X = fft(x_padded);
H = fft(h_padded);
Y = X .* H;
y_circular = ifft(Y);
Output:
Circular Convolution result using FFT:
96 105 81 79
Observation:
The output sequence y_circular represents the circular convolution of the two input sequences, and it
matches what is expected based on the theory of circular convolution.
Conclusion:
The circular convolution of two sequences was efficiently calculated using the FFT method in MATLAB.
This technique utilizes FFT and inverse FFT for fast computation, making it ideal for tasks involving
periodic signal processing.