Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab solution for finding specific position when a sign change occurs inside vector

Status
Not open for further replies.

Andrew8611

Member level 1
Joined
Mar 16, 2006
Messages
37
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,557
Does anybody knows a command in Matlab that lets me find the specific position when a sign change occurs inside a vector??
for example, I wrote t=0:0.01:10000 and then I wrote y=sin(t), which command lets me see the position on the vector y where it changes from positive to negative or from negative to positive?????
 

Help with matlab

I don't know whether there is a command to find the position that sign changes.
But we can write that function ourselves. I think that is not complex. we can check each y in a loop, if y(n)>0 && y(n+1)<=0 or y(n)<0 && y(n+1)>=0, then the sign change occurs at n. and then continue to check the remainder of y. At the end of loop, all the position of sign change are finded.

Ryan
 

Help with matlab

Maybe this small example will help you. It generates a sinewave frequency sweep, and then plots and tabulates the waveform's positive-slope zero-crossing points.
Code:
% Frequency sweep
F0 = 10;        % start frequency, Hertz
F1 = 100;       % stop frequency, Hertz
T  = 0.5;       % duration, seconds
FS = 1000;      % sample rate, Hertz
N = round(T * FS);
t = T * (0:N-1)' / (N-1);
y = sin(2 * pi * (F0 + (F1 - F0) / 2 .* t / T) .* t);
subplot(2,1,1); plot(t, y); xlabel('seconds');
%
% Positive-slope zero-crossing detector
z = and((y > 0), not(circshift((y > 0), 1)));  z(1) = 0;
subplot(2,1,2); plot(t, z); xlabel('seconds');
%
% Find the locations of the zero-crossing points
crossing_points = find(z);
To detect both positive and negative crossings, change the logic line to this:
z = xor((y > 0), circshift((y > 0), 1)); z(1) = 0;

I prefer using array methods like that because MATLAB executes them much faster than a "for" loop.
 
require matlab code for zerocrossing detector

hi i'm in need to simulate the zero crossing detector with sinewave as input.. and then convolute the result with sine wave .... can any one provide me the code for this....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top