0% found this document useful (0 votes)
2 views

assignment

The document contains MATLAB code snippets for various signal processing tasks, including folding, delaying, shifting, and transforming signals. It also demonstrates the concepts of even and odd components of signals, as well as the relationship between delta and unit step functions. Additionally, it calculates energy for original, even, and odd signals.

Uploaded by

talahbilal66
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)
2 views

assignment

The document contains MATLAB code snippets for various signal processing tasks, including folding, delaying, shifting, and transforming signals. It also demonstrates the concepts of even and odd components of signals, as well as the relationship between delta and unit step functions. Additionally, it calculates energy for original, even, and odd signals.

Uploaded by

talahbilal66
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/ 8

Q.

3 Code
n = -5:5;
x = (1 + n/3) .* (-3 <= n & n <= -1) + (1) .* (0 <= n & n <= 3);

subplot(3,2,1)
stem(n,x)
title('Original Signal x(n)')

x_folded = fliplr(x);
n_folded = -fliplr(n);
subplot(3,2,2)
stem(n_folded,x_folded)
title('Folded Signal x(-n)')

x_folded_delayed = [zeros(1,4), x_folded(1:end-4)];


n_folded_delayed = n_folded + 4;
subplot(3,2,3)
stem(n_folded_delayed,x_folded_delayed)
title('Folded then Delayed x(-n-4)')

x_delayed = [zeros(1,4), x(1:end-4)];


n_delayed = n + 4;
x_delayed_folded = fliplr(x_delayed);
n_delayed_folded = -fliplr(n_delayed);
subplot(3,2,4)
stem(n_delayed_folded,x_delayed_folded)
title('Delayed then Folded x(-(n-4))')

n_transformed = -n + 4;
x_transformed = (1 + n_transformed/3) .* (-3 <= n_transformed & n_transformed <= -1) + (1)
.* (0 <= n_transformed & n_transformed <= 3);
subplot(3,2,5)
stem(n_transformed,x_transformed)
title('Transformed x(-n+4)')
Q.4 code
n = -3:6;
x = (n >= -2 & n <= 2) + 0.5*(n == 3 | n == 4);

subplot(4,2,1)
stem(n,x)
title('Original Signal x(n)')

x_shifted = (n-2 >= -2 & n-2 <= 2) + 0.5*(n-2 == 3 | n-2 == 4);


subplot(4,2,2)
stem(n,x_shifted)
title('Shifted x(n-2)')

x_flipped_shifted = (4-n >= -2 & 4-n <= 2) + 0.5*(4-n == 3 | 4-n == 4);


subplot(4,2,3)
stem(n,x_flipped_shifted)
title('Flipped and Shifted x(4-n)')

x_advanced = (n+2 >= -2 & n+2 <= 2) + 0.5*(n+2 == 3 | n+2 == 4);


subplot(4,2,4)
stem(n,x_advanced)
title('Advanced x(n+2)')

x_windowed = x .* (n <= 2);


subplot(4,2,5)
stem(n,x_windowed)
title('Windowed x(n)u(2-n)')

x_delta = x .* (n-1 == 3);


subplot(4,2,6)
stem(n,x_delta)
title('x(n-1)δ(n-3)')

x_squared = (n.^2 >= -2 & n.^2 <= 2) + 0.5*(n.^2 == 3 | n.^2 == 4);


subplot(4,2,7)
stem(n,x_squared)
title('Squared x(n^2)')

x_even = 0.5*(x + fliplr(x));


subplot(4,2,8)
stem(n,x_even)
title('Even part of x(n)')

figure
x_odd = 0.5*(x - fliplr(x));
stem(n,x_odd)
title('Odd part of x(n)')
Q.5 code
n = -5:5;

delta = (n == 0);
u_n = (n >= 0);
u_n1 = (n >= 1);

lhs_a = delta;
rhs_a = u_n - u_n1;

subplot(2,1,1)
stem(n, lhs_a, 'r', 'filled')
hold on
stem(n, rhs_a, 'b')
title('\delta(n) = u(n) - u(n-1)')
legend('LHS: \delta(n)', 'RHS: u(n) - u(n-1)')
hold off

rhs_b = zeros(size(n));
for k = 0:5
rhs_b = rhs_b + (n == k);
end

subplot(2,1,2)
stem(n, u_n, 'r', 'filled')
hold on
stem(n, rhs_b, 'b')
title('u(n) = sum_{k=0}^{\infty} \delta(n-k)')
legend('LHS: u(n)', 'RHS: Summation of \delta(n-k)')
Q.6 code
x = [2 3 4 5 6];
n = -2:2;
x_rev = fliplr(x);
x_even = 0.5 * (x + x_rev);
x_odd = 0.5 * (x - x_rev);
E_x = sum(x.^2);
E_even = sum(x_even.^2);
E_odd = sum(x_odd.^2);
disp([E_x, E_even + E_odd])

Ex=90

You might also like