Injecting (and combining) a sine wave after a period of time

2 views (last 30 days)
Anis Fatini Abdul Aziz
Anis Fatini Abdul Aziz on 29 Mar 2021
Hello everyone,
So,I have this one signal of 100s seconds long. It is an EEG signal which looks very much like a random signal. I want to inject a sine wave tACS data (5s long sine wave) into it at 30s. But when I say injection, I didn't mean putting sine signal over another EEG signal. At the time 30-35 seconds, I wanted to combine the two signals via addition. Lastly, displaying the full 100s EEG signal with 30-35s: sine wave data (tACS)+EEG. I have attached few image to pictorially what I meant. Here is the current code, that I am working on:
load('Test_Sham_Alpha.mat');%load EEG data file
%plot(EEG.Time(1,1:46600)' , EEG.Data(1,1:46600)')
%define sine wave
%%Time specifications:
Fs = 500; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 5; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 5; % hertz
A= 0.001;
x = A*sin(2*pi*Fc*t);
% Plot the signal versus time:
%plot(t,x);%length t elements = 2500
%xlabel('time (in seconds)');
%title('tACS Signal');
%inject f 5 Hz tACS at time: 30 seconds of EEG data (Y= 30453934)
%for 5 seconds (25 cycles)
time= EEG.Time(1,1:46600)
for EEG.Time(1,15000:17500)%length of EEG.time =2501
%add y-axis value for both signals
y1= EEG.Data(1,1:46600);
y2= x
y= y1+y2
%i am not sure if the above make sense or now
%not sure how to continue
%for the figure: I wanted that the plot shows EEG of its full length data
%where between 30-35s of EEG, there is a signal combination (adding of tACS sine
%wave with the EEG)and the rest of EEG signal remained as it is
figure ('Name','Combined EEG+ tACS');
plot(t,y);%length t elements = 2500
xlabel('time (in seconds)');
I have also attached the EEG data that I extracted into an excel file (but only from 25s -40s because 100s is too big but it can easily be plot onto Matlab (fast too), but it is data that requires permission before posting it on public), if you have an idea on how to do it. There are other things that I want to add it on data: ramp-up features, and implementing envelope onto the signals etc. But before I go on to those things, I'd like to settle the basic issues. Note: I can do this on Excel but it couldn't handle that too much data, so I wanted to use maltab but I am not very good at the coding part. I am pretty sure it should be simple. I thought of cutting the datas and then concatenate them but I don't think that is efficient.
Please asisst me. I reallyyyy need help on this. I feel losst :'(

Answers (1)

Rohit Pappu
Rohit Pappu on 1 Apr 2021
A plausible solution is as follows
  • Generate the required sinusoidal signal
%define sine wave
%%Time specifications:
Fs = 500; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 5; % seconds
t = (0:dt:StopTime-dt); % seconds , assuming t is a 1xn vector to match the dimensions of EEG data
%%Sine wave:
Fc = 5; % hertz
A= 0.001;
x = A*sin(2*pi*Fc*t);
  • Select the EEG data corresponding to the time stamps required (In this case, index 15001 to 17500)
y_to_be_modified = EEG.Data(1,15001:17500);
  • Add the sine wave to the EEG data
y_injected = x+y_to_be_modified;
  • Replace the original EEG data section with this injected data
EEG.Data(1,15001:17500) = y_injected;
  • Plot the EEG Data
plot(EEG.Time(1,1:46600) , EEG.Data(1,1:46600))

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!