Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

sth wrong in my matlab code..

Status
Not open for further replies.

was29e

Junior Member level 2
Joined
Mar 10, 2005
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
amman-jordan
Activity points
1,549
hi..
im writing a code to design a multilayer optical filter, the code goes like this:
i have N layers where each of them is described using a characteristic matrix m, and the resulting matrix for the whole structure is M=Πm from the first layer to the last one..

i wrote the code but theres sth. wrong it keeps telling me wrong using vertcat !!

can anyone take a look at it and tell me what is the prob. 'coz i can't find it..


and one more thing: how can i change the extension of a matlab file .m ??


*********************************************

for w=w %w=1000:2000 wavelength
M=[1 0;01];
d= ones(1,Nmax)*wc/4; %d:thickness of layer
%n layers each defined by m
for i=1:Nmax
if mod (i,2)==0
ni=nH;
else
ni=nL;
end

g=(2*pi*ni*d1i)/w; %M: the charactarestic matrix of all
%g=phase layers = multiplication of
m for each layer
m11=cos(g);
m12=(sin(g))/ni;
m21=ni*sin(g);
m22=cos(g);
M=M*[m11 i*m12;m21 m22];
end
t=2*n0/(((M(1)+i*M(3)*ns)*n0)+(i*M(2)+M(4)*ns));
%t=fractional transmission

tstar=conj(t);
T=t.*tstar.*(ns/n0);
R=1-T;
end
plot(R)
axis([wmin wmax 0 1])
 

you have typing problem on the second line:

M=[1 0;01];

should be

M=[1 0;0 1];

you forgot space between '0' and '1'. so the matlab thoth it was only one number.
 

    was29e

    Points: 2
    Helpful Answer Positive Rating
hi..thanx , i didnt notcie that..

one more thing can u tell me how i can get R as a matrix in the big for loop, i cant get the whole results of the loop, it gives me the last one only :(

Added after 4 hours 10 minutes:

so, i did something in my code and it run perfectly, when i tried to run after 3 hours its not working and again i cant find what is wrong....


n0=1
ns=3
w=1000:2000
wc=1500
nL=2
nH=2.5
Nmax=3

for w=w
R(w)=R(w);
M=[1 0;0 1];
d= ones(1,Nmax)*wc/4; %d thickness of layers

for i=1:Nmax
if mod (i,2)==0
ni=nH;
else
ni=nL;
end

g=(2*pi*ni*d(1,i))/w
%g=phase
m11=cos(g);
m12=(sin(g))/ni;
m21=ni*sin(g);
m22=cos(g);
M=M*[m11 i*m12;i*m21 m22];
end
t=2*n0/(((M(1)+i*M(3)*ns)*n0)+(i*M(2)+M(4)*ns));
%t=fractional transmission
tstar=conj(t);
T=t.*tstar.*(ns/n0);
R(w)=1-T;

end

w=[wmin:wmax];
plot(w,R(w))
 

what should R store?

what the following line means: R(w)=R(w);
 

R should store the result of T-1
that is R=R(w)

about R(w)=R(w) i wrote this so it keeps giving me the new vales of R(w) in the end of the loop
 

maybe you mean this:

n0=1
ns=3
w=1000:2000
wc=1500
nL=2
nH=2.5
Nmax=3
R=[];

for w=w
%R(w)=R(w);
M=[1 0;0 1];
d= ones(1,Nmax)*wc/4; %d thickness of layers

for i=1:Nmax
if mod (i,2)==0
ni=nH;
else
ni=nL;
end

g=(2*pi*ni*d(1,i))/w
%g=phase
m11=cos(g);
m12=(sin(g))/ni;
m21=ni*sin(g);
m22=cos(g);
M=M*[m11 i*m12;i*m21 m22];
end
t=2*n0/(((M(1)+i*M(3)*ns)*n0)+(i*M(2)+M(4)*ns));
%t=fractional transmission
tstar=conj(t);
T=t.*tstar.*(ns/n0);
R=[R 1-T];

end

%w=[wmin:wmax];
%plot(w,R)
plot(R)
 

    was29e

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top