I am a newcomer to the Julia world, so I started trying to implement a very simple program:
- Sample a signal
- Reconstruct it (various ways, just rectangular for now)
- Plot it
Everything is fine and 'working' properly, but coming from a OOP (java) and functional (python) background, I'm thinking that the following snippet can be improved to be in a more julia-ish style:
(required packages: DSP, Plots, PyPlot) # parameters Ts = 0.02; n = 0:(100 / Ts); f0 = 5; dt = 0.001; t = 0:dt:10; # sampling x = sin.(2 * pi * f0 * Ts * n); # target signal to sample # reconstruct (need improvement) rectangular_reconstr(i) = x[floor(Int, i * (length(n) / length(t)) + 1)] x_recon_sinc = [rectangular_reconstr(e) for e in 1:(length(t)-1)]
I'm concerned about this list comprehension. Essentially, create a function that maps indices from
(sampled) -> reconstructed is the whole idea here. If you were to do other kinds of interpolation (via spline, triangular or whatever), you can even access all the elements of the sampled array.
Is there any better alternative than this loop-comprehension version?