clear all
close all
lp=0.05;
xstep=0.1;
x=0:xstep:105.6;
K=2*pi*lp;
j=1:100;
[X,J]=meshgrid(x,j);
sinj=sin((J*2-1) .*K .*X) ./(J*2-1);
plotarg=K/2/pi.*(j*2-1);
val=input('Typ av MTF? sinc->1, rect->2, gauss->3 ');
krit=input('Kritisk frekvens? (Anges som faktor större än 1)  ');
if val==1 MTF=(sin(pi*plotarg/krit/lp) ./(pi*plotarg/krit/lp)) .^2;
end
if val==2 MTF=(plotarg/krit/lp<1);
end
if val==3 MTF=exp(-(plotarg/krit/lp) .^2);
end
figure(1)
objekt=1+sum(sinj)/0.7853;
set(1,'Position',[20 280 570 200])
plot(x,objekt,'g')

res=MTF*sinj/0.7853+1;
text(10*xstep,max(res)*1.1,'Objektet grönt, bilden gul')
hold on
plot(x,res,'y')
hold off
figure(2)
set(2,'Position',[150 30 400 205])
plot(plotarg,MTF)
text(8.1,0.9,'MTF')
grid
figure(3)
set(3,'Position',[600 280 424 600])
xmin=round(0.75/lp/xstep);
xmax=round(0.25/lp/xstep);
bild=res'*ones(size(j));
bild=bild-min(min(bild));
bild=bild*64/max(max(bild));
colormap(gray)
image(bild')
figure(4)
set(4,'Position',[556 30 464 205])
MEF=-10*log10(MTF);
plot(plotarg,MEF)
text(4,max(MEF)/10,'Modulation Error Function')
