Effacer les filtres
Effacer les filtres

Why I don't get a curve plot by adding term2 to phi?

2 vues (au cours des 30 derniers jours)
Shaily_T
Shaily_T le 4 Mar 2023
Modifié(e) : Shaily_T le 11 Mar 2023
Hey,
I have an issue where I am stucked for several days. I have the following code:
to run it you need to have the attached matlab file (matlab) on your computer. The issue I am encountering arise when I add 'term2' to 'phi' expression. Before adding it when I plot real and imaginary part of 'exp(-1i*phi)' I have a nice curve which seems reasonable. However, when I add 'term2' to the expression of 'phi' I end up with a plot which is mostly like a scatter thing rather than a curve which should not happen. I want to use 'exp(-1i*phi)' in another expression and having such plot when adding 'term2' to 'phi' is affecting the result badly. I am not sure if this issue originates from somewhere in the code or something else. I have attached the figures I get for real and imaginary part of 'exp(-1i*phi)' in this two situations. The two above ones is for having 'term2' and the two below ones is when removing 'term2' from 'phi' expression. I really appreciate your comments.
L= 0.00435001414404276;
c= 2.99792458E8;
sigma = 2.7E6;
center = 24075189.2672552;
numGaussians = 9;
CombF = c/(793.3863E-9);
Start = CombF+700E6;
End = CombF+900E6;
nu = linspace(Start-60E6, End+90E6, 12000);
gaussEqn1 = zeros(1, length(nu));
for k = 1 : numGaussians
if k==1
b = Start;
else
b = Start+(center * (k-1));
end
thisGaussian1 = 1*exp(-((nu-b).^2)/(2.*(sigma.^2)));
% Add into accumulator array:
gaussEqn1 = gaussEqn1 + thisGaussian1;
dcomb1 = gaussEqn1;
end
load matlab.mat dconst dY Real_nalpha
d = dY - dconst + dcomb1;
dnu =nu(2)-nu(1);
Dif=diff(Real_nalpha)/dnu;
nu = nu(1:length(nu)-1);
Real_nalpha = Real_nalpha(1:length(Real_nalpha)-1);
d = d(1:length(d)-1);
term2=(nu).*Dif;
phi=(4*pi.*(Real_nalpha+term2).*nu*L)/c;
plot(nu,real(exp(-1i*phi)))
hold on;
plot(nu,imag(exp(-1i*phi)))
which shows real part of 'exp(-1i*phi)' when adding term2 which shows imaginary art of 'exp(-1i*phi)' when adding term2
which shows real part of 'exp(-1i*phi)' when removing term2
which shows imaginary art of 'exp(-1i*phi)' when removing term2
I am not sure why I have the two above curves for the real and imaginary part of 'exp(-1i*phi)' when adding term2 in the expression for 'phi'.

Réponses (1)

William Rose
William Rose le 5 Mar 2023
Please post a question in the simplest possible form that will allow others to assist you.
In this case, you can make a matlab.mat file with the five variables you need. I did that, and I attached it. You could do likewise.
Then you can illustrate your unexpected result as follows:
load matlab.mat % load c, L, nu, Real_nalpha, term2
phi1=(4*pi.*(Real_nalpha).*nu*L)/c; % compute phi1
phi2=(4*pi.*(Real_nalpha+term2).*nu*L)/c; % compute phi2
Plot real and imaginary parts:
subplot(2,2,1); plot(nu,real(exp(-1i*phi1))); ylabel('Real'); title('Without term2')
subplot(2,2,3); plot(nu,imag(exp(-1i*phi1))); ylabel('Imag')
subplot(2,2,2); plot(nu,real(exp(-1i*phi2))); ylabel('Real'); title('With term2')
subplot(2,2,4); plot(nu,imag(exp(-1i*phi2))); ylabel('Imag')
You are suprised that the plots on the right are different from the plots on the left. They are different because term2 is a 1x11999 vector whose values are not constant. You used many lines of code to calculate term2. It is not surprising that term2 might vary. That variation makes phi2 vary, which produces the observed result.
If you are suprised that term2 changes, then review the formulas you used to calculate term2. Why would you NOT expect term2 to vary?
  6 commentaires
William Rose
William Rose le 7 Mar 2023
Modifié(e) : William Rose le 7 Mar 2023
[edit: Added a - sign in front of s*n_i in equaiton below. The - sign indicates attenuation when s is >0.]
I am guessing that your equations have to do with the phase ϕof a light wave after it travels a distance 2L through a medium with index of refraction n(nu). For a non-dispersive medium (i.e. n=constant), n is real, and a wave that starts with amplitude 1 will, after a distance 2L, be represented by , where , and s is a real number>0,. If the index of refraction, n, is a function of nu, then n will be complex. The real and imaginary parts of n(nu) are related by the K-K equations, also known as the HIlbert transform. Now the wave is represented by , where . Now it is clear that the imaginary part causes attenuation, because , where the first term, involving , is a real number between 0 and 1 and indicates attenuation.
You wrote that term2 is derived from the real part, using the K-K relationship. But if that is true, then it should ne the imaginary part of n. But according to your equaiton for the phase, term2 is not the imaginary part of n. Is that a possible error?
I am out of my league here. Maybe my understanding of phase angles and index of refraction is wrong.
William Rose
William Rose le 7 Mar 2023
You said "I am sure there is not a problem with the calculation of "Real_nalpha"." You provided Real_nalpha in the file matlab.mat. I renamed it nRe, for brevity. You also provided a formula for term2, and you said the formula comes from the K-K relations. Therefore I computed nIm from nRe, using the formula you gave:
nIm=nu(2:end).*diff(nRe)./diff(nu);
This calculation is much easier than the many lines of code you used to compute term2. The resulting vector nIm matches the vector term2 in the file matlab.mat. See plot below. This confirms that term2 and nRe are related by the formula which you gave.
Notice that the horizontal axis is frequency in MHz, relative to the base frequency of the range shown. The base frequency is 378 THz, which corresponds to about 0.8 um wavelength in vacuum, i.e. near infrared, i.e. slightly longer wavelength than visible light. The values for term2=nIm range from -5000 to +5000. These correspond to attenuation factors in the equation . Values of nIm=-5000 and nIm=+5000 are very large amplification and attenuation factors, respectively. Are you confident in the equation you gave for term2? Could there be a constant that you forgot?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by