-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesignPulseShapingFilter.m
More file actions
70 lines (61 loc) · 2.31 KB
/
Copy pathdesignPulseShapingFilter.m
File metadata and controls
70 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [h, t] = designPulseShapingFilter(Ts, alpha, N_span, OSR, filterType)
% --- Filter Parameters ---
Tsample = Ts / OSR;
Ntaps = N_span * OSR + 1;
% Create time vector centered around 0
% It spans from -N_span*Ts/2 to +N_span*Ts/2
t = (-(Ntaps-1)/2 : (Ntaps-1)/2) * Tsample;
h = zeros(1, Ntaps);
tol = 1e-12;
xt = t / Ts;
% --- Generate Filter Coefficients ---
if strcmpi(filterType, 'RC')
for i = 1:Ntaps
x_curr = xt(i);
if abs(alpha) < tol
h(i) = sinc(x_curr);
else
if abs(x_curr) < tol
h(i) = 1.0;
elseif abs(abs(x_curr) - 1/(2*alpha)) < tol
h(i) = (alpha/2) * sin(pi/(2*alpha));
else
% Standard RC formula
numerator_rc = cos(pi * alpha * x_curr);
denominator_rc = (1 - (2 * alpha * x_curr)^2);
if abs(denominator_rc) < tol
h(i) = 0;
else
h(i) = sinc(x_curr) * (numerator_rc / denominator_rc);
end
end
end
end
elseif strcmpi(filterType, 'RRC')
for i = 1:Ntaps
x_curr = xt(i);
if abs(alpha) < tol
h(i) = sinc(x_curr);
else
if abs(x_curr) < tol
h(i) = (1 - alpha + 4*alpha/pi);
elseif abs(abs(x_curr) - 1/(4*alpha)) < tol
h(i) = (alpha/sqrt(2)) * ( (1 + 2/pi)*sin(pi/(4*alpha)) + ...
(1 - 2/pi)*cos(pi/(4*alpha)) );
else
% Standard RRC formula
numerator_rrc = sin(pi*x_curr*(1-alpha)) + 4*alpha*x_curr .* cos(pi*x_curr*(1+alpha));
denominator_rrc = pi*x_curr .* (1 - (4*alpha*x_curr).^2);
if abs(denominator_rrc) < tol
h(i) = 0;
else
h(i) = numerator_rrc / denominator_rrc;
end
end
end
end
if any(h)
h = h / sqrt(sum(h.^2));
end
end
end