Alfa Heryudono
MTH540/440 - EAS621/622 - DSC550 Discussion Session
September 23, 2020
Topic: Separating Noise from Signals Numerical Experiment.
See the discussion video in mycourses.

ClearAll["Global`*"]
(*f[x_]:=Exp[-x^2]*Sin[5*Pi*x]-x*Cos[0.5*Pi*x]*)
f[x_]:=Exp[-x^2]*Sin[15*Pi*x]-x*Cos[0.5*Pi*x]+x*Sin[2*Pi*x]
x=Table[x,{x,-1,2,0.005}];
input = Table[f[x]+RandomReal[{-0.8,0.8},Length[x]],{i,1,100}];
output = Table[f[x],{i,1,100}];
asso=Thread[input->output];
net=NetChain[{10,10,10,10,10,10,Length[x]},"Input"->Length[x],"Output"->Length[x]]
trained=NetTrain[net,asso]

g1:=Plot[f[x],{x,-1.5,2.5},PlotRange->{-3 ,3}];
nf=f[x]+RandomReal[{-0.4,0.4},Length[x]];
r=trained[nf];
g2:=ListPlot[Thread[{x,nf}],ImageSize->Large,PlotStyle->Gray,Joined->True];
g3:=ListPlot[Thread[{x,r}],ImageSize->Large,PlotStyle->Red];
Show[g1,g2,g3]
Show[g1,g3]