how to write a function that outputs even and odd components of a signal.
Mostrar comentarios más antiguos
How to create a matlab function that has the following form: function [xe,xo] = components(t,x) which takes in the signal defined by the pair of vectors {t,x} and outputs both the even component of the signal with samples vector xe and the odd component of the signal with samples vector xo. Each output vector xe and xo are paired with the input vector t to form a signal. If the vectors t and x are not the same length, return an empty vector for xe and xo. If the length of t is less than 2, you should also return an empty vector for xe and xo. Thanks
6 comentarios
Walter Roberson
el 6 de Sept. de 2019
Christian Witte
el 6 de Sept. de 2019
Walter Roberson
el 6 de Sept. de 2019
In order to "return the empty vector" you need to assign something to the output variables xe and xo
Be careful: size(t) ~= size(x) would be an error if the two did not have the same number of dimensions.
I would normally tend to think that the "even" components of a signal are the ones at index 2, 4, 6, 8, and so on, but if that were the situation, it would not appear to make sense for there to be a t input. I do not understand about "Each output vector xe and xo are paired with the input vector t to form a signal." -- in order to do that, xe and xo would each have to be the same length as t, whereas we know that xe and xo are some kind of subsets of the inputs and the length of t must match the length of the x input. The question is also not clear as to what should be done if the lengths of t and x are odd. The bit about t needing to have at least two points would tend to suggest that the person who wrote the question was expecting only even lengths.
Christian Witte
el 6 de Sept. de 2019
Walter Roberson
el 6 de Sept. de 2019
When I read the question, it is sloppy enough that I suspect the solution being looked for is:
- Check the input conditions and return [] and [] for anything the question defines as being an error. No error messages should be issued -- not even if the number of dimensions of t and x are not the same
- set xe to x([2 4 6 8 ....]) and xo to x([1 3 5 7 9 ...])
David Goodmanson
el 6 de Sept. de 2019
Possibly what is intended is
xe = x(t) + x(-t)
xo = x(t) - x(-t)
although this is only going to work if the t matrix has an odd number of elements with t = 0 right in the middle.
Respuesta aceptada
Más respuestas (1)
Rakesh Paritala
el 27 de En. de 2020
clc;
clear all;
close all;
x=input("enter the values");
n=0:length(x)-1;
n1=(1-length(x))*0.5:(length(x)-1)*0.5;
y=flip(x);
y
x
x_e=(x+y)*0.5;
x_e
x_o=(x-y)*0.5;
x_o
subplot(311)
stem(n1,x);
title('ACTUAL SIGNAL');
subplot(312)
stem(n1,x_e);
title('EVEN SIGNAL');
subplot(313)
stem(n1,x_o);
title('ODD SIGNAL');
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!