Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Essential parameters
- fs = 240;
- Ts = 1/fs;
- data = load ('ECG1.txt');
- % Time vector
- t = 0 : Ts : ((length(data)-1)*Ts);
- % Noise
- fNoise = 50; % Frequency [Hz]
- aNoise = 0.25; % Amplitude
- noise = aNoise*sin(2*pi.*t.*fNoise);
- % Loading data from the file
- x = data(:, 1)';
- y = data(:, 2)';
- %Addition of the noise to the original signal
- signalNoise = y + noise;
- % Plot of noisy signal
- figure(1)
- subplot(2,1,1)
- plot(x, signalNoise, ';Signal with noise ;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- grid on;
- subplot(2,1,2)
- signalNoise_fft = fft(signalNoise);
- stem(abs(signalNoise_fft)(1:250))
- title('ECG Signal', 'FontSize', 20);
- xlabel('Frequency', 'FontSize', 20);
- ylabel('Magnitude', 'FontSize', 20);
- set(gca, 'xTickLabel', 0:24:120);
- % Plot of original signal
- figure(2)
- subplot(2,1,1)
- plot(x, y, ';Original signal;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- grid on;
- subplot(2,1,2)
- y_fft = fft(y);
- stem(abs(y_fft)(1:250))
- title('ECG Signal', 'FontSize', 20);
- xlabel('Frequency', 'FontSize', 20);
- ylabel('Magnitude', 'FontSize', 20);
- set(gca, 'xTickLabel', 0:24:120);
- % Comparison of noisy and original signal
- figure(3)
- plot(x, signalNoise, ';Signal with noise ;');
- hold on
- plot(x, y, ';Original signal;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- grid on;
- hold off;
- % Plot of Notch filter
- figure(4)
- fs2 = fs / 2;
- [b,a] = pei_tseng_notch (50 / fs2, 2/fs2);
- filtered = filter(b,a,signalNoise);
- subplot (2,1,1)
- plot(filtered, ';Notch filter;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- grid on;
- subplot (2,1,2)
- notch_fft = fft(filtered);
- stem (abs(notch_fft)(1:250))
- title('ECG Signal', 'FontSize', 20);
- xlabel('Frequency', 'FontSize', 20);
- ylabel('Magnitude', 'FontSize', 20);
- set(gca, 'xTickLabel', 0:24:120);
- % Plot of FIR filter
- figure(5)
- f1 = 50/(fs/2) - 0.03;
- f2 = 50/(fs/2) + 0.03;
- c = fir1(100,[f1 f2], "stop" );
- filtered2 = filter(c,1,signalNoise);
- subplot (2,1,1)
- plot(filtered2(1,50:500), ';FIR filter;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- grid on;
- subplot (2,1,2)
- fir_fft = fft (filtered2);
- stem (abs(fir_fft)(1:250));
- title('ECG Signal', 'FontSize', 20);
- xlabel('Frequency', 'FontSize', 20);
- ylabel('Magnitude', 'FontSize', 20);
- set(gca, 'xTickLabel', 0:24:120);
- % Comparison of Notch and FIR filter
- figure(6)
- plot(filtered2(1,50:500), ';FIR filter;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- grid on;
- hold on
- plot(filtered, ';Notch filter;');
- title('ECG Signal', 'FontSize', 20);
- xlabel('Time', 'FontSize', 20);
- ylabel('Voltage', 'FontSize', 20);
- hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement