In: Electrical Engineering
Exercise 2.1: Basic digital signals (a) Write a MATLAB program to generate and display (using the stem function) the signals defined in Table 1. The MATLAB code of the first signal (dirac) is given in the report template as an example. (b) Write a MATLAB function [x, t] = sin_NU(f0, fs, T) to generate a sine signal. The output parameters x and t are the signal and time vectors, respectively. The input parameters are f0 (signal frequency in Hz), fs (sampling frequency in Hz), T (signal duration in sec.). (c) Test your sin_NU function with the input parameter values .... and display the result using the plot function. List of basic digital signals to generate: - Dirac (Unit Response) - Unit step (Heaviside step) - Sign - Rectangle - Sine - Sine cardinal Exercise 2.2: Audio aliasing To illustrate the aliasing phenomenon, let’s perform two simple experiments allowing us to “hear” it. Using the sin_NU function of Exercise 1: (a) Generate two 1 kHz sine signals (2 seconds duration), first signal at 20 kHz sample frequency and second signal at 1.5 kHz sample frequency; (b) On the same graph, use the plot function to display the two signals versus t in the range 0 < t < 5 msec.; (c) Listen to the two signals one after another using the function soundsc(x, fs); and (d) Give your interpretation of this listening. Exercise 2.3: Quantization Quantization is done by replacing each value of an analog signal x(t) by the value of the nearest quantization level. To exemplify this operation, let’s simulate an unipolar ADC (Analog to Digital Converter) having the technical specifications: R = 10 Volts (full-scale range) and B = 3 (number of bits). (a) Write a MATLAB function y = adc_NU(x, R, B) where x and y are vectors containing the input signal and the quantized signal, respectively; (b) Test your function with an input ramp signal ranging from -5 to 15 Volts (1 volt per step); and (c) On the same graph, use the plot and stem functions to display the input signal and quantized signal, respectively.
Hello,
Please find the answers (till
exercise 2.2) attached below. If the answer has helped you please
give a double thumbs up rating. Thank you and have
a nice day!
For part a) please provide the table1
b)
The function definition is:
function [x, t] = sin_NU(f0, fs, T);
t = 0:1/fs:T;
x = sin(2*pi*f0*t);
end
c) Test the above with this code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% function testing
f0 = 5; fs = 100; T = 2;
[x, t] = sin_NU(f0, fs, T);
plot(t,x);
grid;
xlabel('Time (s)');
title('SIne wave with f = 5Hz')
You will get the following output:
ex1a) and b) Please run the following program:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% audio aliasing
f0 = 1000; fs1 = 20000;fs2 = 1500; T =
2; %
signal parameters
[x1, t1] = sin_NU(f0, fs1,
T);
% x1 is sampled at 20K
[x2, t2] = sin_NU(f0, fs2,
T);
% x2 is sampled at 1.5K
[x11, t3] = sin_NU(f0, fs1,
5e-3);
% signals for plotting
[x21, t4] = sin_NU(f0, fs2,
5e-3);
subplot(2,1,1)
plot(t3,x11);
grid;
xlabel('Time (s)');
title('SIne waves with f = 1000Hz and fs1 = 20K, fs2 =
1.5K');
subplot(2,1,2)
plot(t4,x21);
grid;
xlabel('Time (s)');
**** End of Code ****
Output:
c) For listening to the sounds run the following code after running the code in part a) above:
soundsc(x1, fs1)
pause(3);
soundsc(x2, fs2)
d) You will notice a shriller sound in the first case. This is because since the sound has not been sampled properly in the second case, it will lose information related to its contents and appear to be of a smaller frequency.