1
$\begingroup$

I am a Mathematica novice and was attempting to package the following code:

srrc[beta_,tau_,t_] :=
    Piecewise[{
        {beta*(Pi*Sin[(Pi*(1+beta))/(4*beta)]+2*Sin[(Pi*(1-beta))/(4*beta)]),Abs[t]==tau/(4*beta)},
        {(4*beta*Cos[Pi*(1+beta)*t/tau]+Pi*(1-beta)*Sinc[Pi*(1-beta)*t/tau])/(1-(4*beta*t/tau)^2),True}
    }]/(Pi*tau)


psi[L_, beta_, tau_, t_] :=
    Normalize[(*...with respect to the integral norm.*)
       srrc[beta, tau, x] (UnitStep[x + L*tau/2] - UnitStep[x - L*tau/2]),
       Integrate[#, {x, -Infinity, Infinity}, PrincipalValue -> True] &
    ]/2 /. x :> t


rho[L_, beta_, tau_, t_] :=
    Integrate[
        psi[L, beta, tau, w - L*tau/2],
        {w, -Infinity, t},
        (*Assumptions\[Rule](L\[Element]Integers)&&(L>0)&&(beta\[Element]Reals)&&(beta\[GreaterEqual]0)&&(tau\\[Element]Reals)&&(tau>0)&&(t\[Element]Reals),*)
        PrincipalValue -> True
    ]


phi[a_?VectorQ, mu_, L_, beta_, tau_, t_] := mu*a.Array[rho[L, beta, tau, t - #*tau] &, Length[a], 0]


model[a_, Fc_, mu_, L_, beta_, tau_, t_] := Exp[I*2*Pi*(Fc*t + phi[a, mu, L, beta, tau, t])]


modCPFSK[a_, Fs_, Fc_, mu_, L_, beta_, tau_] :=
    Assuming[Element[L,Integers] && (L > 0) && Element[beta,Reals] && (beta >= 0) && Element[tau,Reals] && (tau > 0),
        Table[model[a, Fc, mu, L, beta, tau, t], {t, 0, Length[a]*tau + L*tau, 1/Fs}]
    ]

Each of the functions is plotted with calls like the following:

With[{a = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1}, Fs = 20000., mu = 0.002, L = 2, beta = 0.02, tau = 1/2000.},
    ListPlot[ReIm@modCPFSK[a, Fs, 0, mu, L, beta, tau], PlotRange -> Full]
]

(Eventually I would like to use Manipulate[] to illustrate the effects of varying the parameters.)

Unfortunately the code runs very slow-- particularly those functions involving Integrate[]-- and my naive attempts have not yielded faster execution (e.g., pre-evaluating with Evaluate[] and Simplify[]).

Please advice on how to improve its speed. Many thanks in advance.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.