ECE5655 Midterm
ECE5655 Midterm
Contents
ECE 4655/5655 Midterm Exam Spring 2016 2
Problem 1: Panning Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Part a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Part b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Part c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Problem 2: Signal Mean and Variance using CMSIS-DSP . . . . . . . . . . . . . . . . . . . . 5
Part a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Part b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Part c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Part d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Part e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1
ECE 4655/5655 Midterm Exam Spring 2016
Due Monday April 11, 2016
The midterm exam is in the form of a take-home exam, meaning each student is to do his/her own work
without consulting others. All problems involve working with the Cypress FM4 and also some use of Python.
The due date is at the end of class time Monday April 11, 2016.
I have written the exam in an IPython notebook so it is available as a static PDF document and also as
a live notebook document.
What to Turn In: Write your exam solutions in this IPython notebook. You can use markdown cells
to document your C source code and you can insert screen shots as png graphics using something like:
Image(’fname.png’,width=’90%’)
I would like a paper compy of the notebook following conversion to LaTeX and then PDF. Note: The
lab computers can do this conversion or you can do this if you add Pandoc and then MikTeX to your Python
setup. Also Email me a ZIP package containing the IPython notebook and the ZIP file from Problem 1.
where 0 ≤ a ≤ 1. The parameter a is to be controlled by a GUI slider app parameter. I suggest you
have three parameters controlled by the GUI slider app: one for the input of each channel and the third
parameter being the panning variable a. The step size for the panning variable should be 0.02.
In [7]: # FM4 GUI slider control confiured for panning control problem
Image(’FM4_GUI.png’,width=’60%’)
Out[7]:
2
Part a
Write code to implement the panning control functionality and interface it to GUI slider variables. Document
your code here in the notebook using a markdown code block, i.e.,
/* Some c code */
#define MY_CONST 25
int32_t N;
Part b
Test using a 1kHz sinusoid as one input and internally generated noise onthe other input, e.g.,
xRi = (float32_t)(((int16_t)rand_int32())>>2);
Use the input gain sliders to roughly bring the intensity of the 1 kHz tone and the noise into parity. Now
move the panning control from one extreme to the other. To prove to that it it works make a stereo wavefile
recording of this test activity over a 5 to 10 second interval at 48 ksps. Send the wavefile to me with your
exam document.
To generate the 1kHz sinusoid I suggest using either the Analog Discovery or a cell phone funcion
generator app. There are several good ones out there, mostly free.
3
Optionally, you can record the left and right output signals using the Record capability of the Analog
Discovery. With the two channel scope running you find Record under the Control menu. You will have to
select a 50 kHz sampling rate. Then you will have to import the data into Python, resample down to 48
kHz and save as a wavefile. The details are in the cell below.
In [ ]: # Assuming both scopy channels are active, the same csv file will
# contain two columns, plus a one row header.
yL,yR = loadtxt(’scope_record.csv’,delimiter=’,’,skiprows=1,\
usecols=(0,),unpack=True)
# Resample from 50k to 48k using farrow_resample from digitalcom.py
import digitalcom as dc
yL_r = dc.farrow_resample(yL,50.0,48.0)
yR_r = dc.farrow_resample(yR,50.0,48.0)
# Stack L and R as a 2D array which is the form needed for a stereo
# wavefile
yLR = vstack([[yL_r],[yR_r]]).T
# Check the dimensions
yLR.shape
# Should many rows of samples by 2 columns
Once you have the imported file form the Analog Discovery resampled and in a two column stereo format,
save it to a wave file using ssd.to wave.
In [10]: fs = 48000
ssd.to_wav(’problem1.wav’,fs,yLR)
Now that you have a stereo wavefile at fs = 48 ksps, you can listen to it in the notebook using the Audio
control.
Part c
Now that you have heard and also can see the math, describe in words the action of the panning control.
4
Problem 2: Signal Mean and Variance using CMSIS-DSP
In this problem you will re-purpose the function FIR header() from Lab2 for creating a known test signal
that can be imported into a STM32F4 project. In this problem again start with a copy of loop intr.c as
found in the ZIP package. This not going to be a real-time project, so you need to comment out the line
audio_init(hz48000, line_in, intr, I2S_HANDLER);
In [40]: # You may want to change the variable h_FIR to x_sig or similar
# Similarly change #define M_FIR to #define N_xvec or similar
def FIR_header(fname_out,h):
"""
Write FIR Filter Header Files
Part a
Use a header file to store a custom test signal generated in Python to be stored in the header file as float32 t
values. The function that does this is listed above, FIR header(fname out,h).
Create in Python the test signal
x[n] = 3 cos 2π · f1 /fs · n + 2 sin 2π · f2 /fs · n (3)
where fs = 48000 Hz, f1 = 1000 Hz, and f2 = 400 Hz. Create 501 values, that is let 0 ≤ n ≤ 500.
In [47]: # To get started create x[n]
f1 = 1000
5
f2 = 345.3987
fs = 48000
n = arange(0,1001)
x = 3*cos(2*pi*f1/fs*n) + 2*sin(2*pi*f2/fs*n)
In [ ]: # Add Python code to create the header and then move on to part b
Part b
Using the CMSIS-DSP functions
develop code for the Cypress FM4 to calculate the mean and variance of the test vector values read in
from the header file you created in part (a). You may have to do some variable renaming in the header itself
to make more sense in your code, that is change h FIR[M FIR] to x[M FIR] and maybe change the #define
M FIR to #define N xvec. You can actually do the rewrite of the header writing function given above to be
a test vector generation header file writer.
Part c
Compile and run the function and provide screen shots of the computed values.
Part d
Profile the calculation of the mean and the variance calculation using the Keil MDK profile clock. Optionally
place GPIO High/Low calls around your code and capture the rising edge event with the logic analyzer.
gpio_set(TEST_PIN, HIGH);
/* your code here */
gpio_set(TEST_PIN, LOW);
Part e
Compare the values calculated via CMSIS-DSP with Python calculations obtained using:
mx = mean(x)
varx = var(x)
print(’Mean of x = %6.4f and var of x = %6.4f’ % (mx,varx))