How to add 0 values before and after a sine wave ?

Hi,
I have created a sine wave as follow:
Fs=2000;
t=0:1/Fs:1-1/Fs
f0=100;
y=sin(2*pi*f0*t)
Now, I would like to add 10 points with their value = 0 just before and after this sine wave. How could I do that ?
Thanks in advance!

2 Comments

Does that mean there will be 10 inserted points prior to the first value, then 20 inserted points between each cycle, and then 10 inserted points at the end?
Ok, but I have the same quesiton. If you add 10 points before AND after each cycle, then you're adding 20 points between each cycle. Is that what you want?

Sign in to comment.

 Accepted Answer

It's not exactly clear what you're asking for but here are two solutions.
If you just want to add 10 points to the beginning and end of your entire signal
% number of elements to insert
nAdded = 10;
% value to use as filler
filler = 0;
% insert the values
fillVec = repmat(filler, 1, nAdded);
expandedY = [fillVec, y, fillVec]; %Here's your new vector
If you want to add 10 points between each cycle of the sine curve including the beginning and end
% number of elements to insert
nAdded = 10;
% value to use as filler
filler = 0;
% lenght of 1 period (number of indices)
pdLength = length(y)/f0;
% insertion indices
origIdx = pdLength : pdLength : length(y); %indices of y
expandedIdx = origIdx + cumsum(repmat(nAdded,1,length(origIdx))); %indices of expanded y
origIdx = [0, origIdx];
expandedIdx = [0, expandedIdx];
% create new vector
expandedY = repmat(filler, 1, length(y) + f0*nAdded+nAdded); %expanded y value
for i = 1 : length(expandedIdx)-1
expandedY(expandedIdx(i)+nAdded+1 : expandedIdx(i+1)) = y(origIdx(i)+1 : origIdx(i+1));
end

More Answers (0)

Categories

Asked:

yj
on 10 Jan 2019

Commented:

on 10 Jan 2019

Community Treasure Hunt

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

Start Hunting!