Effacer les filtres
Effacer les filtres

Even & Odd Discrete time Signals

56 vues (au cours des 30 derniers jours)
Tauqir Hassan
Tauqir Hassan le 10 Fév 2019
Réponse apportée : Paul le 9 Juin 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 commentaires
ANAND AMAR
ANAND AMAR le 11 Oct 2020
Error in (line 3)
xe= ( x(n)+x(-n) )/2;
tanishq katre
tanishq katre le 2 Sep 2021
qki tu gadha hai

Connectez-vous pour commenter.

Réponses (3)

S. Sukkrishvar Vijay
S. Sukkrishvar Vijay le 31 Juil 2020
n + (-1)^n

Hafiz
Hafiz le 9 Juin 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 le 9 Juin 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

Catégories

En savoir plus sur Signal Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by