MATLAB Answers

Approximate the first zero crossing of an exponentially decaying waveform.

2 views (last 30 days)
Ahmed Mohamed Mansoor
Ahmed Mohamed Mansoor on 14 Jul 2021
Answered: Yazan on 17 Jul 2021
Trying to answer this question. So part a and b has been accomplished. I am not able to do part c. Can anyone please help me with this.
function p = wave_fction
%q2b
y = 0.1;
t = linspace(0,20,12);
p = ((exp(-y.*t))/sqrt(1-y.^2)).*sin((atan(sqrt((1-y.*2)/y))+t*sqrt(1-y.^2)));
tt = 0:20;
yy = spline(t,p,tt);
figure (1)
plot(t,p,'o',tt,yy),xlabel('x-axis'),ylabel('y-axis')
title ('Spline1')
hold on
m = 0:20;
n = (m\0);
plot (m,n)
hold off
y = 0.1;
t = linspace(0,20,200);
p = ((exp(-y.*t))/sqrt(1-y.^2)).*sin((atan(sqrt((1-y.*2)/y))+t*sqrt(1-y.^2)));
tt = 0:20;
yy = spline(t,p,tt);
figure (2)
plot(t,p,'o',tt,yy),xlabel('x-axis'),ylabel('y-axis')
title ('Spline2')
hold on
m = 0:20;
n = (m\0);
plot (m,n)
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a = t;
b = p;
c = tt;
figure (3)
vq2 = interp1(a,b,c,'spline');
plot(a,b,'o',c,vq2,':.');
hold on
m = 0:20;
n = (m\0);
plot (m,n)
hold off
xlim([0 20]);
title('Interp1');
err= abs(((1.6794-2)/1.6794)*100)
This is what has been done so far. Please help me complete part (c ) of the question.

Answers (1)

Yazan
Yazan on 17 Jul 2021
Looking at the figures that your code produces, you can see clearly that the first zero-crossing is not around 1.6794 as your text suggests, so there is a problem somewhere. Anyways, you can interpolate the t-position of the first zero-crossing using the following.
% find index of first datapoint below zero
idx = find(p<0, 1, 'first');
% 15 query points
tt = linspace(t(idx-1), t(idx), 15);
% You can use any interpolation method you find fitting your problem
pq = interp1([t(idx-1), t(idx)], [p(idx-1), p(idx)], tt);
% find index of first datapoint below zero using interpolated signal
idx2 = find(pq<0, 1, 'first');
% take the midpoint between this point and its above-zero neighbor
tq = mean([tt(idx2-1); tt(idx2)]);

Community Treasure Hunt

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

Start Hunting!