Even & Odd Discrete time Signals

89 visualizaciones (últimos 30 días)
Tauqir Hassan
Tauqir Hassan el 10 de Feb. de 2019
Respondida: Paul el 9 de Jun. de 2024
I am writing a program to seperate, plot even and odd parts of a discrete time signal. Following is my code:
I am getting error at line 3 & 4. "Array indices must be positive integers or logical values."
Since I am trying to flip and invert the signal x[n] , so 'x(-n)' is obvious to use but I am getting error. Kindly help.
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel('n');ylabel('Amplitude');title('Original Signal');
subplot(312);stem(n,xe);grid on; xlabel('n');ylabel('Amplitude');title('Even Signal');
subplot(313);stem(n,xo);grid on; xlabel('n');ylabel('Amplitude');title('Odd Signal');
  2 comentarios
ANAND AMAR
ANAND AMAR el 11 de Oct. de 2020
Error in (line 3)
xe= ( x(n)+x(-n) )/2;
tanishq katre
tanishq katre el 2 de Sept. de 2021
qki tu gadha hai

Iniciar sesión para comentar.

Respuestas (3)

S. Sukkrishvar Vijay
S. Sukkrishvar Vijay el 31 de Jul. de 2020
n + (-1)^n

Hafiz
Hafiz el 9 de Jun. de 2024
n= -3:4;
x=[0 0 0 2 3 -1 2 -3];
xe= ( x(n)+x(-n) )/2;
xo= ( x(n)-x(-n) )/2;
subplot(311);stem(n,x);grid on; xlabel('n');ylabel('Amplitude');title('Original Signal');
subplot(312);stem(n,xe);grid on; xlabel('n');ylabel('Amplitude');title('Even Signal');
subplot(313);stem(n,xo);grid on; xlabel('n');ylabel('Amplitude');title('Odd Signal');

Paul
Paul el 9 de Jun. de 2024
Matlab doesn't support zero or negtaive indices, so it won't be possible to implement this operation using ordinary vector indexing.
One approach is to define a fucntion that returns elements of the signal x[n] for values of n. One option is to use an anonymous function.
Though not stated expliclty, it appears that x[n] = 0 for n < 0 and x[n] = 0 for n > 4.
x = @(n) (n == 0)*2 + (n == 1)*3 + (n == 2)*-1 + (n == 3)*2 + (n == 4)*-3;
n = -5:5;
tiledlayout(3,1);
nexttile,stem(n,x(n)),title('x[n]')
xe = (x(n) + x(-n))/2;
nexttile,stem(n,xe);title('xe[n]')
xo = (x(n) - x(-n))/2;
nexttile,stem(n,xo);title('xo[n]')
all(x(n) == xe + xo)
ans = logical
1

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by