How to plot 3 seconds worth of ECG data from excel and perform a DFT to find the power spectrum

10 views (last 30 days)
Hello, I have a code asking me to:
  1. The file avf.csv contains 3 minutes of a noisy ECG signal. The first column of data is the time intervals a sample was taken, and the second column of data is the magnitude of the ECG in mV. Perform the following using the ECG data:
  2. Plot 3 seconds worth of the ECG and label the plot appropriately.
  3. Perform a DFT (with the DFT function) and create a separate plot of the power spectrum. Label the plot appropriately.
I think I have plotted the ECG wave for 3 seconds correctly but I am not sure that I have done the DFT function correctly to create a power spectrum. I also need to make my amplitude one sided and I am not sure how to do that. Can someone please verify my code and help me out with my errors.
I have also attached my file
here is my code:
Excel = csvread('avf.csv');
Fs = 1/(Excel(2,1)-Excel(1,1));
N = 3*Fs+1; %L
T = N/Fs;
t = (0:1:N-1)/Fs;
%x = avf(1:N, 1);
f = (0:1:N-1)*Fs/N;
y = avf(1:N, 2); %xt
plot(t,y)
xlabel('time(s)'); ylabel('amp'); title('Signal');
xt = y
fk = Fs*(0:(N-1))/N;
L = N + 24
xt = [y, zeros(N,24)];
Xk = fft(xt,N);
Ak = abs(Xk)/N;
%Y = fft(xt);
%P2 = abs(Y/N);
%P1 = P2(1:L/2+1);
%Pq(2:end-1) = 2*pi(2:end-1)
%Ak = 1/N*abs(Y);
Pk = Ak.^2
figure(2);
plot(fk,Pk);
title('DFT');
xlabel('Frequency(HZ)');
ylabel('Amplitude Spectrum');

Answers (1)

Harshita Gokavi
Harshita Gokavi on 9 Nov 2023
Excel = csvread('avf.csv');
Fs = 1/(Excel(2,1)-Excel(1,1));
N = 3*Fs+1; %L
T = N/Fs;
t = (0:1:N-1)/Fs;
%x = avf(1:N, 1);
f = (0:1:N-1)*Fs/N;
y = avf(1:N, 2); %xt
plot(t,y)
xlabel('time(s)'); ylabel('amp'); title('Signal');
xt = y
fk = Fs*(0:(N-1))/N;
L = N + 24
xt = [y, zeros(N,24)];
Xk = fft(xt,N);
Ak = abs(Xk)/N;
%Y = fft(xt);
%P2 = abs(Y/N);
%P1 = P2(1:L/2+1);
%Pq(2:end-1) = 2*pi(2:end-1)
%Ak = 1/N*abs(Y);
Pk = Ak.^2
figure(2);
plot(fk,Pk);
title('DFT');
xlabel('Frequency(HZ)');
ylabel('Amplitude Spectrum');

Categories

Find more on Measurements and Feature Extraction in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!