I am working on a senior design project for school, and I am using g.MobiLab+, Openvibe, and Matlab. I've gone through the tutorials and I am still unclear about how OpeVibe interfaces with multiple/different inputs and outputs when writing the Matlab script. I have essentially tried to get this working on the Tutorial 2 code, but it seems to fail every time. I've attached my scenario.Any assistance on the issue would be very helpful. Thanks!
Code: Select all
function box_out = EEG_Process(box_in)
for i = 1: OV_getNbPendingInputChunk(box_in,1)
if(~box_in.user_data.is_headerset)
% The output is the input + noise, only on first channel
box_in.outputs{1}.header = box_in.inputs{1}.header;
box_in.outputs{1}.header.n1_channels = 1;
box_in.outputs{1}.header.channel_names = {'Channel 1 '};
box_in.user_data.is_headerset = 1;
% We print the header in the console
disp('Input header is :')
box_in.inputs{1}.header
disp('Output header is :')
box_in.outputs{1}.header
end
% we increment the matrix count
box_in.user_data.n1_matrix_processed = box_in.user_data.n1_matrix_processed + 1;
[box_in, start_time, end_time, matrix_data] = OV_popInputBuffer(box_in,1
% Sample Frequency
Fs = box_in.inputs{1}.header.sampling_rate;
% Sample time
T = 1/Fs;
% Length of signal
L = box_in.inputs{1}.header.nb_samples_per_buffer;
% Time vector
t = (0:L-1)*T;
%{
We generate the requested sinusoid noise
noise_amplitude = box_in.settings(2).value;
noise_frequency = box_in.settings(1).value;
sinusoid = sin(2*pi* noise_frequency *t);
%}
% We add this sinus to the original signal on first channel only
sig = matrix_data(1,1:L);
%{
%subplot(2,1,1);
%plot(Fs*t,sinusoid)
%title('Noise')
%xlabel('time (seconds)')
%subplot(3,1,2);
%plot(Fs*t,sig)
%title('Signal Corrupted with the noise (channel 1)')
%xlabel('time (seconds)')
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(sig,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
fmin = box_in.settings(1).value;
fmax = box_in.settings(2).value;
%subplot(3,1,3)
plot(f(fmin*2:fmax*2),2*abs(Y(fmin*2:fmax*2)))
title('Single-Sided Amplitude Spectrum of EEG Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
%}
% we sum the FFT for later mean computation
if box_in.user_data.nb_matrix_processed == 1
box_in.user_data.mean_fft_matrix = Y;
else
box_in.user_data.mean_fft_matrix = box_in.user_data.mean_fft_matrix + Y;
end
box_in = OV_addOutputBuffer(box_in,1,start_time,end_time,sig);
end
for i = 1: OV_getNbPendingInputChunk(box_in,2)
if(~box_in.user_data.is_headerset)
% The output is the input + noise, only on first channel
box_in.outputs{2}.header = box_in.inputs{2}.header;
box_in.outputs{2}.header.nb_channels = 2;
box_in.outputs{2}.header.channel_names = {'FFT '};
box_in.user_data.is_headerset = 1;
% We print the header in the console
disp('Input header is :')
box_in.inputs{2}.header
disp('Output header is :')
box_in.outputs{2}.header
end
% we increment the matrix count
box_in.user_data.n2_matrix_processed = box_in.user_data.n2_matrix_processed + 1;
[box_in2, start_time, end_time, matrix_data2] = OV_popInputBuffer(box_in,2);
Fs = box_in.inputs{2}.header.sampling_rate; % Sampling frequency
T = 1/Fs; % Sample time
L = box_in.inputs{2}.header.nb_samples_per_buffer; % Length of signal
t = (0:L-1)*T; % Time vector
%{
We generate the requested sinusoid noise
noise_amplitude = box_in.settings(2).value;
noise_frequency = box_in.settings(1).value;
sinusoid = sin(2*pi* noise_frequency *t);
%}
% We add this sinus to the original signal on first channel only
sig = matrix_data(1:6,1:L);
%subplot(2,1,1);
%plot(Fs*t,sinusoid)
%title('Noise')
%xlabel('time (seconds)')
%subplot(3,1,2);
%plot(Fs*t,sig)
%title('Signal Corrupted with the noise (channel 1)')
%xlabel('time (seconds)')
% Plot single-sided amplitude spectrum.
fmin = box_in.settings(1).value;
fmax = box_in.settings(2).value;
%subplot(3,1,3)
plot(f(fmin*2:fmax*2),2*abs(Y(fmin*2:fmax*2)))
title('Single-Sided Amplitude Spectrum of EEG Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
% we sum the FFT for later mean computation
% Very first data group that comes through
if box_in.user_data.nb_matrix_processed == 1
box_in.user_data.mean_fft_matrix = Y;
else
% Remaining data that comes through
box_in.user_data.mean_fft_matrix = box_in.user_data.mean_fft_matrix + Y;
end
box_in = OV_addOutputBuffer(box_in,2,start_time,end_time,sig);
end
box_out = box_in;
box_out2 = box_in2;
end