Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds gaussian case #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions experiments_music.m
Original file line number Diff line number Diff line change
@@ -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))

37 changes: 37 additions & 0 deletions functions/generate_music_data.m
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions functions/generate_music_gaussian.m
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions functions/generate_music_stair.m
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions functions/generate_music_triangle.m
Original file line number Diff line number Diff line change
@@ -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