function [ h, tf ] = Jakes_Flat( fd, Ts, Ns, t0, E0, phi_N )
%JAKES_FLAT
% Inputs:
% fd, Ts, Ns : Doppler frequency, sampling time, number of samples
% t0, E0 : initial time, channel power
% phi_N : initial phase of the maximum Doppler frequeny
% sinusoid
%
% Outputs:
% h, tf : complex fading vector, current time
if nargin < 6, phi_N = 0; end
if nargin < 5, E0 = 1; end
if nargin < 4, t0 = 0; end
N0 = 8; % As suggested by Jakes
N = 4*N0 + 2; % an accurate approximation
wd = 2*pi*fd; % Maximum Doppler frequency[rad]
t = t0 + [0:Ns-1]*Ts; % Time vector
tf = t(end) + Ts; % Final time
coswt = [ sqrt(2)*cos(wd*t); 2*cos(wd*cos(2*pi/N*[1:N0]')*t) ];
h = E0/sqrt(2*N0+1)*exp(j*[phi_N pi/(N0+1)*[1:N0]])*coswt;
end
Enter code here...>> tic; Jakes_Flat( 926, 1E-6, 50000, 0, 1, 0 ); toc
Elapsed time is 0.008357 seconds.
function Jakes_Flat( fd, Ts, Ns, t0 = 0, E0 = 1, phi_N = 0 )
# Inputs:
#
# Outputs:
N0 = 8; # As suggested by Jakes
N = 4*N0+2; # An accurate approximation
wd = 2*pi*fd; # Maximum Doppler frequency
t = t0 + [0:Ns-1]*Ts;
tf = t[end] + Ts;
coswt = [ sqrt(2)*cos(wd*t'); 2*cos(wd*cos(2*pi/N*[1:N0])*t') ]
h = E0/sqrt(2*N0+1)*exp(im*[ phi_N pi/(N0+1)*[1:N0]']) * coswt
return h, tf;
end
# Saved this as "jakes_model.jl"
julia> include( "jakes_model.jl" )
Jakes_Flat (generic function with 4 methods)
julia> @time Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 )
elapsed time: 0.65922234 seconds (61018916 bytes allocated)
julia> @time Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 )
elapsed time: 0.042468906 seconds (17204712 bytes allocated, 63.06% gc time)
0.042468906 sec) than first(0.65922234 sec), it's still much higher to Matlab(0.008357 sec).@code_warntype Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 )@code_warntype Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 )
[ phi_N pi/(N0+1)*[1:N0]']
function Jakes_Flat( fd, Ts, Ns, t0 = 0, E0 = 1, phi_N = 0 )
# Inputs:
#
# Outputs:
N0 = 8; # As suggested by Jakes
N = 4*N0+2; # An accurate approximation
wd = 2*pi*fd; # Maximum Doppler frequency
t = t0 + [0:Ns-1;]*Ts;
tf = t[end] + Ts;
coswt = [ sqrt(2)*cos(wd*t'); 2*cos(wd*cos(2*pi/N*[1:N0;])*t') ]
temp = zeros(1,N0+1)
temp[1,2:end] = pi/(N0+1)*[1:N0;]'
temp[1,1] = phi_N
h = E0/sqrt(2*N0+1)*exp(im*temp ) * coswt
return h, tf;
end
Otherwise, if we keep telling people that they need to convert their code to use for-loops, I think Julia isn't going to seem very compelling for people looking for alternatives to Matlab, R, etc.
x' * A * x
Is it possible to tell Julia to run the vectorized code in parallel? Looking at the documentation I see that you can do it easily for the looped version but is there a macro or something to pass the vectorized version so that is becomes parallel?
function Jakes_Flat( fd, Ts, Ns, t0 = 0, E0 = 1, phi_N = 0 )# Inputs:## Outputs: N0 = 8; # As suggested by Jakes N = 4*N0+2; # An accurate approximation wd = 2*pi*fd; # Maximum Doppler frequency ts = collect(t0 + (0:Ns-1)*Ts) tf = ts[end] + Ts; Ns = collect(1:N0)
coswt = [ cosvec(ts, wd)'; cosmat(ts, Ns, wd, N) ] h = E0/sqrt(2*N0+1)*exp(im*[ phi_N pi/(N0+1)*(1:N0)']) * coswt return h, tf;end
@acc function cosvec(ts, wd) Float64[sqrt(2)*cos(wd*t) for t in ts]end
@acc function cosmat(ts, Ns, wd, N) Float64[2*cos(wd*cos(2*pi/N*n)*t) for n in Ns, t in ts]endjulia> @time Jakes_Flat( 926, 1e-6, 50000, 0, 1, 0 ) 0.004779 seconds (115 allocations: 4.965 MB)julia> @time Jakes_Flat_noacc( 926, 1e-6, 50000, 0, 1, 0 ) 0.019072 seconds (75 allocations: 8.396 MB)>> tic; Jakes_Flat( 926, 1E-6, 50000, 0, 1, 0 ); tocElapsed time is 0.009936 seconds.julia> @time h, f = Jakes_Flat( 926, 1e-6, 5000000, 0, 1, 0 )
0.585940 seconds (153 allocations: 495.918 MB, 12.47% gc time)
(>> tic; Jakes_Flat( 926, 1E-6, 5000000, 0, 1, 0 ); toc
Elapsed time is 0.609867 seconds.