Info
This question is closed. Reopen it to edit or answer.
Discrete Fourier Transform problem
1 view (last 30 days)
Show older comments
Hi All,
I am trying to do a discrete Fourier transform on a specific cell Vy(i+1,probe_j,probe_k). What is wrong with my code? I just get some dotted lines as output!
close all clear all clc
a = 0.02; d = 0.02;
source_j = 26; source_k = 26;
probe_j = 29; probe_k = 45;
L = (4*pi)*10^(-7); C = 0.5*(8.854*10^(-12)); del_L = 0.0002; vL = 1/sqrt(L*C); ZL = sqrt(L/C); del_t = del_L/(2*vL);
na = (a/del_L); nd = (d/del_L); nt = 1013;
Vy = zeros (nt, nd, na);
V1i = zeros(nt,nd,na); V2i = zeros(nt,nd,na); V3i = zeros(nt,nd,na); V4i = zeros(nt,nd,na);
V1r = zeros(nt,nd,na); V2r = zeros(nt,nd,na); V3r = zeros(nt,nd,na); V4r = zeros(nt,nd,na); f = linspace(1*(10^9),10*(10^9),100);
F=zeros(1013,na,nd);
%%excite just one cell V1i(1,26, 26) = 1; V2i(1,26, 26) = 1; V3i(1,26, 26) = 1; V4i(1,26, 26) = 1;
for i=1:nt-1
%%%%%%%%%%%%%Scattering%%%%%%%%%%%%%%%%%%%%%%
for j = 1:nd
for k = 1:na
% [V1i(i,j,k); V2i(i,j,k); V3i(i,j,k) ;V4i(i,j,k)] = 0.5*[-1 1 1 1; 1 -1 1 1; 1 1 -1 1; 1 1 1 -1]*[V1i(i,j,k); V2i(i,j,k); V3i(i,j,k); V4i(i,j,k)];
V1r(i,j,k) = 0.5*(-V1i(i,j,k) + V2i(i,j,k) + V3i(i,j,k) + V4i(i,j,k));
V2r(i,j,k) = 0.5*(V1i(i,j,k) - V2i(i,j,k) + V3i(i,j,k) + V4i(i,j,k));
V3r(i,j,k) = 0.5*(V1i(i,j,k) + V2i(i,j,k) - V3i(i,j,k) + V4i(i,j,k));
V4r(i,j,k) = 0.5*(V1i(i,j,k) + V2i(i,j,k) + V3i(i,j,k) - V4i(i,j,k));
%
end
end
%%%%%%%%%%%%%Connection%%%%%%%%%%%%%%%%%%%%%%
%Boundary Cells :-
k=1;
for j=2:nd-1
V1i(i+1,j,k)=-V1r(i,j,k);
V4i(i+1,j,k)=V2r(i,j+1,k);
V2i(i+1,j,k)=V4r(i,j-1,k);
V3i(i+1,j,k)=V1r(i,j,k+1);
end
k=na;
for j=2:nd-1
V3i(i+1,j,k)=-V3r(i,j,k);
V4i(i+1,j,k)=V2r(i,j+1,k);
V1i(i+1,j,k)=V3r(i,j,k-1);
V2i(i+1,j,k)=V4r(i,j-1,k);
end
j=1;
for k=2:na-1
V2i(i+1,j,k)=-V2r(i,j,k);
V1i(i+1,j,k)=V3r(i,j,k-1);
V3i(i+1,j,k)=V1r(i,j,k+1);
V4i(i+1,j,k)=V2r(i,j+1,k);
end
j=nd;
for k=2:na-1
V4i(i+1,j,k)=-V4r(i,j,k);
V2i(i+1,j,k)=V4r(i,j-1,k);
V1i(i+1,j,k)=V3r(i,j,k-1);
V3i(i+1,j,k)=V1r(i,j,k+1);
end
%Corner Cells:-
%Left-Bottom corner:
j=1;
k=1;
V1i(i+1,j,k)=-V1r(i,j,k);
V2i(i+1,j,k)=-V2r(i,j,k);
V3i(i+1,j,k)=V1r(i,j,k+1);
V4i(i+1,j,k)=V2r(i,j+1,k);
%Right-Bottom corner:
j=nd;
k=1;
V1i(i+1,j,k)=-V1r(i,j,k);
V4i(i+1,j,k)=-V4r(i,j,k);
V3i(i+1,j,k)=V1r(i,j,k+1);
V2i(i+1,j,k)=V4r(i,j-1,k);
%Left-Top corner:
j=1;
k=na;
V2i(i+1,j,k)=-V2r(i,j,k);
V3i(i+1,j,k)=-V3r(i,j,k);
V1i(i+1,j,k)=V3r(i,j,k-1);
V4i(i+1,j,k)=V2r(i,j+1,k);
%Right-Top corner:
j=nd;
k=na;
V3i(i+1,j,k)=-V3r(i,j,k);
V4i(i+1,j,k)=-V4r(i,j,k);
V1i(i+1,j,k)=V3r(i,j,k-1);
V2i(i+1,j,k)=V4r(i,j-1,k);
%Intermediate Cells:-
for j = 2:nd-1
for k=2:na-1
V1i(i+1,j,k) = V3r(i,j,k-1);
V2i(i+1,j,k) = V4r(i,j-1,k);
V3i(i+1,j,k) = V1r(i,j,k+1);
V4i(i+1,j,k) = V2r(i,j+1,k);
end
end
Vy(i+1,probe_j,probe_k) = 0.5*(V1i(i+1,probe_j,probe_k) + V2i(i+1,probe_j,probe_k) + V3i(i+1,probe_j,probe_k) + V4i(i+1,probe_j,probe_k));
F = fft(Vy(i+1,probe_j,probe_k));
end
% plot(1:nt,Vy(:,probe_j,probe_k));
plot(f, abs(F));
% plot(Vy(:,30,30));
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!