Minor bug fixes and code formatting
[100GbE-PON.git] / txFilter.m
CommitLineData
5117fc58
AIL
1function x = txFilter(modData, rolloff, span, sps)
2 %% Transmitter pulse-shaping (root raised cosine) filter.
3 %% Inputs:
4 %% - modData: modulated data
5 %% - rolloff: rolloff factor in root raised cosine filter.
6 %% - span: filter span (number of symbols)
7 %% - sps: samples per symbol
8 %% Output:
9 %% - x: pulse-shaped waveform
10
11 %% Construct filter object
12 txfilter = comm.RaisedCosineTransmitFilter...
13 ('Shape', 'Square root', ...
14 'RolloffFactor', rolloff, ...
15 'FilterSpanInSymbols', span, ...
16 'OutputSamplesPerSymbol', sps, ...
17 'Gain', sqrt(sps)); % so that output has energy 1
18
19 %% Extract filter coefficients
20 coef = coeffs(txfilter);
21 %% Upsample data and perform filtering in frequency domain
22 filter_fft = fft(coef.Numerator, length(modData) * sps);
23 modData_fft = fft(upsample(modData, sps));
24 x = ifft(modData_fft .* filter_fft.');
25 %% Re-order signal due to circular convolution
26 l = (length(coef.Numerator) - 1) / 2;
27 x = [x(l:end); x(1:l-1)];
28end