Last active
August 29, 2015 13:58
-
-
Save balzer82/10293627 to your computer and use it in GitHub Desktop.
Animation for an Electromagnetic Wave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear all | |
close all | |
clc | |
%% Zeichne eine elektromagnetische Welle | |
f=103.2e6; % Frequenz der Welle | |
w=2*pi*f; % Kreisfrequenz | |
oversampling=20;% Abtastung | |
c=3e8; % Lichtgeschwindigkeit in m/s | |
% Beschränkung auf Fernfeld ab 4...10 x Lambda | |
lambda=c/f; | |
tmin=4*lambda/c; | |
tmax=1.0e-7; % darzustellende Zeit | |
t=linspace(tmin,tmax,oversampling*f*tmax)'; | |
r=c.*t; % Weg in m | |
H=1./r.*sin(w.*t); % Magnetische Feldstärke | |
H=H./max(H); % normieren | |
E=1./r.*sin(w.*t); % Elektrische Feldstärke | |
E=E./max(E); % normieren | |
N=zeros(length(t),1); % Nullvektor | |
%% Plotten | |
figure(1) | |
set(gcf, 'Position', [100 100 720 580]) | |
set(gcf,'Color','w') | |
magh=plot3(r(1),N(1),E(1),'r','linewidth',2); | |
grid on | |
hold on | |
elh=plot3(r(1),H(1),N(1),'g','linewidth',2); | |
scatter3(0,0,0,500,'fill','k') | |
line([min(r) max(r)],[0 0],[0 0],'Linewidth',2,'color','k') | |
%line(linspace(min(r),max(r),length(r)),zeros(length(r),1),(1./r)./max(1./r)) | |
legend('Magnetic','Electric','Antenna','location','east') | |
xlim([0 max(r)]) | |
ylim([-1 1]) | |
zlim([-1 1]) | |
th=text(max(r)/2, 0.8, 1, '0.0', 'fontsize', 24); | |
xlabel('Distance [m]') | |
ylabel('Magnetic Field') | |
zlabel('Electric Field') | |
set(gcf,'Paperpositionmode','auto') | |
title(['Electromagnetic Wave with ' num2str(f/1e6) ... | |
'MHz (\lambda=' num2str(round(lambda*100)/100) 'm) in '... | |
num2str(tmax*1e3) 'ms']) | |
%axis('equal') | |
%% Create GIF | |
mygif = 'elektromagnetischeWelle.gif'; | |
for i=2:5:length(t) | |
set(magh, 'X', r(1:i), 'Y', N(1:i), 'Z', E(1:i)) | |
set(elh, 'X', r(1:i), 'Y', H(1:i), 'Z', N(1:i)) | |
millisecond = round(t(i)*1e9)/1e6; % in milliseconds | |
set(th,'string',[num2str(millisecond, '%.6f') 'ms']) | |
%pause(0.01) | |
drawnow | |
f = getframe(gcf); | |
[im,map]=rgb2ind(f.cdata,256,'nodither'); | |
imwrite(im,map,mygif,'writemode','append','Delaytime',0.1) | |
end | |
close(all) | |
%print(gcf,'-dpng','-r300','elektromagnetischeWelle.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
