Hello Abdullah
be aware that what you are calling alpha is often called alpha/2, but I don't think that had anything to do with the problem you are having. I stayed with your definition of alpha.
Everything appears to be fine up until the width calculation. I don't know whether you intended that w denote circular frequency, but in this case it is (regular) frequency. To avoid ambiguity I went with frequency and did not use circular frequency. The code below finds the widths and the resulting Q.
clc
close all
fs= 10000;
t = (0:1/fs:(1-(1/fs)));
f= 4000;
alpha= (f*pi)/500;
y = 10*exp(-alpha*t).*sin(2*pi*f*t);
figure(1)
plot(t,y); grid on
Q0 = pi*f/alpha
N1=10000;
S =fft(y,N1);
F1=S(1:N1/2);
PF1=2*F1.*conj(F1)/(fs*N1);
LPF1=10*log10(PF1);
LP=LPF1(1:N1/2);
fvec=fs*(1:N1/2)/N1;
figure(2)
plot(fvec,LP); grid on
xlim([3990 4010])
[LPmax ind0] = max(LP);
LPhalf = LPmax - 10*log10(2);
indx = find(LP>LPhalf);
ind1 = [indx(1)-5:ind0];
f1 = interp1(LP(ind1),fvec(ind1),LPhalf,'spline');
ind2 = [ind0:indx(end)+5];
f2 = interp1(LP(ind2),fvec(ind2),LPhalf,'spline');
Q = f/(f2-f1)
Q0 = 500.0000
Q = 499.9917
Best Answer