adding noise to an ecg signal

Hi,
I am trying to add 50Hz noise to an ECG signal (imported from ASCII file) so that I can test my 50Hz notch filter. I have plotted my ECG data and have designed my '50Hz noise sinusoid' but how do I go about adding the noise to the signal?
I am a novice at MATLAB so any help would be great.
PS - I have tried +, and plotting together but the problem seems to be about the matrices not matching?
Thanks in advance
Katherine

Answers (3)

I would do something like this:
% Sampling
fs = 1000;
Ts = 1/fs;
% Time vector
t = 1:Ts:10-Ts;
% Signal
f = 1; % Frequency [Hz]
a = 1; % Amplitude
signal = sin(2*pi.*t.*f); % Sample sinusoidal signal. Your ECG signal goes here.
% Noise
fNoise = 50; % Frequency [Hz]
aNoise = 0.25; % Amplitude
noise = aNoise*sin(2*pi.*t.*fNoise);
% Signal + Noise
signalNoise = signal + noise;
% Plots
figure();
subplot(3,1,1);
plot(t, signal);
xlabel('Time [s]');
ylabel('Amplitude');
title('Original signal');
subplot(3,1,2);
plot(t, noise);
xlabel('Time [s]');
ylabel('Amplitude');
title('Noise');
subplot(3,1,3);
plot(t, signalNoise);
xlabel('Time [s]');
ylabel('Amplitude');
title('Original signal + Noise');
The trick is that your noise signal must have the same length than your ECG signal. If you do it this way, you can warranty that. Try it and let me know if it works ;-)

9 Comments

Thanks so much for your help!
I am still having an issue using your answer. I know that my ECG signal has 10,000 data points (i.e. 10 seconds of data at 1000 Hz).
When using your code, I am adjusting the t for the noise so that it has the same length as my own signal:
% Sampling
fs = 10000;
Ts = 1/fs;
% Time vector
t = 1:10000; time vector for our data
% Signal
f = 1; % Frequency [Hz]
a = 1; % Amplitude
signal = Channel_9; % Our ECG signal
% Noise
fNoise = 50; % Frequency [Hz]
aNoise = 0.25; % Amplitude
noise = aNoise*sin(2*pi*t.*fNoise);
% Signal + Noise
signalNoise = signal + noise;
I am getting the error at this point:
Error in ==> Testfilter at 19
signalNoise = signal + noise;
Error using ==> plus
Matrix dimensions must agree.
Any advice?
Thanks again!!
Sorry the frequency of the signal should say 1000Hz, typo just!
Do you have the ECG .mat file so I could try it? I am almost sure the problem is there. Send it to my email amt015@gmail.com ;-)
Sir Can we realize the popular noises of ECG signals like EMG, Powerline interference and baseline drift using matlab? I am working on de-noising of ECG signal using matlab and wanted to add these noises to my ECG signal and view the results. Can you please help me sir! I will be grate full to you if you can help me in any means. Thankyou sir
hello my friend ..I am trying to do the same thing here so could you help me plz if you found any thing.
Aparna Gupta comments to Arturo Moncada-Torres:
sir ,i have EEG .mat file n i want to add noise into that EEG signal.Can you please help me?
Aparna Gupta: please note that Arturo Moncada-Torres will not be notified about your comment. As Arturo posted 6 years ago, it is unlikely that Arturo is following the discussion any more.
Dear @Walter Roberson sir, Sir can u help me with my queries??
actually a sinusoidal signal is adding to other sinusoidal signal
but the same not working instead same ecg signal is appearing
what could be the reason

Sign in to comment.

Fangjun Jiang
Fangjun Jiang on 15 Jul 2011
You must have you ECG signal data. You need to know the time step of the data,i.e. what is the elapsed time between the first data and second data. Then you need to know the length of your ECG signal, i.e. how many total time does your ECG signal last. Then you need to generate your noise signal use the same time step and generate the signal with the same length. Then you can simply add them together.
Do you have Simulink? If you do, it's much easier doing this in Simulink. You can use the FromWorkspace block to import your ECG signal, then add a periodical sinusoid noise. You don't need to worry about the length of the noise signal because it simply repeats again and again.

1 Comment

what is procedure for adding noise in ecg signal?. i use from file block to load ECG signal but i have d'not idea which block i introduce for noise and how i use filter for removing that noise ? if you any idea then please help me.

Sign in to comment.

Umesh Pande
Umesh Pande on 1 Jun 2016
Hello sir i am working on project to remove 50hz noise from ECG signal using TVLMS algorithm in Matlab can you guide me

Asked:

on 15 Jul 2011

Commented:

MD
on 10 Aug 2023

Community Treasure Hunt

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

Start Hunting!