Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. (*declaration of parameters*)
  2. T = 2.0;
  3. w = 0.05;
  4. a = 2.0;
  5. num = 1000.0;
  6. A = 1.0;
  7. Amp = 0.05;(*noise amplitude*)
  8. (*declaration of continous function*)
  9. pulse[x_] := A*(UnitStep[x + w*T] - UnitStep[x - w*T])
  10. (*funciton sampling*)
  11. funX = Table[i, {i, -T/2, T/2, T/(num - 1)}];
  12. fun1 = pulse /@ funX + Amp*RandomReal[{-0.5, 0.5}, num];
  13. fun2 = pulse /@ (a*funX) + Amp*RandomReal[{-0.5, 0.5}, num];
  14. ListPlot[Transpose[{funX, fun1}], PlotRange -> All, Filling -> Axis,
  15. Frame -> True, FrameLabel -> {"Time [s]", "Amplitude [V]", "Pulse"},
  16. PlotLegends -> {"Pulse"}, ImageSize -> Large]
  17.  
  18. (*Fourier Transform*)
  19. xf = With[{
  20. i = Function[{t0, t1, x0, x1},
  21. Evaluate@
  22. Integrate[(x0 + (x1 - x0)/(t1 - t0) *(t - t0))*
  23. Exp[-2*Pi*I*f*t], {t, t0, t1}]]},
  24. Compile[{{f, _Real}, {t, _Real, 1}, {x, _Real, 1}} ,
  25. Total@i[Most[t], Rest[t], Most[x], Rest[x]]]
  26. ];
  27.  
  28. freq = Table[j, {j, -40., 40.}]/T;
  29. Xorig = xf[#, funX, fun1] & /@ freq;
  30. Xscaled = xf[#, funX, fun2] & /@ freq;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement