how to select one first and second sample of a sampled signal?

조회 수: 5 (최근 30일)
SimTec
SimTec 2020년 1월 20일
댓글: SimTec 2020년 1월 20일
here I am trying to store and output separatly the first sample and second sample of sampled signal. example, I have a sinewave that I sample at Ts. the first sample I store it and output it sperately and the second sample I do same, then come the third and fourth smaples, and continues so one.
this is the function but I get same as input and no selection has been made
function [y1,y2] = select(u)
y_o1=0;
y_o2=0;
for i=1:2
disp(i)
if i==1
y_o1=u;
else
y_o2=u;
end
end
y1=y_o1;
y2=y_o2;
end

답변 (2개)

Guillaume
Guillaume 2020년 1월 20일
I'm not sure what you are trying to achieve with the code you have written, it doesn't make much sense I'm afraid.
The whole lot simplifies to:
function [y1, y2] = select(u)
y1 = u;
y2 = u;
end
which just copies u into two new variables. Not very useful.
However, I suspect you meant to do:
function [y1, y2] = select(u)
y1 = u(1); %get first element
y2 = u(2); %get second element
end
But even that is not very useful. There's no reason to create two new variables just to copy the first two elements of something. Wherever you were going to write y1, you can just write u(1) and not bother with the copy.
  댓글 수: 1
SimTec
SimTec 2020년 1월 20일
i did the for loop as i thought with samplig frequency, the for loop increment each sample time and select the nex sample and then output both at the same time

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


SimTec
SimTec 2020년 1월 20일
Hello Guillaume,
I am trying to samples first and second values of sampled signal in real time, becasue I want to feed it to half band FIR filter which has two inputs.
for example, I have this signal:x(n*Ts)=[0 2 5 7 9 11 15 11 9 7 5 2 0 -1]. with this function I want to select 0 and 2, then 5 and 7, then 9 and 11, then 15 and 11 in real time!

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by