Finding Zero Crossing of Signal
4 views (last 30 days)
Show older comments
Hello Everyone..
I am sharing the code for which i need to find zero crossing. Though i tried aloy but ould not fix it. Its all working but i need to find the Zero crossing points for signal DA3 in it.
Thanks in advance
Rf = 40e3; Cf = 680e-15;
R2 = 16e3;
R1 = 16e3;
wu = 1 / ((R1 * Rf / (R1 + Rf)) * Cf);
R1da1=1.35e3/2; %CHANGE FROM PAPER e3/2
R2da1=6.26e3/2;
fda1lp=150e6;%changed from 6 to 5
tau1da1=1/(2*pi*fda1lp);
%%% DA2 Parameters %%% %%%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%%
R1da2=2.43e3/2;
R2da2=6.26e3/2;
C1da2=84e-12;
%%% DA3 Parameters %%% %%%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%% %%%
R1da3=2.45e3/2;
R2da3=9.77e3/2;
C1da3=92e-12;
T = 30 / wu;
N = 100;
time = 1: 1: N;
time=T*time/N;
Q = 5e-15;
QTIME = 4e-9; % Max 11ns
I= Q / QTIME;
to1=1e-9;
to2=to1+QTIME;
syms s;
X1s = (exp (-s * to1)) * 1 / s- (exp (-s * to2)) * (1 / s);
I = Q / QTIME;
ip = I * X1s;
%%%%%%%%%%%%%%%%%%%%%%%%% Time Domain DA1-DA3 %%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%
syms gda1 t1da1 ;
tf_da1 = gda1 / (1 + s * t1da1);
tf = subs (tf_da1, {gda1, t1da1}, {R2da1 / R1da1, tau1da1});
pretty (tf);
%%%%% DA2 Transfer Function %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%
syms r1da2 r2da2 c1da2;
tf_da2=(r2da2/r1da2)*(1+s*c1da2*2*r1da2)/(1+s*c1da2*r1da2);
tf_da2=tf_da2./(1+s/(2*pi*150e6));
tf2=subs(tf_da2,{r1da2,r2da2,c1da2},{R1da2,R2da2,C1da2});
pretty(tf2);
syms r1da3 r2da3 c1da3;
tf_da3=s*c1da3*r2da3/(1+s*c1da3*r1da3);
tf_da3=0.1+tf_da3./(1+s/(2*pi*150e6));
tf3=subs(tf_da3,{r1da3,r2da3,c1da3},{R1da3,R2da3,C1da3});
pretty(tf3);
%%%%%%%%%%% Time Domain DA1 %%%%%%%%%%%
syms t ;
da1 = ip * tf;
DA11 = ilaplace (da1);
da1t = subs (DA11, {t}, {time});
%%%%%%%%%%% Time Domain DA2 %%%%%%%%%%%
da2 = da1 * tf2;
da2s = ilaplace (da2);
da2t = subs (da2s, {t}, {time});
%%%%%%%%%%% Time Domain DA3 %%%%%%%%%%%
da3 = da2 * tf3;
da3s = ilaplace (da3);
da3t = subs (da3s, {t}, {time}); % zerocrossing for this signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%
close all
figure;
plot (time * 1e9, da3t, '-k' , 'LineWidth' , 2);
xlabel ( 'Time - [ns]' ); ylabel ( 'Amplitude - [V]' );
title ( 'DA Transient Output' );
hold on
grid on
legend ( 'DA1' , 'DA2' , 'DA3' );
3 Comments
Star Strider
on 12 Apr 2020
Unrecognized function or variable 's'.
Error in
x1s=(exp(-s*to1))*1/s-(exp(-s*to2))*(1/s);
That occurs in the 15th line.
I have been doing my best to help you since you began posting this problem. I will stop if you want to post a different problem.
Answers (1)
Star Strider
on 12 Apr 2020
The end of your code now becomes:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%
close all
figure;
zci = @(v) find(v(:).*circshift(v(:), [1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
da3td = double(da3t);
idx = zci(da3td);
if da3td(1) * da3td(end) < 0
idx = idx(2:end);
end
for k = 1:numel(idx)
t_exact(k) = interp1(da3td(idx(k))+[-1 +1]*1E-5, time(idx(k))*1E9+[-1 +1], 0);
end
plot (time * 1e9, da3t, '-k' , 'LineWidth' , 2);
hold on
plot(time(idx)*1E9, da3td(idx), 'r+')
hold off
xlabel ( 'Time - [ns]' ); ylabel ( 'Amplitude - [V]' );
title ( 'DA Transient Output' );
hold on
grid on
legend ( 'DA1' , 'DA2' , 'DA3' );
text(t_exact, 0, sprintf('\\downarrow time = %.4f',t_exact), 'HorizontalAlignment','left', 'VerticalAlignment','bottom')
You can eliminate plotting the red ‘+’ if you want.
.
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!