Definicija in graf funkcije v Mathematici. Ukaza Piecewise in Plot.

f[x_]:=Sin[x]+Cos[x/3];
Plot[f[x],{x,-10,10}]
Plot[f[x],{x,-10,10},PlotStyle->{Red,Thick,Dashed}]
g[x_]:=Piecewise[{{ x,0<x<1},{1,1≤ x<2},{3-x,2≤x<3}},0]
g1=Plot[g[x],{x,-1,4}]
h[x_]=UnitStep[x-2]-UnitStep[x-4];
g2=Plot[h[x],{x,0,5},PlotStyle->{Red,Thick}];
Show[g1,g2]

Ukaz Manipulate.

Manipulate[Plot[Sin[x(1+a x)],{x,0,6}],{a,0,2}]

1. Vaja: Fourierova transformacija

1.  Primer: Narisi graf funkcije  sin(t)  za 0≤ t ≤ π in 0 drugod.  Uporabi ukaz Piecewise.
	Vzeli bomo definicijo Fourierove transformacije po (Tomsic, Slivnik)  FourierParameters->{1,1}

f[t_]:=Piecewise[{{Sin[t],0≤t≤π}},0]
Plot[f[t],{t,-π,2π},PlotStyle->{Thick,Red,Dashed}]

2. Primer: Narisi graf funkcije f(x) in njene Fourierove transformiranke. 
	 a. f(t) = 1, za  -π ≤ t ≤ π in 0 drugod
b. f(t) = 1, za -π ≤ t ≤ π,  -3 π ≤  t ≤  -2 π, 2 π ≤  t ≤  3 π in 0 drogod. 
c. f(t) = cos(t), za -π ≤ t ≤  π in 0 drugod
	 d. f(t)=(e^(-π t^2))cos(6t)

Clear[f,t]
f[t_]:=Piecewise[{{1,-Pi≤t≤Pi}},0]
Plot[f[t],{t,-3Pi/2,3Pi/2},PlotStyle->Thick]
FourierTransform[f[t],t,ω,FourierParameters->{1,1}]
Plot[%,{ω,-10,10},PlotRange->All]

Clear[f,t]
f[t_]:=Piecewise[{{1,-Pi≤t≤Pi},{1,-3Pi ≤t≤-2Pi||2Pi ≤t≤3Pi}},0]
Plot[f[t],{t,-4Pi,4Pi},PlotStyle->Thick]
FourierTransform[f[t],t,ω,FourierParameters->{1,1}]//FullSimplify
Plot[%,{ω,-10,10},PlotRange->All]

Clear[f,t]
f[t_]:=Piecewise[{{Cos[t],-Pi/2≤t≤Pi/2}},0]
Plot[f[t],{t,-Pi,Pi},PlotStyle->Thick]
FourierTransform[f[t],t,ω,FourierParameters->{1,1}]//FullSimplify
Plot[%,{ω,-10,10},PlotRange->All]

Clear[f,t]
f[t_]:=Exp[-Pi t^2]Cos[6t]; 
Plot[f[t],{t,-2,2},PlotRange->All]
FourierTransform[f[t],t,ω]//FullSimplify
Plot[Evaluate[%],{ω,0,10},PlotRange->{0,0.5}]

3. Primer: Narisi graf funkcije, njene Fouriereve transformirake in gostoto spektra s pomocjo LogLogPlot.
	a. f(t)=sin(t), za  0≤ t≤π,  in 0 drugod.
	b. f(t)=sin(10t)(e^(-t/10)), za t>0 in 0 drugod.
	c. f(t)=sin(x)/x
	d. f(t)=(e^(-|t|))
	e. f(t)=(e^(-t^2))

Clear[f,t]
f[t_]:=Piecewise[{{Sin[t],0≤t≤Pi}},0]
Plot[f[t],{t,-Pi/2,3Pi/2},PlotStyle->Thick]
FourierTransform[f[t],t,ω,FourierParameters->{1,1}]
LogLogPlot[Evaluate@Abs[%],{ω,1*^-1,1*^1},PlotRange->All]

Clear[f,t];
f[t_]:=Piecewise[{{Sin[10 t]Exp[-t/10],t>0}},0]
Plot[f[t],{t,-1,20}]
FourierTransform[f[t],t,ω]
Plot[Abs[%],{ω,-10,10}]
LogLogPlot[Evaluate@Abs[%%],{ω,1*^-1,1*^2},PlotRange->All]

