
a=1;
signal[t_]:=Exp[-t^2/a^2];
            
Plot[signal[t],{t,-5,5},PlotRange->{{-5,5},{0,1}},AxesLabel->{"t","s"}]

spectre[T_,npoints_]:=Module[{te,temps,echantillons,transFourier,frequences,spectre},
	te=T/npoints;
	temps[k_]:=-T/2+(k-1)*te;
	echantillons:=Table[signal[temps[k]],{k,npoints}];
	transFourier=Fourier[echantillons,FourierParameters->{-1,-1}]*T;
	frequences[k_]:=(k-1)/T;
	spectre=Table[{frequences[k],Abs[transFourier[[k]]]},{k,npoints}];
	Return[spectre];
]
            

tfSignal[f_]:=a*Sqrt[Pi]*Exp[-(Pi*a*f)^2];
            

T=20; npoints=100;
sp=spectre[T,npoints];
p1=ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{-npoints/T,npoints/T},{0,2}},
									PlotStyle->{RGBColor[1,0,0]}];
p2=Plot[tfSignal[f],{f,-npoints/T,npoints/T},PlotRange->{{-npoints/T,npoints/T},{0,2}}];
            
Show[p1,p2]

T=100; npoints=500;
sp=spectre[T,npoints];
p1=ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{-npoints/T,npoints/T},{0,2}},
									PlotStyle->{RGBColor[1,0,0]}];
p2=Plot[tfSignal[f],{f,-npoints/T,npoints/T},PlotRange->{{-npoints/T,npoints/T},{0,2}}];
            
Show[p1,p2]

T=100; npoints=100;
sp=spectre[T,npoints];
p1=ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{-npoints/T,npoints/T},{0,2}},
									PlotStyle->{RGBColor[1,0,0]}];
p2=Plot[tfSignal[f],{f,-npoints/T,npoints/T},PlotRange->{{-npoints/T,npoints/T},{0,2}}];
            
Show[p1,p2]

a=1;
b=0.1; 
signal[t_]:=Exp[-t^2/a^2]*Cos[2*Pi*t/b];
                
Plot[signal[t],{t,-5,5},PlotRange->{{-2,2},{-1,1}},
                        AxesLabel->{"t","s"}]

T=100; npoints=3000;
sp=spectre[T,npoints]; 
                
ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{0,npoints/T},{0,2}},
                        PlotStyle->{RGBColor[1,0,0]}]

a=1;
signal[t_]:=If[Abs[t]<(a/2),1,0];
                

T=100; npoints=3000;
sp=spectre[T,npoints]; 
                
ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{0,npoints/T},{0,2}},
                        PlotStyle->{RGBColor[1,0,0]}]

b=1; (*periode*)
w0=2*Pi/b;
signal[t_]:=Cos[w0*t]+0.5*Cos[2*w0*t]+0.1*Cos[3*w0*t];
            

T=100; npoints=1000;
sp=spectre[T,npoints];
            
ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{0,npoints/T},{0,T}},
                    PlotStyle->{RGBColor[1,0,0]}]

b=0.9;
w0=2*Pi/b;
signal[t_]:=Cos[w0*t]+0.5*Cos[2*w0*t]+0.1*Cos[3*w0*t];
T=100; npoints=1000;
sp=spectre[T,npoints];
            
ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{0,npoints/T},{0,T}},PlotStyle->{RGBColor[1,0,0]}]

b=0.9;
w0=2*Pi/b;
hamming[t_]:=0.54+0.46*Cos[2*Pi*t/T];
signal[t_]:=(Cos[w0*t]+0.5*Cos[2*w0*t]+0.1*Cos[3*w0*t])*hamming[t];
T=100; npoints=1000;
sp=spectre[T,npoints];
            
ListPlot[sp,AxesLabel->{"f","S"},PlotRange->{{0,npoints/T},{0,T}},
                    PlotStyle->{RGBColor[1,0,0]}]
