Asked by s0ter48
on 9 Jul 2019

Hey guys,

I have an measurement of three sinusoidal signals.

But it is enough to only work with one in this case.

The measurement doesn´t have an int number of periods and i need to cut for my further work.

To make it more clear here is an picutre:

In this case we have 4 periods.

So i have to find the first negative to positive zero corssing and the last negative to positive zero crossing.

I found this code in the forum but it don´t work with my files but maby it can help u ?!

t = linspace(0,10*pi,200);

x = sin(t);

mcs = x .* circshift(x, [0 -1]);

zxix = find(mcs <= 0);

for k1 = 1:2:size(zxix,2)-1

zx(k1) = interp1(x(zxix(k1):zxix(k1)+1), t(zxix(k1):zxix(k1)+1), 0);

end

figure(1)

plot(t, x)

hold on

plot(zx, zeros(size(zx)), '+r', 'MarkerSize',10)

hold off

grid

I hope u can help me.

Thanks in advance

Answer by David Sanchez
on 9 Jul 2019

Accepted Answer

Hi,

bear in mind that the sampling of your curve might play an important role in the game.

The code below might help you out:

t = linspace(0,10*pi,200);

x = sin(t);

zero_crossings_pos = [];

for kind = 1:length(t)-1

if (x(kind) <= 0) && (x(kind+1) > 0)

zero_crossings_pos = [zero_crossings_pos kind];

end

end

figure,

plot(t,x,t,x,'o')

hold on

plot(t(zero_crossings_pos),x(zero_crossings_pos),'r*')

hold off

xlabel('x')

ylabel('sin(x)')

title('sin')

t_crop = t(zero_crossings_pos(2):zero_crossings_pos(5));

x_crop = x(zero_crossings_pos(2):zero_crossings_pos(5));

figure,

plot(t_crop,x_crop)

xlabel('x')

ylabel('sin(x)')

title('Cropped sin')

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## s0ter48 (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/470828-cut-sinusoidal-signal-in-a-integer-number-of-periods#comment_722704

## s0ter48 (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/470828-cut-sinusoidal-signal-in-a-integer-number-of-periods#comment_722707

Sign in to comment.