Question
MATLAB I am having trouble loading the file and plotting it. The file name is ecg1 and the Data File is in dat format. A
MATLAB
I am having trouble loading the file and plotting it. The file name is ecg1 and the Data File is in dat format. A sample of the file is at the bottom and the is the first part.
% MATLAB PROGRAM ECG_plot.m
% Use this program to read the files ecg1.dat, ecg2.dat, ecg3.dat, and ecg4.dat (one at a time)
% Run the program by entering at the MATLAB command line
% ECG_plot
% and provide the name of the input file to be read in response to the prompt
clear all % clears all active variable
close all
%% Loading the ECG file %%
fnam = input('Enter the ECG file name :','s');
fid = fopen(fnam);
ecg = fscanf(fid,'%f ');
fs = 200; %sampling rate
sze = length(ecg);
necg = ecg/max(ecg); % normalize the maximum value to unity
time = [1 : sze]/fs;
figure;
plot(time,necg);
axis tight;
ylabel('ECG');
xlabel('Time in seconds');
FILE NAMED ecg1
-8.8760400e-01 |
-9.1384900e-01 |
-8.8623000e-01 |
-8.8012700e-01 |
-9.3063400e-01 |
-9.0652500e-01 |
-9.0255700e-01 |
-9.1751100e-01 |
-9.4772300e-01 |
-9.7518900e-01 |
-9.3811000e-01 |
-9.4604500e-01 |
-9.5199600e-01 |
-9.3689000e-01 |
-9.5977800e-01 |
-9.3536400e-01 |
-8.7814300e-01 |
-8.7036100e-01 |
-9.0789800e-01 |
-9.0362500e-01 |
-8.8394200e-01 |
-9.3689000e-01 |
-9.1461200e-01 |
-9.1461200e-01 |
-8.9279200e-01 |
-9.3154900e-01 |
-9.0393100e-01 |
-8.8623000e-01 |
I was able to figure it out. I have to modify this portion of the code below. Modify the ECG_plot.m script by following the steps below to calculate and plot the frequency spectrum of each signal. The frequency spectrum is calculated by fft command. y=fft(ecg); p1=abs(y/length of y); p2=p1(1:length/2+1).*2; freq = sampling frequency*(0:(length/2))/length; plot(freq(2:end-1),p2(2:end-1)); |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started