Digital Signal Processing using Arm Cortex-M based Microcontrollers by Cem Ünsalan, M. Erkin Yücel, H. Deniz Gürhan.
- Chapter 1, sections 1-3
- Chapter 5, sections 1-5
- Chapter 10, sections 1-3
- Lecture 0 slides on Introduction
Supplemental reading#
Lab 1 instructions#
Complete the following exercises during your lab section. Include your results in the lab report.
If you are unfamiliar with a particular MATLAB function, type doc or help in the MATLAB command window.
DSP in MATLAB#
Since these exercises are intended to teach the basics of MATLAB, some possible solutions are provided.
Create a vector t representing the time variable with range of one second and sampling period of of \(T_s = 0.001\) sec. One way to create a vector of evenly spaced numbers in MATLAB is with the : operator. Alternatively, you can use the linspace function. Solution 1:
t = 0:0.001:1;
Solution 2:
t = linspace(0,1,1001);
xt = sin(2*pi*t); plot(t,xt);
Explanation: Many MATLAB functions that operate on scalars (including sin ) are automatically ‘mapped’ to arrays. Since t is an vector, the expression sin(2*pi*t) applies the scalar function \(x(t) = sin( 2\pi t)\) to each element of t . Solution 2:
x = @(t) sin(2*pi*t); plot(t,x(t));
xlabel('Time [seconds]'); ylabel('Signal Amplitude x(t)'); title('x(t)=sin(t)');
[~, ind] = min(abs(t-0.32)); xt(ind)
Explanation: The expression abs(t-0.32) measures the distance of each element in t to the desired value of 0.32. Combining this expression with the min function allows us to find the element of t which is closest to 0.32. The min function returns two values: the value of the minimum (which we discard by assigning the special name ~ ) and the index ind which tells us the position in the array that is closest to 0.32. Solution 2:
ind = 1 + 0.32/0.001 xt(ind)
xn = xt(1:8:end);
Solution 2:
xn = downsample(xt,8);
tn = t(1:8:end); hold all; stem(tn,xn);
Include the code for steps 1-6 in your lab report along with the figure you generated.
Using the STM32H735G discovery kit and starter code#
In order for you to get started programming the board, we have created a sample project which passes a signal from the input jack to the output jack (this is known as a talkthrough.) Additionally, the spectrum of the input signal is visualized on the LCD.
- Follow the instructions in the setup guide to import the starter code and program the board..
- Connect the blue input jack on the board to the signal generator set to a 10kHz sine wave.
- Connect the green output jack on the board to the oscilloscope.
- Configure the oscilloscope and verify the that the signal appears as expected.
- Locate the process_left_sample function in lab.c . Change the behavior from a talkthrough \(f(x[n]) = x[n]\) to a squaring function \(f(x[n]) = ^2\) by modifying the line output_sample = input_sample; Rerun the program and observe the result on the oscilloscope.
- At the end of the process_left_sample function in lab.c , locate the line return output_sample; . Put a breakpoint at this line.
- Allow the program to continue until it stops at the breakpoint. Add a watch expression for the variable elapsed_cycles and record the value. Include this measurement in your lab report.
Lab report contents#
Be sure to include everything listed in this section when you submit your lab report.
I. Results from lab exercise#
- DSP in MATLAB
- Using the STM32H735G discovery Kit and starter code
II. Assignment questions#
- What is aliasing? How do you manage aliasing in DSP applications?
- Draw a block diagram of a generic DSP system and a talk-through system.
- How are 32-bit floating-point results saved on the ARM Cortex-M7 processor? Explain briefly the IEEE single-precision floating-point format.
- Give an example (such as one or more lines of C code) that would result in the processor using IEEE single-precision floating point for an operation.
- How can you estimate the number of clock cycles required to execute a section of code on the STM32 board?
Lab 0. Review of Prerequisites (Optional)