BMEN 3311 Lab2 F2022 answer
docx
keyboard_arrow_up
School
University of North Texas *
*We aren’t endorsed by this school
Course
3311
Subject
English
Date
Jan 9, 2024
Type
docx
Pages
3
Uploaded by BrigadierDiscovery640
BMEN 3311 Lab 2 Sampling & Quantization
Names: Group #:
Question1. The figure below shows how blood pressure can be classified based on the diastolic and systolic pressures. Write a MATLAB script m-file to display a message indicating the classification based on the values of two variables representing the diastolic and systolic pressures. The two blood pressure values should be read in from the keyboard
dia = input(
'Enter diastolic pressure:'
);
sys = input(
'Enter systolic pressure:'
);
if (sys < 90) && (dia < 60)
disp(
'Low b.p.'
);
elseif (sys < 120) && (dia < 80)
disp(
'Ideal b.p.'
);
elseif (sys < 140) && (dia < 90)
disp(
'Pre-high b.p.'
);
else
disp(
'High b.p.'
);
end
Question 2. The following analog signal is sampled at 1.2kHz over an interval of 100 ms.
x
(
t
)
=
5.5sin
(
2
π
50
t
)
+
4.3cos
(
2
π
10
t
)
a.
Write a MATLAB script to create the digital signal using 10 bits and an operating voltage
range from -10 V to 10 V. Plot the digital signal and ensure that plot is labeled accordingly. Have TA verify plot.
TA initial Code _____
b.
Create a histogram of the quantization error. The x-axis is voltage and y-axis is occurrence of error. Have TA verify histogram.
Note: Quantization error is the difference between quantized signal and original signal. Use the histogram function to plot in MATLAB.
TA initial Code_____
What does the x and y axis of the histogram mean?
Create a signal been sampled at 12 bits. What would happen to the quantization error as the number of bits is increased and why? close all
;
%% a, create a signal and plot
fs = 1200; % Hz;
t_total = 0.1; % second;
t = 1/1200:1/1200:t_total; % create the time vector with maximum sampling
xt = 5.5*sin(2*pi*50*t) + 4.3*cos(2*pi*10*t);
bits = 10; % sampled at 10 bits
Xmin = -10; % v
Xmax = 10; % v
L = 2^bits; %# of quantization levels R=(Xmax-Xmin)/L; %resolution of ADC
n = length(t);
% current value under quantization: xq = xmin + i*R
% where i = round((x-xmin)/R)
for idx = 1:n
i(idx) = round((xt(idx)-Xmin)/R);
xq10(idx) = Xmin+ i(idx)*R;
end
figure; set(gcf, 'color'
, [1 1 1]);
plot(t,xt,
'b'
); xlabel(
'time(s)'
);
ylabel(
'magnitude (v)'
);
hold on
;
stairs(t,xq10,
'r'
);
legend(
'raw data'
,
'10 bits'
);
hold off
;
grid on
;
%% b, histogram of the quantization error.
% 1, calculate 10bit error
errorq10 = xt-xq10;
% 2, calculate 12bit error
bits = 12; % sampled at 12 bits
L = 2^bits; %# of quantization levels R=(Xmax-Xmin)/L; %resolution of ADC
n = length(t);
% current value under quantization: xq = xmin + i*R
% where i = round((x-xmin)/R)
for idx = 1:n
i(idx) = round((xt(idx)-Xmin)/R);
xq12(idx) = Xmin+ i(idx)*R;
end
errorq12 = xt-xq12;
% 3, generate figure
figure; set(gcf,
'color'
,[1 1 1]);
histogram(errorq10); hold on
;
histogram(errorq12); hold off
;
xlabel(
'magnitude (v)'
);
ylabel(
'number of occurrences'
);
legend(
'10bit'
,
'12bit'
);
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