Clear[f,t];
f[t_]:=Sin[10t]/t 
Plot[f[t],{t,-5,5},PlotRange->All]
FourierTransform[f[t],t,ω]
Plot[Evaluate[%],{ω,-40,40},PlotRange->All]
LogLogPlot[%%,{ω,1*^-1,1*^2},PlotRange->All]

Clear[f,t]
f[t_]:=Exp[-Abs[t]] 
Plot[f[t],{t,-5,5},PlotRange->All]
FourierTransform[f[t],t,ω]
Plot[Evaluate[%],{ω,-40,40},PlotRange->All]
LogLogPlot[%%,{ω,1*^-1,1*^1},PlotRange->All]

Clear[f,t]
f[t_]:=Exp[-t^2] 
Plot[f[t],{t,-5,5},PlotRange->All]
FourierTransform[f[t],t,ω]
Plot[Evaluate[%],{ω,-40,40},PlotRange->All]
LogLogPlot[%%,{ω,1*^-1,1*^2},PlotRange->All]

4. Primer: Uporabi ukaz  Manipulate in prikazi graf funkcije in njene Fourierove transformiranke za razlicne vrednosti parametra.
	a. f(t)=((e^(-((t^2)/(2 (a^2)))))/(Sqrt[2 π a])), za vrednosti parametra a na intervalu [1,5]. 
	b. f(t)=sin(t)/t zavrednosti parametraanaintervalu [1,5].

Clear[f,g,t];
f[t_,a_]=1/Sqrt[a*2π]Exp[-t^2/2/a^2]
g[ω_,a_]=FourierTransform[f[t,a],t,ω,Assumptions->a>0]
Manipulate[
g1=Plot[f[t,a],{t,-5,5},PlotStyle->{Blue,Thick},PlotRange->All];
g2=Plot[g[ω,a],{ω,-5,5},PlotStyle->{Red,Thick},PlotRange->All];
Show[{g1,g2},PlotRange->{-0.1,0.6},AxesOrigin->{0,0}],{a,0.5,2}]

Clear[f,g,t]
f[t_,a_]=Sin[a t]/t;
g[ω_,a_]=FourierTransform[f[t,a],t,ω];
Manipulate[
g1=Plot[f[t,a],{t,-5,5},PlotStyle->{Blue,Thick},PlotRange->All];
g2=Plot[g[ω,a],{ω,-5,5},PlotStyle->{Red,Thick},PlotRange->All];
Show[{g1,g2}],{a,1,5}]

5. Primer: Konvolucija funkcije z enotnim impulzom  s(t)=1, za  -σ ≤ t≤ σ  in 0, drugod.
(f*s) (t) = (∫_(-∞)^∞)f(u)s(t-u)du =  1/(2 σ) (∫_(t-σ)^(t+σ))f(u)du 
Konvolucija v tocki t je enaka povprecni vrednosti funkcije f(u) na [t-σ,t+σ].
a. f(t)=(e^(-|t|))
              b. f(t)= h(t)+h(t-1)+h(t-2), kjer je h(t) enotska stopnica  UnitStep
              c. f(t)={{-1,-2≤x≤0},{2,0≤x≤1},{1,1≤x≤2},{0,True}}

Clear[f,t]
f[t_]=Exp[-Abs[t]];
impulz[t_,σ_]=Piecewise[{{1/(2 σ),-σ≤t≤ σ}},0];
konv[t_,σ_]=Integrate[f[u] impulz[t-u,σ],{u,-∞,∞},Assumptions->σ>0];
Manipulate[
g1=Plot[impulz[t,σ],{t,-2,2},PlotStyle->Thick,PlotRange->All];
g2=Plot[konv[t,σ],{t,-2,2},PlotStyle->{Thick,Red},PlotRange->All];
Show[{g1,g2}],{σ,0.1,1}]

