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

7 views (last 30 days)
SimTec on 20 Jan 2020
Commented: SimTec on 20 Jan 2020
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

Guillaume on 20 Jan 2020
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.
SimTec on 20 Jan 2020
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 on 20 Jan 2020
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!