-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding efficient methods for CFO application
- Loading branch information
1 parent
f84e389
commit ad3958c
Showing
3 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Adding Carrier Frequency Offset δ in Hz to the input signal x sampled at frequency samplingRate (In Hz) with initial phase ϕ (default 0) | ||
This function does not mutate the input signal. See addCFO! for mutating function. | ||
In case you want to add normalized CFO, set the samplingRate to 1. | ||
# --- Syntax | ||
y = addCFO(x,delta,samplingRate) | ||
# --- Input parameters | ||
- x : Input signal | ||
- δ : Carrier frequency offset [Hz] | ||
- samplingRate : Sampling rate [Hz] | ||
# --- Output parameters | ||
- y : Signal with CFO | ||
""" | ||
function addCFO(x::Union{AbstractVector{Complex{T}},AbstractVector{T}},δ,samplingRate,ϕ=0) where T | ||
y = zeros(Complex{T},length(x)) | ||
addCFO!(y,x,δ,samplingRate,ϕ) | ||
return y | ||
end | ||
|
||
function addCFO!(y::AbstractVector{Complex{T}},x::AbstractVector,δ::Number,samplingRate::Number,ϕ=0) where T | ||
# --- Basic array check | ||
@assert length(x) == length(y) "Input and output should have same length (here input x is $(length(x)) and pre-allocated output has size $(length(y))" | ||
# --- CFO pulsation | ||
ω = δ / samplingRate | ||
# --- Adding CFO | ||
@inbounds @simd for n ∈ eachindex(x) | ||
y[n] = x[n] * Complex{T}(exp(2im*π*ω*( (n-1) + ϕ))) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters