-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathhelperModClassFrameGenerator.m
More file actions
39 lines (33 loc) · 1.67 KB
/
Copy pathhelperModClassFrameGenerator.m
File metadata and controls
39 lines (33 loc) · 1.67 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
function y = helperModClassFrameGenerator(x, windowLength, stepSize, offset, sps)
%helperModClassFrameGenerator Generate frames for machine learning
% Y = helperModClassFrameGenerator(X,WLEN,STEP,OFFSET) segments the
% input, X, to generate frames to be used in machine learning algorithms.
% X must be a complex-valued column vector. The output, Y, is a size
% WLENxN complex-valued array, where N is the number of output frames.
% Each individual frame has WLEN samples. The window is progressed STEP
% samples for the new frame. STEP can be smaller or greater than WLEN.
% The function starts segmenting the input, X, after it calculates an
% initial offset based on the OFFSET value. OFFSET is a two-element
% real-valued vector, where the first element is the deterministic offset
% value and the second element is the maximum value of the random offset
% value. Total offset is OFFSET(1)+randi([0 OFFSET(2)]) samples. The
% deterministic part of the offset removes transients, while the random
% part enables the network to adapt to unknown delay values. Each frame
% is normalized to have unit energy.
%
% See also ModulationClassificationWithDeepLearning.
% Copyright 2018 The MathWorks, Inc.
numSamples = length(x);
numFrames = ...
floor(((numSamples-offset)-(windowLength-stepSize))/stepSize);
y = zeros([windowLength,numFrames],class(x));
startIdx = offset + randi([0 sps]);
frameCnt = 1;
while startIdx + windowLength < numSamples
xWindowed = x(startIdx+(0:windowLength-1),1);
framePower = sum(abs(xWindowed).^2);
xWindowed = xWindowed / sqrt(framePower);
y(:,frameCnt) = xWindowed;
frameCnt = frameCnt + 1;
startIdx = startIdx + stepSize;
end