Search code examples
matlabmatrixfrequencynoisetrigonometry

adding a sin wave to an ecg signal


I am trying to add a 50hz sinusoidal noise to an ecg signal, the data file has a dimension of : <373046x1 double> in volts and it was recorded over a period of 186.52 seconds

, here is my noise code

 freqNoise = 50;    %  My Frequency [Hz]
 amplNoise = 0.25;  %  My Amplitude
 myNoise  = amplNoise*sin(2*pi.*t.*freqNoise);

every time I try to add the noise to the data I get the error of "matrix sizes must agree", I know they should but How can I make them agree without modifying the ecg signal


Solution

  • Added following line on top of your code:

    t = 0:186.52/(373046-1):186.52 ;
    

    Above vector hold time instants where we want to calculate the value of signal. Length of signal in time is 186.52 and want 373046 samples during time. So separation between two samples is 186.52/(373046-1) seconds.