Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function [sin_5] = denoising_wl_sin(A, n, initial_sin)
%% denoising the nth column of cell A by subsampling and wavelet filtering, then fit the data using sine function.
%% initial_sin is the initial parameters for sine function fitting. it is a
%% vector [a, b ,c, d] which a is the ampl, b is the frequ, c is the phase,
%% d is the intercept.
% view2(:, 9:12) = denoising_wl_sin(conv_feature, 2, [20 2 3 70]);
maxiter = size(A, 2);
b = cell(1, maxiter);
%% subsampling
for i =1 : maxiter
temp = A{1, i};
conv_d = temp(:, n);
Leng = length(conv_d)/5;
if Leng~= floor(Leng)
conv_e = zeros(ceil(Leng) * 5, 1);
for j = 1 : length(conv_d)
conv_e(j) = conv_d(j);
end
conv_d = conv_e;
end
Mat = reshape(conv_d, 5, []);
aver_5 = sum(Mat, 1)/5;
if Leng~= floor(Leng)
aver_5(ceil(Leng)) = sum(Mat(:, end))/(length(temp(:,3))-floor(Leng) * 5);
end
aver_5 = aver_5';
b{1, i} = aver_5;
end
%% wavelet filtering
c = cell(size(b));
for i = 1 : length(b)
s = b{1, i};
l_s = length(s);
[cA1, cD1] = dwt(s,'haar');
A1= upcoef('a',cA1,'haar',1,l_s);
D1= upcoef('a',cD1,'haar',1,l_s);
% subplot(1,2,1); plot(A1); title('Approximation A1')
% subplot(1,2,2); plot(D1); title('Detail D1')
[thr,sorh,keepapp] = ddencmp('den','wv',s);
[C,L] = wavedec(s,1,'haar');
clean = wdencmp('gbl',C,L,'haar',1,1e06,sorh,keepapp);
% figure;
% subplot(2,1,1); plot(s); title('Original')
% subplot(2,1,2); plot(clean); title('denoised')
c{1, i} = clean;
end
% c{1,32}= c{1, 32}';
clean_conv_5 = c;
%% sine fitting
lengc = size(c, 2); % Number of users
A = zeros(lengc, 4);
A_result = cell(1, lengc);
for i = 1 : lengc
days = length(c{1, i});
axis_x = 1 : 5 : days*5;
axis_y = c{1, i}';
fx =@(a, t) a(1) * sin(2*pi*t/a(2)+a(3))+a(4);
A(i, :) = lsqcurvefit( fx, initial_sin, axis_x, axis_y);
A_res = fx(A(i, :), axis_x);
A_result{1, i} = A_res;
end
sin_5= A;
end