Skip to content

Commit 31d48a7

Browse files
committed
Adding raised cosine and sqrt raised cosine filter templates
1 parent ad3958c commit 31d48a7

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

src/DigitalComm.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ include("Channel/addCFO.jl")
5353
export addCFO
5454
export addCFO!
5555

56+
# --- Raised cosine filters
57+
include("raisedCosine.jl")
58+
export raisedCosine
59+
export sqrtRaisedCosine
60+
5661

5762
# ----------------------------------------------------
5863
# --- Function definition

src/raisedCosine.jl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
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
3+
Output is a Vector{Float64} array of size L= 2KN+1 \n
4+
SRRC definition is based on [1] \n
5+
[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
6+
Syntax \n
7+
h = raisedCosine(N,beta,ovS)
8+
Input parameters \n
9+
- N : Symbol span (Int16)
10+
- beta : Roll-off factor (Float64)
11+
- ovS : Oversampling rate (Int16)
12+
"""
13+
function raisedCosine(N,beta,ovS)
14+
# --- Final size of filter
15+
nbTaps = 2 * N * ovS + 1;
16+
# --- Init output
17+
h = zeros(Float64,nbTaps);
18+
counter = 0;
19+
# --- Iterative SRRC definition
20+
for k = -N*ovS : 1 : N*ovS
21+
counter = counter + 1;
22+
if k == 0
23+
## First singular point at t=0
24+
h[counter] = 1;#(1-beta) + 3*beta/pi;
25+
elseif abs(k) == ovS / (2*beta);
26+
## Second possible singular point
27+
h[counter] = pi/4*sin(pi/(2beta))/(pi/(2beta));
28+
else
29+
## Classic SRRC formulation (see [1])
30+
h[counter] = sin(pi*k/ovS)/(pi*k/ovS) * cos(pi*beta*k/ovS)/(1- 4beta^2*(k/ovS)^2);
31+
end
32+
end
33+
return h
34+
end
35+
36+
37+
"""
38+
Returns the Finite Impulse Response of a Square Root Raised Cosine (SRRC) filter. \n
39+
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
40+
Output is a Vector{Float64} array of size L= 2KN+1\n
41+
SRRC definition is based on [1]\n
42+
[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
43+
Syntax\n
44+
h = sqrtRaisedCosine(N,beta,ovS) \n
45+
Input parameters \n
46+
- N : Symbol span (Int16)
47+
- beta : Roll-off factor (Float64)
48+
- ovS : Oversampling rate (Int16)
49+
"""
50+
function sqrtRaisedCosine(N,beta,ovS)
51+
# --- Final size of filter
52+
nbTaps = 2 * N * ovS + 1;
53+
# --- Init output
54+
h = zeros(Float64,nbTaps);
55+
counter = 0;
56+
# --- Iterative SRRC definition
57+
for k = -N*ovS : 1 : N*ovS
58+
counter = counter + 1;
59+
if k == 0
60+
## First singular point at t=0
61+
h[counter] = (1-beta) + 4*beta/pi;
62+
elseif abs(k) == ovS / (4*beta);
63+
## Second possible singular point
64+
h[counter] = beta/sqrt(2)*( (1+2/pi)sin(pi/(4beta))+(1-2/pi)cos(pi/(4beta)));
65+
else
66+
## Classic SRRC formulation (see [1])
67+
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) );
68+
end
69+
end
70+
# --- Max @ h[0]
71+
h = h ./ maximum(h)
72+
return h
73+
end

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ include("test_hardConstellation.jl");
1818
# Symbol demapper
1919
include("test_symbolDemapper.jl");
2020

21-
2221
# AWGN
2322
include("test_addNoise.jl");
2423

2524
# Test Waveforms
2625
include("test_waveforms.jl");
26+
27+
# Test filters
28+
include("test_filters.jl")

test/test_filters.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ----------------------------------------------------
2+
# --- Import modules
3+
# ----------------------------------------------------
4+
using DigitalComm
5+
using DSP
6+
using Test
7+
# ----------------------------------------------------
8+
# --- Tests
9+
# ----------------------------------------------------
10+
println("Tests for filters");
11+
@testset "Raised Cosine filter test" begin
12+
# Create the vector
13+
h = raisedCosine(12,0.5,16)
14+
# Check type
15+
@test h isa Vector{Float64}
16+
# Check size
17+
sH = 12*16*2+1
18+
@test length(h)== sH
19+
# Check it is 1 in the middle
20+
@test h[1+ (sH-1)÷2] == 1
21+
# Check Nyquist criterion
22+
for n 0 : 11
23+
@test (h[1 + n*16],0,atol=1e-8)
24+
end
25+
end
26+
27+
@testset "Raised Cosine filter test" begin
28+
# Create the vector
29+
h = sqrtRaisedCosine(12,0.5,16)
30+
# Check type
31+
@test h isa Vector{Float64}
32+
# Check size
33+
sH = 12*16*2+1
34+
@test length(h)== sH
35+
# Check it is 1 in the middle
36+
@test h[1+ (sH-1)÷2] == 1
37+
# Check Nyquist criterion
38+
# sqrt is not a Nyquist filter but h*h is !
39+
p = conv(h,h)
40+
p = p /maximum(p)
41+
for n 0 : 2*11
42+
@test (p[1 + n*16],0,atol=1e-4)
43+
end
44+
end

0 commit comments

Comments
 (0)