Skip to content

Commit

Permalink
Adding raised cosine and sqrt raised cosine filter templates
Browse files Browse the repository at this point in the history
  • Loading branch information
RGerzaguet committed Nov 2, 2021
1 parent ad3958c commit 31d48a7
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/DigitalComm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ include("Channel/addCFO.jl")
export addCFO
export addCFO!

# --- Raised cosine filters
include("raisedCosine.jl")
export raisedCosine
export sqrtRaisedCosine


# ----------------------------------------------------
# --- Function definition
Expand Down
73 changes: 73 additions & 0 deletions src/raisedCosine.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Returns the Finite Impulse Response of a Raised Cosine (RC) filter. The filter is defined by its span (evaluated in number of symbol N), its Roll-Off factor and its oversampling factor. The span corresponds to the number of symbol affected by filter before and after the center point.\n
Output is a Vector{Float64} array of size L= 2KN+1 \n
SRRC definition is based on [1] \n
[1] 3GPP TS 25.104 V6.8.0 (2004-12). http://www.3gpp.org/ftp/Specs/archive/25_series/25.104/25104-680.zip \n
Syntax \n
h = raisedCosine(N,beta,ovS)
Input parameters \n
- N : Symbol span (Int16)
- beta : Roll-off factor (Float64)
- ovS : Oversampling rate (Int16)
"""
function raisedCosine(N,beta,ovS)
# --- Final size of filter
nbTaps = 2 * N * ovS + 1;
# --- Init output
h = zeros(Float64,nbTaps);
counter = 0;
# --- Iterative SRRC definition
for k = -N*ovS : 1 : N*ovS
counter = counter + 1;
if k == 0
## First singular point at t=0
h[counter] = 1;#(1-beta) + 3*beta/pi;
elseif abs(k) == ovS / (2*beta);
## Second possible singular point
h[counter] = pi/4*sin(pi/(2beta))/(pi/(2beta));
else
## Classic SRRC formulation (see [1])
h[counter] = sin(pi*k/ovS)/(pi*k/ovS) * cos(pi*beta*k/ovS)/(1- 4beta^2*(k/ovS)^2);
end
end
return h
end


"""
Returns the Finite Impulse Response of a Square Root Raised Cosine (SRRC) filter. \n
The filter is defined by its span (evaluated in number of symbol N), its Roll-Off factor and its oversampling factor. The span corresponds to the number of symbol affected by filter before and after the center point.\n
Output is a Vector{Float64} array of size L= 2KN+1\n
SRRC definition is based on [1]\n
[1] 3GPP TS 25.104 V6.8.0 (2004-12). http://www.3gpp.org/ftp/ Specs/archive/25_series/25.104/25104-680.zip\n
Syntax\n
h = sqrtRaisedCosine(N,beta,ovS) \n
Input parameters \n
- N : Symbol span (Int16)
- beta : Roll-off factor (Float64)
- ovS : Oversampling rate (Int16)
"""
function sqrtRaisedCosine(N,beta,ovS)
# --- Final size of filter
nbTaps = 2 * N * ovS + 1;
# --- Init output
h = zeros(Float64,nbTaps);
counter = 0;
# --- Iterative SRRC definition
for k = -N*ovS : 1 : N*ovS
counter = counter + 1;
if k == 0
## First singular point at t=0
h[counter] = (1-beta) + 4*beta/pi;
elseif abs(k) == ovS / (4*beta);
## Second possible singular point
h[counter] = beta/sqrt(2)*( (1+2/pi)sin(pi/(4beta))+(1-2/pi)cos(pi/(4beta)));
else
## Classic SRRC formulation (see [1])
h[counter] = ( sin(pi*k/ovS*(1-beta)) + 4beta*k/ovS*cos(pi*k/ovS*(1+beta))) / (pi*k/ovS*(1- (4beta*k/ovS)^2) );
end
end
# --- Max @ h[0]
h = h ./ maximum(h)
return h
end
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ include("test_hardConstellation.jl");
# Symbol demapper
include("test_symbolDemapper.jl");


# AWGN
include("test_addNoise.jl");

# Test Waveforms
include("test_waveforms.jl");

# Test filters
include("test_filters.jl")
44 changes: 44 additions & 0 deletions test/test_filters.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ----------------------------------------------------
# --- Import modules
# ----------------------------------------------------
using DigitalComm
using DSP
using Test
# ----------------------------------------------------
# --- Tests
# ----------------------------------------------------
println("Tests for filters");
@testset "Raised Cosine filter test" begin
# Create the vector
h = raisedCosine(12,0.5,16)
# Check type
@test h isa Vector{Float64}
# Check size
sH = 12*16*2+1
@test length(h)== sH
# Check it is 1 in the middle
@test h[1+ (sH-1)÷2] == 1
# Check Nyquist criterion
for n 0 : 11
@test (h[1 + n*16],0,atol=1e-8)
end
end

@testset "Raised Cosine filter test" begin
# Create the vector
h = sqrtRaisedCosine(12,0.5,16)
# Check type
@test h isa Vector{Float64}
# Check size
sH = 12*16*2+1
@test length(h)== sH
# Check it is 1 in the middle
@test h[1+ (sH-1)÷2] == 1
# Check Nyquist criterion
# sqrt is not a Nyquist filter but h*h is !
p = conv(h,h)
p = p /maximum(p)
for n 0 : 2*11
@test (p[1 + n*16],0,atol=1e-4)
end
end

2 comments on commit 31d48a7

@RGerzaguet
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/47997

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.5 -m "<description of version>" 31d48a7a83a6b7abb1bd29b78dabb9961e3ab890
git push origin v1.0.5

Please sign in to comment.