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

3 visualizzazioni (ultimi 30 giorni)
Shaily_T il 4 Mar 2023
Modificato: Shaily_T il 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)));
gaussEqn1 = gaussEqn1 + thisGaussian1;
dcomb1 = gaussEqn1;
end
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'.
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Risposte (1)

William Rose il 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:
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 CommentiMostra 5 commenti meno recentiNascondi 5 commenti meno recenti
William Rose il 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?

Accedi per commentare.

### Categorie

Scopri di più su Annotations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!