how to write a function that outputs even and odd components of a signal.

조회 수: 48 (최근 30일)
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
Walter Roberson
Walter Roberson 2019년 9월 6일
When I read the question, it is sloppy enough that I suspect the solution being looked for is:
  1. 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
  2. set xe to x([2 4 6 8 ....]) and xo to x([1 3 5 7 9 ...])
David Goodmanson
David Goodmanson 2019년 9월 6일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Nishant Gupta
Nishant Gupta 2019년 9월 9일
Hi Christian,
As you have not mentioned any input vector, so I am assuming the input as a random vector and the function created is as follows:
t=-10:10; %vector time
x=rand(1,numel(t)); % Your signal
components(t,x);
%function to output even and odd component
function [xe,xo] = components(t,x)
x_reverse = fliplr(x);% time reversal
xe = 0.5*(x + x_reverse); %even component
xo = 0.5*(x - x_reverse); %odd component
subplot(3,1,1);
plot(t,x);
title('Your signal x')
subplot(3,1,2);
plot(t,xe);
title('Even part');
subplot(3,1,3);
plot(t,xo);
title('Odd part');
end

추가 답변 (1개)

Rakesh Paritala
Rakesh Paritala 2020년 1월 27일
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');

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by