Clear[f,t]
f[t_]=UnitStep[t]+UnitStep[t-1]+UnitStep[t-2];
impulz[t_,σ_]=Piecewise[{{1/(2 σ),-σ≤t≤ σ}},0];
konv[t_,σ_]=Integrate[f[u] impulz[t-u,σ],{u,-∞,∞},Assumptions->σ>0];
Manipulate[
g1=Plot[impulz[t,σ],{t,-2,2},PlotStyle->Thick,PlotRange->All];
g2=Plot[konv[t,σ],{t,-2,2},PlotStyle->{Thick,Red},PlotRange->All];
Show[{g1,g2}],{σ,0.1,0.5}]

Clear[f,g,g1,g2,g3,a,x,g,h];
f[x_,a_]:=Piecewise[{{1,a-1/2≤x≤a+1/2}},0];
g[x_]:=Piecewise[{{-1,-2≤x≤0},{2,0≤x≤1},{1,1≤x≤2}},0];
h[a_]=Integrate[f[x,a]*g[x],{x,-3,3}];
g0=Plot[h[a],{a,-3,3}];
g1=Plot[g[x],{x,-3,3},PlotRange->All,PlotStyle->{Red,Thick},Filling->Axis,FillingStyle->{Opacity[0.2]}];

Manipulate[g3=Plot[f[x,a],{x,-3,3},Filling->Axis];
g4=ListPlot[{{{a,h[a]}},{{a,h[a]}}},PlotStyle->{{PointSize[0.02],Blue},{PointSize[0.015],White}}];
Show[g0,g1,g3,g4,PlotRange->All],{a,-2.5,2.5}]

6. Primer: Konvoucija s trikotnim impuzom s(t)={{2x+1,-1/2≤x≤ 0},{1-2x,0≤ x≤ 1/2}},{0,True}}
         a. f(x)={{-1,-2≤x≤0},{2,0≤x≤1},{1,1≤x≤2}}

Clear[f,g,g1,g2,g3,t,x];
f[x_]:=Piecewise[{{2x+1,-1/2≤x<=0},{1-2x,0≤ x≤ 1/2}},0];
g[x_]:=Piecewise[{{-1,-2≤x≤0},{2,0≤x≤1},{1,1≤x≤2}},0];
h[t_]=Integrate[f[t-x]*g[x],{x,-4,4}];

g0=Plot[2h[t],{t,-4,4},PlotStyle->Thick];
g1=Plot[g[x],{x,-4,4},PlotRange->All,PlotStyle->{Red,Thick}];
Show[g1,g0]

7. Primer: Konvolucija funkcije z Gausovo funkcijo s(t)=(1/(Sqrt[2(σ^2)π]))(e^((-(t^2))/(2(σ^2)))). Parameter σ doloca stopnjo glajenja. 
	a. f(t)=h(t)   parameter σ pretece vrednosti [0.1,0.5].

Clear[f,t,impulz,konv,σ];
f[t_]=UnitStep[t];
impulz[t_,σ_]=1/Sqrt[2σ^2 π]Exp[-t^2/2/σ^2];
konv[t_,σ_]=Integrate[f[u] impulz[t-u,σ],{u,-∞,∞},Assumptions->σ>0];
Manipulate[
g1=Plot[impulz[t,σ],{t,-2,2},PlotStyle->Thick,PlotRange->{0,4}];
g2=Plot[konv[t,σ],{t,-2,2},PlotStyle->{Thick,Red},PlotRange->{0,4}];
Show[{g1,g2}],{σ,0.1,5}]

Naloge

1. Naloga: Narisi graf funkcije f(x)=cos(x), -π/2 ≤ x≤ π/2  in f(x)=0 drugod.
2. Naloga: Poisci Fourierovo transformacijo F(ω) funkcije f(t), iz prejsnje naloge, in inverzno fourierovo trasnformacijo funkcije F(ω). 
3. Naloga: Preveri veljavnost Parsevalove enacbe v gornjem primeru. 
4. Naloga: Poisci sinusno in kosinusno Fourierevo transformacijo funkcije f(t)=(e^(-t)). 
	Ukaza FourierSinTransform in FourierCosTransform.
5. Naloga: Uporabi ukaz Manipulate  in prikazi na isti graf funkcijo  f(t)=(e^(-t^2/a))
 	in njeno Fourierevo transformiranko v odvisnosti od parametra  a∈[1,5].
6. Naloga: Narisi graf funkcije f(x)=(e^(-t/10))sin(10t), t>0 in narisi graf gostote spektra |F(ω)|  z ukazom LogLogPlot na intervalu 
	ω∈[0.1,100].