i want code for the below given task

14 views (last 30 days)
kalyani chava
kalyani chava on 4 Apr 2020
Edited: DGM on 29 Apr 2022
Load an ECG signal. Add a 50 Hz, 100 Hz and 150 Hz frequency sinusoidal signals to this ECG signals. Plot the original ECG signal, corrupted ECG signal and their spectrum.
  3 Comments
Ameer Hamza
Ameer Hamza on 4 Apr 2020
Exactly, this is clearly an assignment or a project. I hope that you don't expect us to complete it for you. As Peng mentioned, you need to show some code that you have already tried. This forum is focused on MATLAB related questions, e.g., errors, syntax issues, suggestions, etc. Your problem is not specifically related to MATLAB, and it is still very kind of Peng to solve Task 1 of the assignment for you. Now you can extend it further to solve the other two tasks.

Sign in to comment.

Accepted Answer

Peng Li
Peng Li on 4 Apr 2020
close all; clear;
%% this is an examplary ECG recording with sampling frequency 200 hz
y = load('2GCCY.txt');
fs = 200;
N = length(y);
% show data
hfd = figure('Name', 'Orignal data and contaminated data');
had1 = subplot(211);
t = (0:1/fs:(N-1)/fs)';
plot(had1, t, y);
% zoom in to better visualize data
had1.XLim = [0 20];
title('Original ECG');
xlabel('time (s)');
% add 50 Hz noise, SNR 1:1
fn1 = 50;
n50 = std(y).*sin(2*pi*fn1*t);
yn50 = y + n50;
had2 = subplot(212);
plot(had2, t, yn50);
had2.XLim = [0 20];
title('Original ECG contaminated by 50 Hz noise');
xlabel('time (s)');
%% fft
Fy = fft(y);
f = fs/N .* ((-N/2+1):N/2);
% show fft
hff = figure('Name', 'FFT');
haf1 = subplot(211);
plot(f, fftshift(abs(Fy)./N));
haf1.XLim = [0 fs/2];
title('Amplitude spectrum of orignal ECG');
xlabel('Frequency (Hz)');
ylabel('Amplitude spectrum');
% fft of contaminated data
Fyn50 = fft(yn50);
% show fft
haf2 = subplot(212);
plot(f, fftshift(abs(Fyn50)./N));
haf2.XLim = [0 fs/2];
title('Amplitude spectrum of ECG + 50 Hz noise');
xlabel('Frequency (Hz)');
ylabel('Amplitude spectrum');

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by