-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathload_sine_wave_data.m
53 lines (40 loc) · 1.63 KB
/
load_sine_wave_data.m
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
%LOAD_SIN_WAVE_DATA Load data generated by a sine wave
%
% [DATA, CP] = LOAD_SINE_WAVE_DATA( LENGTH, AMPLITUDES, FREQUENCIES,
% SNRS)
%
% This function generates data of length DATA_LENGTH (default 10),
% as generated by sine wave(s).
%
% The segments are defined by AMPLITUDES, FREQUENCIES and SNRS.
% The first is a vector is amplitudes.
% The second argument is vector of frequencies for each segment
% The last argument is a vector which indicates the signal-to-noise ratio
% (modellen by gaussian-white-noise).
function [ datapoints, change_points ] = load_sine_wave_data( data_length, amplitudes, frequencies, snrs )
if nargin < 1; data_length = 10; end
if nargin < 2; amplitudes = [1 3 1 5 2]; end
if nargin < 3; frequencies = ones(length(amplitudes), 1) * 10; end
if nargin < 4; snrs = zeros(length(amplitudes), 1 ); end
if ~isequal(length(amplitudes), length(frequencies), length(snrs) )
error ('All input arguments must be of the same length');
end
datapoints = zeros(data_length, 1);
change_points = zeros(length(amplitudes), 1);
per_segment = ceil(data_length/ length(amplitudes));
i = 1;
for segment = 1 : length(amplitudes)
t = 1:0.001:per_segment;
a = amplitudes(segment);
f = frequencies(segment);
snr = snrs(segment);
y = a * sin(2 * pi * f * t);
if snr > 0
y = awgn(y, snrs(segment));
end
datapoints(i:i+length(y)-1) = y;
change_points(segment) = i;
i = i + length(y);
end
change_points(1) = [];
end