Skip to content

Commit 6225ba8

Browse files
authored
Merge pull request #2 from hassiweb/performance-improvement-of-channel
Performance improvement in channel processing
2 parents 0fa4af6 + 8032776 commit 6225ba8

1 file changed

Lines changed: 30 additions & 26 deletions

File tree

src/Channel/getChannel.jl

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,10 @@ function getChannel(nbSamples::Int,channelModel::ChannelModel,randSeed=-1)
312312
freq = channelModel.samplingFreq;
313313
# --- Ensuring additional delay for proper interpolation
314314
delay = channelModel.delayProfile .+ fdGap;
315-
cir = zeros(Complex{Float64}, nbSamples, delaySpread + sS);
316-
for indexTime = 1 : 1: nbSamples
317-
for k = 1 : 1 : delaySpread + sS
318-
# --- Each index is superimposition of all timed compondent
319-
for= 1 : 1 : nbTaps
320-
# --- Shannon interpolation with sinc. on sincSupport
321-
cir[indexTime,k] += powerLin[∂] * raylAmpl[indexTime,∂] * sinc.(pi*(k/freq - delay[∂]) * freq);
322-
end
323-
end
324-
end
315+
# --- Shannon interpolation with sinc. on sincSupport
316+
shannonInterp = sinc.(pi.*(transpose(1:delaySpread+sS)./freq .- delay) .* freq);
317+
# --- Each index is superimposition of all timed compondent
318+
cir = transpose(powerLin) .* raylAmpl[1:nbSamples] * shannonInterp;
325319
return ChannelImpl(1,cir,channelModel,powerLin,randSeed);
326320
else
327321
# ----------------------------------------------------
@@ -356,7 +350,9 @@ sigChan : applyChannel(sigId,channelImpl)
356350
# ---
357351
# v 1.0 - Robin Gerzaguet.
358352
"""
353+
359354
function applyChannel(sigId,channelImpl)
355+
360356
if !Bool(channelImpl.timeVarying)
361357
# --- Classic convolution
362358
return sigChan = conv(sigId,channelImpl.cir);
@@ -370,26 +366,34 @@ function applyChannel(sigId,channelImpl)
370366
nbTaps =size(channelImpl.cir,2);
371367
nbOut =length(sigId)+nbTaps
372368
sigChan = zeros(Complex{Float64},nbOut)
373-
# n is time index of output, δ is lag index
374-
for n = 1 : 1 : length(sigId)
375-
# --- At beginning, not possible to have all index
376-
nbMaxTap = min(n,nbTaps);
377-
# --- Classic time domain convolution
378-
for δ = 1 : 1 : nbMaxTap
379-
sigChan[n] += channelImpl.cir[n,δ] * sigId[n-δ+1];
380-
end
381-
end
382-
# At the end we have zero
369+
timeVaryingConv!(sigChan, channelImpl.cir, sigId, nbTaps)
370+
371+
# At the end we have zero
383372
buffEnd = zeros(Complex{Float64},nbTaps *2);
384373
buffEnd[1:nbTaps] = sigChan[1:nbTaps];
385-
for n = 1:nbTaps
386-
# --- Classic time domain convolution
387-
for δ = 1 : 1 : nbTaps
388-
sigChan[length(sigId)+n] += channelImpl.cir[end,δ] * buffEnd[n+nbTaps-δ+1];
389-
end
390-
end
374+
timeVaryingConvTail!(sigChan, channelImpl.cir, buffEnd, length(sigId), nbTaps)
375+
391376
return sigChan;
392377
end
393378
end
394379

380+
function timeVaryingConv!(sigChan, cir, sigId, nbTaps)
381+
# n is time index of output, δ is lag index
382+
for n = 1:length(sigId)
383+
# --- At beginning, not possible to have all index
384+
nbMaxTap = min(n,nbTaps);
385+
# --- Classic time domain convolution
386+
for δ = 1:nbMaxTap
387+
@inbounds sigChan[n] += cir[n,δ] * sigId[n-δ+1];
388+
end
389+
end
390+
end
395391

392+
function timeVaryingConvTail!(sigChan, cir, buffEnd, nbSigSamples, nbTaps)
393+
for n = 1:nbTaps
394+
# --- Classic time domain convolution
395+
for δ = 1 : 1 : nbTaps
396+
@inbounds sigChan[nbSigSamples+n] += cir[end,δ] * buffEnd[n+nbTaps-δ+1];
397+
end
398+
end
399+
end

0 commit comments

Comments
 (0)