-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhard_thresholding.m
40 lines (33 loc) · 901 Bytes
/
hard_thresholding.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
function s = hard_thresholding(a, k)
% HARD_THRESHOLDING performs the thresholding of the input Gabor
% coefficients, while taking into account the complex conjugacy.
%
% This means that approximately k pairs of coefficients are chosen
% (depending on whether the DC coefficient is kept), such that synthesis of
% s produces a real signal.
%
% Date: 29/07/2020
% By Ondrej Mokry, Pavel Zaviska
% Brno University of Technology
% Contact: [email protected]
odd = mod(length(a),2);
% taking only half of the spectrum + dc coefficient
a = a(1:floor(length(a)/2)+1);
a(1) = a(1)/2;
% sorting them
[~, ind] = sort(abs(a), 'descend');
s = zeros(length(a),1);
if k < length(a)
s(ind(1:k)) = a(ind(1:k));
else
s = a;
end
% compute conjugates of selected coefficients
s(1) = s(1)*2;
if odd
s_conj = conj(flip(s(2:end)));
else
s_conj = conj(flip(s(2:end-1)));
end
s = [s; s_conj];
end