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

8 Ansichten (letzte 30 Tage)
Anis Fatini Abdul Aziz
Anis Fatini Abdul Aziz am 29 Mär. 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:
%figure;
%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
end
%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 :'(
Regards,
Anis

Antworten (1)

Rohit Pappu
Rohit Pappu am 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))
  18 Kommentare
Anis Fatini Abdul Aziz
Anis Fatini Abdul Aziz am 17 Apr. 2021
Okay so I tried something, but it looks so weird, like there is AM on the top part of the signal. Also, why are there no ramp up as I expect there would be? Idk T.T Please help, where did I do wrong. Here is my code:
load('Test_1mA_5Hz_Alpha.mat');%load EEG data file
scalingFactor = 10^-9
env_window = scalingFactor* EEG.Data(1,15001:45000)%window of interest for envelope extraction
t_window = EEG.Time(1,15001:45000)% 30 s to 90 s
t_ref = EEG.Time(1,1:50400)%entire signal from 0s to 100s
y_ref = scalingFactor*EEG.Data(1,1:50400)
figure (1);
plot( t_ref,y_ref )
title('Reference: EEG + 1mA 5Hz tACS Signal from Phantom Head')
xlabel ('Time, s');
ylabel ('Voltage, V');
%Using ROAST tACS voltage results recorded
%y-values of tacs is scaled from mV to V and transposed
load('channel_3_F3.mat');
mili =10^-3
tacs= mili*(q(1:30000,1)');
y_injected = tacs+y_to_be_modified; % Assuming x and y_to_be_modified have the same units ie. nV
EEG.Data(1,15001:45000) = y_injected;
figure(2);
plot(EEG.Time(1,1:46600) , EEG.Data(1,1:46600)) % Plots the entire signal
title('Combined EEG+ROAST-tACS')
xlabel ('Time,s');
ylabel ('Voltage, V');
figure(3)
[env_upper,env_lower] = envelope(env_window)
plot(t_window , env_window) % Plot the entire signal
hold on
plot(t_window, env_upper, t_window, env_lower) % Overlay the envelope on the above plot. Use line spec to change the line colors
hold off
title('Envelope of Referred Signal from Phantom Head')
xlabel ('Time,s');
ylabel ('Voltage, V');
%possible idea
%B_extract = B(30:90)
%Modulate Signal B with A ie. B_extract+A.*B_extract (Amplitude modulation)
load('Test_Sham_Alpha.mat');
EEG.Data = scalingFactor*EEG.Data;
am_mod = envelope(env_window) + y_to_be_modified.*envelope(env_window);
EEG.Data(1,15001:45000) = am_mod;
figure (4)
plot(EEG.Time(1,1:46600) , EEG.Data(1,1:46600))
title('Amplitude Modulated EEG+tACS Signal')
xlabel ('Time,s');
ylabel ('Voltage, V');
Please assist :'(
Anis Fatini Abdul Aziz
Anis Fatini Abdul Aziz am 21 Apr. 2021
does anyone know how?? please, it is still not working.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Biomedical Signal Processing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by