BMEN 3311 Lab 1 F2022 answer
docx
keyboard_arrow_up
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
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
Related Documents
Related Questions
Question iii please help......
arrow_forward
An 8085 assembly language program is given below.
Line 1: MVI A, B5H
2: MVI B, OEH
3: XRI 69H
4: ADD B
5: ANI 9BH
6: CPI 9FH
7: STA 3010H
8: HLT
The contents of the accumulator just execution of the ADD instruction in line
4 will be
arrow_forward
QUESTION i please help........
arrow_forward
2. Consider the following circuit
D
å lå
a. Find the expressions for D, T, Qo*, Q₁*.
b. Write the transition output table.
c. Draw the state diagram of the circuit.
d.
Is this a Mealy or Moore machine? Explain.
T
21
a la
1
arrow_forward
Here is the data flow diagram for a particular instruction. The various values shown indicate the state of the machine after the action of this
instruction. The question mark locates this instruction in memory.
GatePC
DR 100
GateMARMUX
RO
X2FFF
PC X
RI
x3006
MARMUX
TRAPVECTOR
R2
x3005
X0:0
PCMUX
R3
x3004
ZEXT
R4
x3003
OFPSETŐ OR
R5
x3002
PC OR BASER
R6
x3001
PCOFFSET
(7:0)
R7
x3000
ADDR2MUX
ADDRIMUX
SR2
SRI
(100
SEXT
IMMS
SEXT
SRZMUX
SEXT
FINITE
[50]
SEXT
STATE
[40]
MACHINE
Arith/Logic Operation
AL select
IRO01
A/L RESULT
LOGIC
GateALU
Gate MDR
16
16
MDR
MAR
T16
МЕМORY
x 30 0O
x 30 0 1
X 3:0:0 2
x3003
x3004
x 30 03
x3001
x: 3:0 0 4
X 30 05
X300 6
x3000
x3006
x3002
What is that instruction in binary? (You may use any number of spaces to organize the bits.)
address instruction
х3002
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you

Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning
Related Questions
- Question iii please help......arrow_forwardAn 8085 assembly language program is given below. Line 1: MVI A, B5H 2: MVI B, OEH 3: XRI 69H 4: ADD B 5: ANI 9BH 6: CPI 9FH 7: STA 3010H 8: HLT The contents of the accumulator just execution of the ADD instruction in line 4 will bearrow_forwardQUESTION i please help........arrow_forward
- 2. Consider the following circuit D å lå a. Find the expressions for D, T, Qo*, Q₁*. b. Write the transition output table. c. Draw the state diagram of the circuit. d. Is this a Mealy or Moore machine? Explain. T 21 a la 1arrow_forwardHere is the data flow diagram for a particular instruction. The various values shown indicate the state of the machine after the action of this instruction. The question mark locates this instruction in memory. GatePC DR 100 GateMARMUX RO X2FFF PC X RI x3006 MARMUX TRAPVECTOR R2 x3005 X0:0 PCMUX R3 x3004 ZEXT R4 x3003 OFPSETŐ OR R5 x3002 PC OR BASER R6 x3001 PCOFFSET (7:0) R7 x3000 ADDR2MUX ADDRIMUX SR2 SRI (100 SEXT IMMS SEXT SRZMUX SEXT FINITE [50] SEXT STATE [40] MACHINE Arith/Logic Operation AL select IRO01 A/L RESULT LOGIC GateALU Gate MDR 16 16 MDR MAR T16 МЕМORY x 30 0O x 30 0 1 X 3:0:0 2 x3003 x3004 x 30 03 x3001 x: 3:0 0 4 X 30 05 X300 6 x3000 x3006 x3002 What is that instruction in binary? (You may use any number of spaces to organize the bits.) address instruction х3002arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Electricity for Refrigeration, Heating, and Air C...Mechanical EngineeringISBN:9781337399128Author:Russell E. SmithPublisher:Cengage Learning

Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning