forked from wallacelab22/Human_AV_Motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeCAM_and_NOISE_update.m
104 lines (91 loc) · 4.02 KB
/
makeCAM_and_NOISE_update.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function [CAM, speaker2_6_noise, speaker3_7_noise, speaker4_8_noise] = makeCAM_and_NOISE_update(cLvl, dur, silence, Fs, noise_reduction_scalar)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CAM = array of voltages to present to speakers %
% cLvl = coherence level (between 0 and 1) %
% speed = an abandoned way to slow or speed the motion stimuli. %
% direction = explanatory. 1 = leftward motion. %
% dur = duration of stimuli in seconds. Can accept decimals, %
% but for uneven durations, you may need to round the Fs*t %
% operation when generating duration in samples
% silence = period of silence at the beggin of the sound in seconds
% Fs = Sampling frequency %
% speaker2_6_noise = uncorrelated and correlated noise to be played
% out of diagonal upper right and diagonal lower left %
% speakers
% speaker3_7_noise = uncorrelated and correlated noise to be played %
% out of upper and lower speakers
% speaker4_8_noise = uncorrelated and correlated noise to be played %
% out of diagonal upper left and diagonal lower right
% speakers %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n_speakers = 8;
dB_speaker_reduction = 10*log10(n_speakers);
n_speaker_reduction_scalar = 10^(-(dB_speaker_reduction)/20);
dB_noise_reduction = NaN;
n_noise_reduction_scalar = 10^(-(dB_noise_reduction)/20);
% Calculate duration in samples. Rounding is unnessesary if you have an
% even duration (one that doesn't produce a decimal when multiplying by Fs)
samples = round(dur.*Fs);
silent = zeros((silence.*Fs),2);
% Generate the 4 noise signals
N1 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N2 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N3 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N4 = rand(samples,1)-.5;
N5 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N6 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N7 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N8 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
N9 = (rand(samples,1)-.5)*n_speaker_reduction_scalar;
% Generate noise signals of 0, 100, and 50% correlation
leftright_n0 = [N1 N2];
updown_n0 = [N3 N5];
diag45_225_n0 = [N6 N7];
diag135_315_n0 = [N8 N9];
% Unused array of all noises together
Y = [n0 n50 n100];
% Generate ramp for increasing and decreasing N4 amplitute in speaker
rampu = (1/samples:1/samples:1)';
rampd = (1:-1/samples:1/samples)';
% Convolve the ramps with N4
nup = N4 .* rampu;
ndown = N4 .* rampd;
% Generate the leftward and rightward motion signal
left = [nup ndown];
right = [ndown nup];
% Apply the proper motion
if direction == 1
motion = right;
else
motion = left;
end
% Titrates the SNR
% Noise for each speaker
if cLvl <.5
speaker2_6_noise = leftright_n0;
speaker1_5_noise = diag45_225_n0;
speaker4_8_noise = updown_n0;
speaker3_7_noise = diag135_315_n0;
motion = motion.*cLvl.*2;
CAM = speaker2_6_noise + motion;
else
speaker2_6_noise = leftright_n0.*(1-cLvl).*2;
speaker1_5_noise = diag45_225_n0.*(1-cLvl).*2;
speaker4_8_noise = updown_n0.*(1-cLvl).*2;
speaker3_7_noise = diag135_315_n0.*(1-cLvl).*2;
CAM = speaker2_6_noise + motion;
end
% Applies an onset and offset ramped "gate"
CAM = makeramp(dur,Fs,CAM);
speaker1_5_noise = makeramp(dur,Fs,speaker1_5_noise);
speaker3_7_noise = makeramp(dur,Fs,speaker3_7_noise);
speaker4_8_noise = makeramp(dur,Fs,speaker4_8_noise);
% Scales the signal (and noise speakers) between -1 and 1
CAM = normalize(CAM);
CAM = cat(1, silent, CAM);
speaker1_5_noise = normalize(speaker1_5_noise);
speaker1_5_noise = cat(1, silent, speaker1_5_noise);
speaker3_7_noise = normalize(speaker3_7_noise);
speaker3_7_noise = cat(1, silent, speaker3_7_noise);
speaker4_8_noise = normalize(speaker4_8_noise);
speaker4_8_noise = cat(1, silent, speaker4_8_noise);