-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin2soundprime.m
44 lines (38 loc) · 1.08 KB
/
bin2soundprime.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
function sound_data = bin2sound(is_barker, bin , A, carrier_f, delta_f , w_duration, Fs)
sound_data = [];
if is_barker == 0
f0 = carrier_f - delta_f;
f1 = carrier_f + delta_f;
f2 = carrier_f - 2 * delta_f;
f3 = carrier_f + 2 * delta_f;
t = 0:(1/Fs):w_duration;
w0 = A*cos(2*pi * f0 * t);
w1 = A*cos(2*pi * f1 * t);
w2 = A*cos(2*pi * f2 * t);
w3 = A*cos(2*pi * f3 * t);
for i = size(bin)
if bin(1, i) == 0 && bin(1, i) == 0
sound_data = [sound_data, w0];
elseif bin(1, i) == 0 && bin(1, i) == 1
sound_data = [sound_data, w1];
elseif bin(1, i) == 1 && bin(1, i) == 0
sound_data = [sound_data, w2];
elseif bin(1, i) == 1 && bin(1, i) == 1
sound_data = [sound_data, w3];
end
end
elseif is_barker == 1
f0 = carrier_f - delta_f;
f1 = carrier_f + delta_f;
t = 0:(1/Fs):w_duration;
w0 = A*cos(2*pi * f0 * t);
w1 = A*cos(2*pi * f1 * t);
for i = bin
if i == 1
sound_data = [sound_data, w0];
elseif i == 0
sound_data = [sound_data, w1];
end
end
end
end