BMEN 3311 Lab 1 F2022 answer

docx

School

University of North Texas *

*We aren’t endorsed by this school

Course

3311

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

docx

Pages

7

Uploaded by BrigadierDiscovery640

Report
BMEN 3311 Lab 1 – Basics of MATLAB Names: ID: Make sure all questions are answered, lab report is properly formatted/easy to read, names student ID are typed, screenshots are all visible and legible, and submitted before deadline. Practice 1 – Variables – 10 points Write a command to clear the MATLAB workspace. Then, create the following variables: 1. A variable called a which has the character value ‘q’. 2. A variable called b which has the Boolean value true. 3. A variable called c which is an array of integers between 1 and 10. 4. A variable called d which is an array of characters with the values ‘h’, ‘e’, ‘l’, ‘l’, ‘o’. Now find out the data types of all variables you just created. Label them as comments in MATLAB. Ex. variable = false; %Boolean Submit as script or screenshot below. Make sure the code runs correctly for all problems. % Clear workspace clear % Creat variables a = 'q' ; b = true; c = 1:10; d = 'hello' ; % Find out types of all variables whos
Practice 2 – Array Operation – 10 points Let a = [1 3 1 2] and b = [7 10 3 11]. Run commands sequentially. 1. Sum all elements in a and add the result to each element of b. 2. Raise each element of b to the power of the corresponding element of a. hint: (array b)^(array a) 3. Divide each element of b by 4. 4. Display b (final result) % Clear workspace clear % Initialise a and b a = [1 3 1 2]; b = [7 10 3 11]; % Perform array operations b = b + sum(a); b = b.^a; b = b / 4;
Practice 3 – function and save – 15 points Write MATLAB commands to compute the sine , cosine and tangent of an array of numbers between 0 and 2 π (in steps of 0.1). Save the original input array (using the save function) and all three output arrays to a single MAT file (named trig.mat ) and then clear the workspace. % Clear workspace Clear % Create array x = 0:0.01:(2*pi); % Compute sin/cos/tan s=sin(x); c=cos(x); t=tan(x); % Save to file save( 'trig.mat' , 'x' , 's' , 'c' , 't' );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Practice 4 – math – 15 points Write a MATLAB script that reads in three floating point values from the user (a, b and c), which represent the lengths of three sides of a triangle. Then compute the area of the triangle according to the equation: where s is half of the sum of the three sides, or the average of a, b, & c. Hint: look up MATLAB function that prompts read-in values from user % Clear workspace clear % Read a, b, c a = input( 'Enter a: ' ); b = input( 'Enter b: ' ); c = input( 'Enter c: ' ); % Compute area of triangle s = (a + b + c) / 2; area = sqrt(s * (s-a) * (s-b) * (s-c))
Practice 5 – Heart rate calculation – 40 points A PPG signal is modeled using the following equation: y = f ( t )= 6.8 sin ( 2 π 1 t ) + 4.4 sin ( 2 π 2 t ) 1. In MATLAB, create a plot of the modeled PPG waveform. Assume that each data point is 1 ms apart, and create a signal 3 seconds in length. Label the plot “Modeled PPG”, y- axis “Magnitude”, and x-axis “Time(s)”. 2. What is the maximum amplitude of the modeled signal? 3. Use the function findpeaks to help determine the instantaneous heart rate in beats per minute of the modeled signal with following equation. HR = 60 ( T 2 T 1 ) Hint: Set up the function to return the magnitude and location of peaks. For example [y x] = findpeaks(signal). Heat Rate = ______ BPM clear; %% section1 % set the time vector 0.001s:0.001s:3s t = 0.001:0.001:3; % get the function (method1) ft = 6.8*sin(2*pi*1*t)+4.4*sin(2*pi*2*t); % % get the function (method2) for i = 1:3000 ft(i) = 6.8*sin(2*pi*1*t(i))+4.4*sin(2*pi*2*t(i)); end % plot the data plot(t,ft); title( 'Modeled PPG' ); xlabel( 'Magnitute' ); ylabel( 'Time(s)' ); %% section2 AmpMax = max(ft); %% section3 [pk pkloc] = findpeaks(ft,t); HR = 60/(pkloc(3)-pkloc(1));
Practice 6 – load and plot ECG data – (bonus 20 points). An ECG (ecg_100.dat) data has 2 channels, recorded as 360Hz, and total length is 10 seconds. The ECG device has a maximum recording range of 0-10mV and sampled at 12bits. Write a code to load and plot this data. Specific note: this is one type of very common biosignal raw data. The data is always saved as binary format with a specific bit precision. The raw data is also arranged as the single-line long format as: Sample1_channel1 Sample1_channel2 Sample2_channel1 Sample2_channel2 Sample3_channel1 Sample3_channel2 … … Two hints here to help you get through the coding: 1, for loading the 12bit unsigned data, use the precision ‘ubit12’. The unsigned 12bit data is ranged from 0 to 2^12, you need to assign them to 0-10 mV. 2, the channel 1 in the single-line long format should be read by 1:2:length(data). % answer for question 6. % ini clear; close; clc; time = 10; % in second t = 0:1/360:10-1/360; % get the data using fopen-fread-fclose combo fID = fopen( 'ecg_100.dat' , 'r' ); ecg = fread(fID,2*360*time, 'ubit12' ); fclose(fID); % convert bit to mV ecg = 10*ecg./2^12; % seperate channels ecg_ch1 = ecg(1:2:length(ecg)); ecg_ch2 = ecg(2:2:length(ecg)); figure; subplot(2,1,1); plot(t,ecg_ch1); xlabel( 'time(s)' ); ylabel( 'mV' ); title( 'ecg 1000 channel1' ); subplot(2,1,2); plot(t,ecg_ch2); xlabel( 'time(s)' ); ylabel( 'mV' ); title( 'ecg 1000 channel2' );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help