i want to store the result of 191 iterations in one variable and then i want to find the slope of those values.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
A = load ('example.txt') size(A) n = 191; for i = 1:191 A (i,:) A([i] , [2 3 4 5 6 7 8 9])
freq(i) = A (i,1) s11mag(i) = A(i,2) s11ang(i) = A(i,3) s12mag(i) = A(i,4) s12ang(i) = A(i,5) s21mag(i) = A(i,6) s21ang(i) = A(i,7) s22mag(i) = A(i,8) s22ang(i) = A(i,9)
% 1deg = 0.0174532925 radians q = 0.0174532925
s11real(i) = s11mag(i) * cos(s11ang(i) * q) s11img(i) = s11mag(i) * sin (s11ang(i) * q) s11(i) = s11mag(i).* exp( j * (s11ang(i) * q))
s12real(i) = s12mag(i) * cos(s12ang(i) * q) s12imag(i) = s12mag(i) * sin (s12ang(i) * q) s12(i) = s12mag(i).* exp( j * (s12ang(i) * q))
s21real(i) = s21mag(i) * cos(s21ang(i) * q) s21imag(i) = s21mag(i) * sin (s21ang(i) * q) s21(i) = s21mag(i).* exp( j * (s21ang(i) * q))
s22real(i) = s22mag(i) * cos(s22ang(i) * q) s22imag(i) = s22mag(i) * sin (s22ang(i) * q) s22(i) = s22mag(i).* exp( j * (s22ang(i) * q))
s = [s11 s12 ; s21 s22] D = ((1+s11(i))*(1+s22(i))-s12(i)*s21(i)) Z0 = 50
%s- parameter to y-parameter
y11(i) = ((1-s11(i))*(1+s22(i))+s12(i)*s21(i)) / (D * Z0) y12(i) = -2*s12(i) / (D * Z0) y21(i) = -2*s21(i) / (D * Z0) y22(i) = ((1+s11(i))*(1-s22(i))+s12(i)*s21(i)) / (D * Z0)
y = [y11 y12 ; y21 y22]
y11real(i) = real(y11(i)) y11imag(i) = imag (y11(i)) y12real(i) = real(y12(i)) y12imag(i) = imag (y12(i)) y21real(i) = real(y21(i)) y21imag(i) = imag (y21(i)) y22real(i) = real(y22(i)) y22imag(i) = imag (y22(i))
%extrinsic parasitic capacitances
Cgdo(i) = -y12imag(i) / (2 * pi * freq(i)) Cgda(i) = [0.01:0.5] * Cgdo(i) Cgdi(i) = 2 * Cgda(i) Cgd(i)= Cgdo(i) - Cgda(i) - Cgdi(i) Cdso(i) = y22imag(i) /(2 * pi * freq(i)) - Cgdo(i) Cpda(i) = [0.01:0.5]* Cdso(i) Cpdi(i) = 3* Cpda(i) Cds(i) = Cdso(i) - (4 * Cpda(i)) Cgs(i) = Cgd(i) Cpga(i) = [0.01:0.5] * Cdso(i)
Cgso(i) = y11imag(i) /(2 * pi * freq(i)) - Cgdo(i) Cpgi(i) = Cgso(i) - Cgd(i) - Cpga(i)
%plotting capacitances vs frequency
% subplot(221);plot(freq,Cpga);hold on; % subplot(222);plot(freq,Cpgi);hold on; % subplot(223);plot(freq,Cpda);hold on; % subplot(224);plot(freq,Cpdi);hold on;
% de- embedding capacitances Cpga,Cpda and Cgda from Y-parameters
y11int(i) = y11(i) - (j* (2 * pi * freq(i)) (Cpga(i) + Cgda(i))) y12int(i) = y12(i) + (j (2 * pi * freq(i)) * Cgda(i)) y21int(i) = y21(i) + (j* (2 * pi * freq(i)) * Cgda(i)) y22int(i) = y22(i) - (j* (2 * pi * freq(i)) *(Cgda(i) +Cpda(i)))
yint = [y11int y12int ; y21int y22int]
y11intreal(i) = real(y11int(i)) y11intimag(i) = imag (y11int(i)) y12intreal(i) = real(y12int(i)) y12intimag(i) = imag (y12int(i)) y21intreal(i) = real(y21int(i)) y21intimag(i) = imag (y21int(i)) y22intreal(i) = real(y22int(i)) y22intimag(i) = imag (y22int(i))
%converting Yint-para to z-parameters
z11(i) = y22int(i) / (y11int(i) * y22int(i) - y12int(i) * y21int(i)) z12(i) = -y12int(i) / (y11int(i) * y22int(i) - y12int(i) * y21int(i)) z21(i) = -y21int(i) / (y11int(i) * y22int(i) - y12int(i) * y21int(i)) z22(i) = y11int(i) / (y11int(i) * y22int(i) - y12int(i) * y21int(i))
z = [z11 z12 ; z21 z22]
w(i) =(2* pi* freq(i))
z11real(i) = real (z11(i)) z11imag(i) = imag (z11(i)) z12real(i) = real (z12(i)) z12imag(i) = imag (z12(i)) z21real(i) = real (z21(i)) z21imag(i) = imag (z21(i)) z22real(i) = real (z22(i)) z22imag(i) = imag (z22(i))
m(i) = w(i) * (z11imag(i) - z12imag(i)) n(i) = w(i) * (z22imag(i) - z12imag(i)) o(i) = w(i) * z12imag(i)
subplot(221);plot(w(i)^2, m(i)); hold on; subplot(222);plot(w(i)^2, n(i)); hold on; subplot(223);plot(w(i)^2, o(i)); hold on; subplot(224);plot(w(i)^2,m(i),’b’, w(i)^2,n(i),’r’, w(i)^2,o(i),’g’); hold on ;
end
3 Comments
Matt Fig
on 20 Nov 2012
Two things:
- FORMAT YOUR CODE!
- Ask a question.
ria
on 21 Nov 2012
Image Analyst
on 21 Nov 2012
A tip: in the editor, type control-A and then control-I and it will make your code look nice - fix all the indenting.
Answers (1)
John Petersen
on 20 Nov 2012
gradient(y)
will give you the slope at every point of the variable y.
2 Comments
ria
on 26 Nov 2012
John Petersen
on 28 Nov 2012
The default spacing used by gradient() is sequential points. The actual spacing of those points is defined by the user. You CAN specify a different spacing if you want. Here's an example:
t = 0:.01:10;
ct = cos(t);
slope_of_ct = gradient(ct);
figure;plot(t,ct,t,slope_of_ct); grid on;
legend('signal','slope of signal');
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!