From 96fa2b3f394d08d4d94f00dc02393cfa9df35d3b Mon Sep 17 00:00:00 2001 From: charles sutton Date: Sun, 15 Oct 2017 15:04:10 +0200 Subject: [PATCH 1/4] Adds gaussian case --- functions/generate_music_data.m | 37 +++++++++++++++++++++++++ functions/generate_music_gaussian.m | 43 +++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 functions/generate_music_data.m create mode 100644 functions/generate_music_gaussian.m diff --git a/functions/generate_music_data.m b/functions/generate_music_data.m new file mode 100644 index 0000000..278a8c8 --- /dev/null +++ b/functions/generate_music_data.m @@ -0,0 +1,37 @@ + +% this function wraps all data generating functions for the project +% badly coded from generate_data +function [data] = generate_music_data(data_options) + +% set default values for empty fields +% elementary signal +if ~isfield(data_options,'type') data_options.type = 'gaussian'; end +if ~isfield(data_options,'width') data_options.width = 0.1; end +if ~isfield(data_options,'noise_level') data_options.width = 0.1; end + +%dataset +if ~isfield(data_options,'n') data_options.n = 1000; end +if ~isfield(data_options,'D') data_options.D = 50; end +%if ~isfield(data_options,'k') data_options.k = 2; end +if ~isfield(data_options,'mu') data_options.mu = [0.25, 0.75]; end +if ~isfield(data_options,'circular') data_options.circular = 'on'; end + +data_options.gain = 'on'; + +if ~isfield(data_options,'seed') data_options.seed = 555; end + +switch data_options.type + case 'gaussian' + data = generate_music_gaussian(data_options); + case 'triangle' + data = generate_music_triangle(data_options); + case 'stair' + data = generate_music_stair(data_options); + +end +% adding gaussian noise on data +if data_options.noise_level > 0 + data = data + data_options.noise_level * randn(data_options.n, data_options.D); +end + +end \ No newline at end of file diff --git a/functions/generate_music_gaussian.m b/functions/generate_music_gaussian.m new file mode 100644 index 0000000..dc2c360 --- /dev/null +++ b/functions/generate_music_gaussian.m @@ -0,0 +1,43 @@ +% badly coded from generate gaussian +function [ data ] = generate_music_gaussian(data_options) +% this function generates a dataset of gaussian signals given the data_options +% parameters : +% n - size of the dataset +% D - num of sample points in the range [-1,1] +% mu - delay parameters +% width - the std parameter given to the normalpdf function +% circular : 'on' means the interval is circular and so overlap +% gain : add rayleigh gain + +data = zeros(data_options.n,data_options.D); +I = linspace(-1,1,data_options.D); + +if strcmpi(data_options.circular,'on') + %case circular + half_width = norminv(0.99,0,data_options.width); % disclaimer, in the gaussian case, half width is not witdh/2 + half_width_sample = round(0.5*half_width * data_options.D); + I_extended = linspace(-1 - half_width , 1 + half_width , data_options.D + 2*half_width_sample); + data_extended = zeros(data_options.n, data_options.D + 2*half_width_sample); + for mu = data_options.mu + for j = 1:data_options.n + gain = raylrnd(sqrt(2/pi)); + data_extended(j,:) = data_extended(j,:) + gain * normpdf(I_extended, mu, data_options.width); + end + end + + data = data_extended(:,half_width_sample+1:data_options.D + half_width_sample); + data(:,1:half_width_sample) = data(:,1:half_width_sample) + data_extended(:,data_options.D + half_width_sample+1 : data_options.D + 2*half_width_sample); + data(:, data_options.D - half_width_sample + 1 : data_options.D ) = data(:, data_options.D - half_width_sample + 1 : data_options.D ) + data_extended(:, 1 : half_width_sample ); + +else + + for mu = data_options.mu + for j = 1:data_options.n + gain = raylrnd(sqrt(2/pi)); + data(j,:) = data(j,:) + gain * normpdf(I, mu, data_options.width); + end + end + +end + +end \ No newline at end of file From 6662e1ce0f0d18b51e78d171dc768b79fc5167cb Mon Sep 17 00:00:00 2001 From: charles sutton Date: Sun, 15 Oct 2017 15:11:19 +0200 Subject: [PATCH 2/4] adapt to triangle data --- functions/generate_music_triangle.m | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 functions/generate_music_triangle.m diff --git a/functions/generate_music_triangle.m b/functions/generate_music_triangle.m new file mode 100644 index 0000000..5c06bd2 --- /dev/null +++ b/functions/generate_music_triangle.m @@ -0,0 +1,56 @@ +function [ data ] = generate_music_triangle(data_options) +% this function generates a dataset of triangle signals given the data_options +% parameters : +% n - size of the dataset +% D - num of sample points in the range [-1,1] +% k - num of triangle summed +% width - the half width of a triangle +% circular : 'on' means the interval is circular and so overlap +% gain : 'on' means we add rayleigh gain + +data = zeros(data_options.n,data_options.D); +I = linspace(-1,1,data_options.D); + +if strcmpi(data_options.circular,'on') + %case circular + half_width = data_options.width; % disclaimer, in the triangle case, half width is not witdh/2 + half_width_sample = round( 0.5* half_width * data_options.D)+1; % convert number of sample points + I_extended = linspace(-1 - half_width , 1 + half_width , data_options.D + 2*half_width_sample); + data_extended = zeros(data_options.n, data_options.D + 2*half_width_sample); + for middle_point = data_options.mu + for j = 1:data_options.n + gain = raylrnd(sqrt(2/pi)); + + middle_point_idx = find(I_extended > middle_point,1); + start_point_idx = find(I_extended > middle_point - data_options.width,1); + end_point_idx = find(I_extended > middle_point + data_options.width,1)-1; + + data_extended(j,start_point_idx:middle_point_idx) = data_extended(j,start_point_idx:middle_point_idx) + (gain/data_options.width^2)*(I_extended(start_point_idx:middle_point_idx) - I_extended(start_point_idx)); + + data_extended(j,middle_point_idx+1:end_point_idx) = data_extended(j,middle_point_idx+1:end_point_idx) - (gain/data_options.width^2)*(I_extended(middle_point_idx+1:end_point_idx) - I_extended(end_point_idx)); + end + end + + data = data_extended(:,half_width_sample+1:data_options.D + half_width_sample); + data(:,1:half_width_sample) = data(:,1:half_width_sample) + data_extended(:,data_options.D + half_width_sample+1 : data_options.D + 2*half_width_sample); + data(:, data_options.D - half_width_sample + 1 : data_options.D ) = data(:, data_options.D - half_width_sample + 1 : data_options.D ) + data_extended(:, 1 : half_width_sample ); +else + + for middle_point = data_options.mu + for j = 1:data_options.n + + gain = raylrnd(sqrt(2/pi)); + + middle_point_idx = find(I > middle_point,1); + start_point_idx = find(I > middle_point - data_options.width,1); + end_point_idx = find(I>middle_point + data_options.width,1)-1; + + data(j,start_point_idx:middle_point_idx) = data(j,start_point_idx:middle_point_idx) + (gain/data_options.width^2)*(I(start_point_idx:middle_point_idx) - I(start_point_idx)); + data(j,middle_point_idx+1:end_point_idx) = data(j,middle_point_idx+1:end_point_idx) - (gain/data_options.width^2)*(I(middle_point_idx+1:end_point_idx) - I(end_point_idx)); + end + end + +end + + +end \ No newline at end of file From 3f07821e5d5f55413099131c4d4a5956fc2e4ec4 Mon Sep 17 00:00:00 2001 From: charles sutton Date: Sun, 15 Oct 2017 15:15:06 +0200 Subject: [PATCH 3/4] adapt to stair data --- functions/generate_music_stair.m | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 functions/generate_music_stair.m diff --git a/functions/generate_music_stair.m b/functions/generate_music_stair.m new file mode 100644 index 0000000..c9dd3f5 --- /dev/null +++ b/functions/generate_music_stair.m @@ -0,0 +1,54 @@ +%badly coded from generate_stair.m +function [ data ] = generate_stair(data_options) +% this function generates a dataset of stair signals given the data_options +% parameters : +% n - size of the dataset +% D - num of sample points in the range [-1,1] +% mu - +% width - the half width of a stair +% circular : 'on' means the interval is circular and so overlap +% gain : 'on' means we add rayleigh gain + +data = zeros(data_options.n,data_options.D); +I = linspace(-1,1,data_options.D); + +if strcmpi(data_options.circular,'on') + %case circular + half_width = data_options.width / 2 ; + half_width_sample = round( 0.5* half_width * data_options.D)+1; % convert number of sample points + I_extended = linspace(-1 - half_width , 1 + half_width , data_options.D + 2*half_width_sample); + data_extended = zeros(data_options.n, data_options.D + 2*half_width_sample); + for start_point = data_options.mu + for j = 1:data_options.n + + gain = raylrnd(sqrt(2/pi)); + + start_point_idx = find(I_extended > start_point,1); + end_point_idx = find(I_extended > start_point+data_options.width,1); + + data_extended(j,start_point_idx:end_point_idx) = data_extended(j,start_point_idx:end_point_idx) + gain / data_options.width; + + end + end + + data = data_extended(:,half_width_sample+1:data_options.D + half_width_sample); + data(:,1:half_width_sample) = data(:,1:half_width_sample) + data_extended(:,data_options.D + half_width_sample+1 : data_options.D + 2*half_width_sample); + data(:, data_options.D - half_width_sample + 1 : data_options.D ) = data(:, data_options.D - half_width_sample + 1 : data_options.D ) + data_extended(:, 1 : half_width_sample ); +else + + for start_point = data_options.mu + for j = 1:data_options.n + + gain = raylrnd(sqrt(2/pi)); + + start_point_idx = find(I > start_point,1); + end_point_idx = find(I>start_point+data_options.width,1); + + data(j,start_point_idx:end_point_idx) = data(j,start_point_idx:end_point_idx) + gain / data_options.width; + end + end + +end + + +end \ No newline at end of file From 9743c7de8f6817a8193e5723b5020e14712fe5f3 Mon Sep 17 00:00:00 2001 From: charles sutton Date: Sun, 15 Oct 2017 23:24:53 +0200 Subject: [PATCH 4/4] add music experimentation --- experiments_music.m | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 experiments_music.m diff --git a/experiments_music.m b/experiments_music.m new file mode 100644 index 0000000..41fbf35 --- /dev/null +++ b/experiments_music.m @@ -0,0 +1,42 @@ +%% Parameters data +clear all +close all +clc +tic +%diary('/Users/Code/Desktop/hello_diary') +%diary on +data_options = struct(); +data_options.type = 'gaussian'; +data_options.noise_level = 0.1; +data_options.mu = [-0.5, 0, 0.9]; +data_options.n = 5000; +data_options.D = 200; +data_options.gain = 'on'; +data_options.circular = 'on'; +data_options.width = 0.1; + +data_options.neigh = 1000; +data_options.tries = 50; +%% Parameters algo +radius_options = struct('it',5,'it_end',2,'it_start',5,'it_mid',4); + +%% Subsampling options +sub_options = struct('state',true,'nb',round(sqrt(data_options.n))); + +%% Plotting options +plt_options = struct('sample',true,'avg',true,'msvd',true,'rmsvd',true); + +%% Generating dataset of pulses +noisy_data = generate_music_data(data_options); +%% plot +I = linspace(-1,1,data_options.D); +close all +for i=50:55 +plot(I,noisy_data(i,:)) +hold on +end + +%% MUSIC + +pmusic(noisy_data, length(data_options.mu)) +