Skip to content

Commit 57d5d19

Browse files
Some cleaning to the text
1 parent df078ee commit 57d5d19

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

content/learning-paths/embedded-and-microcontrollers/cmsisdsp-dev-with-python/_index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
title: Learn how to get started with CMSIS-DSP using Python
2+
title: Getting Started with CMSIS-DSP Using Python
33

4-
minutes_to_complete: 10
4+
minutes_to_complete: 30
55

66
who_is_this_for: Developers writing DSP/AI software
77

88
learning_objectives:
99
- Understand how to use the CMSIS-DSP Python package
10-
- Understand how the Python implementation maps to the C one
11-
- Develop a complex application with CMSIS-DSP
10+
- Understand how the Python implementation maps to the C implementation
11+
- Develop a complex application using CMSIS-DSP
1212

1313
prerequisites:
1414
- Some familiarity with DSP programming
1515
- Some familiarity with Python programming
1616
- Knowledge of C
1717
- Some familiarity with CMSIS-DSP
18-
- Python installed on your computer
18+
- Python installed on your system
1919

2020
author: Christophe Favergeon
2121

content/learning-paths/embedded-and-microcontrollers/cmsisdsp-dev-with-python/how-to-1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The CMSIS-DSP Python package is a Python API for CMSIS-DSP. Its goal is to make
1818

1919
For this reason, the Python API is as close as possible to the C one.
2020

21-
Fixed point arithmetic is not often provided by Python packages which generally focus on floating-point operations. The CMSIS-DSP Python package provides the same fixed point arithmetic functions as the C version : Q31, Q15 and Q7. The package is also providing float functions and in the future will also provide half-precision floats like the C API.
21+
Fixed-point arithmetic is rarely provided by Python packages, which generally focus on floating-point operations. The CMSIS-DSP Python package provides the same fixed-point arithmetic functions as the C version: Q31, Q15 and Q7. The package also provides floating-point functions and will also support half-precision floats in the future, like the C API.
2222

23-
Finally, the CMSIS-DSP Python package is compatible with NumPy and can be used with all other scientific and AI Python packages such as SciPy or PyTorch.
23+
Finally, the CMSIS-DSP Python package is compatible with NumPy and can be used with all other scientific and AI Python packages such as SciPy and PyTorch.
2424

content/learning-paths/embedded-and-microcontrollers/cmsisdsp-dev-with-python/how-to-5.md

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plt.show()
2323

2424
The slices we created are overlapping. By applying a Hanning window function and summing the slices, you can reconstruct the original signal.
2525

26-
Indeed, summing two Hanning window shifted by half the width of the sample block:
26+
Indeed, summing two Hanning windows shifted by half the width of the sample block gives:
2727
![summed hanning alt-text#center](sumhanning.png "Figure 5. Summed Hanning Window")
2828

2929
As result, if you multiply the overlapping blocks of samples by Hanning windows and sum the result, you can reconstruct the original signal:
@@ -96,27 +96,61 @@ scaling = (energy - self._noise)/energy
9696

9797
(Don’t evaluate this Python code in your Jupyter notebook—it will be run later as part of the full implementation.)
9898

99-
### NoiseSuppressionReference class
99+
### NoiseSuppression and NoiseSuppressionReference classes
100100

101101
The entire algorithm will be packaged as a Python class.
102102
The class functions are explained below using Python code that should not be evaluated in the Jupyter notebook.
103103

104104
You should only evaluate the full class definition in the Jupyter notebook—not the code snippets used for explanation.
105105

106106

107-
#### NoiseSuppressionReference constructor
107+
#### NoiseSuppression constructor
108108

109+
`NoiseSuppression` is a shared class used by both the float reference implementation and the Q15 version.
109110

111+
```python
112+
class NoiseSuppression():
113+
def __init__(self,slices):
114+
self._windowLength=len(slices[0])
115+
self._fftLen,self._fftShift=fft_length(self._windowLength)
116+
117+
self._padding_left=(self._fftLen - self._windowLength)//2
118+
self._padding_right=self._fftLen- self._windowLength-self._padding_left
119+
120+
self._signal=[]
121+
self._slices=slices
122+
self._window=None
123+
```
110124

111-
The constructor:
125+
The constructor for `NoiseSuppression`:
112126
- Uses the audio slices as input
113-
- Computes the VAD signal for the full audio signal
114-
- Applies the Hanning window to each slice
115127
- Computes the FFT length that can be used for each slice
116128
- Computes the padding needed for the FFT
117129

118130
The FFT length must be a power of 2. The slice length is not necessarily a power of 2. The constructor computes the closest usable power of 2. The audio slices are padded with zeros on both sides to match the required FFT length.
119131

132+
#### NoiseSuppressionReference constructor
133+
134+
```python
135+
class NoiseSuppressionReference(NoiseSuppression):
136+
def __init__(self,slices):
137+
# In a better version this could be computed from the signal length by taking the
138+
# smaller power of two greater than the signal length.
139+
NoiseSuppression.__init__(self,slices)
140+
141+
# Compute the vad signal
142+
self._vad=clean_vad([signal_vad(w) for w in slices])
143+
self._noise=np.zeros(self._fftLen)
144+
# The Hann window
145+
self._window=dsp.arm_hanning_f32(self._windowLength)
146+
```
147+
148+
The constructor for `NoiseSuppressionReference`:
149+
- Uses the audio slices as input
150+
- Call the constructor for `NoiseSuppression`
151+
- Computes the VAD signal for the full audio signal
152+
- Compute the Hanning window
153+
120154

121155
#### subnoise
122156
```python
@@ -218,6 +252,9 @@ def overlap_and_add(self):
218252
```
219253

220254
### The final code for the Python class
255+
256+
You can evaluate this code in your Jupyter notebook.
257+
221258
```python
222259
def fft_length(length):
223260
result=2

content/learning-paths/embedded-and-microcontrollers/cmsisdsp-dev-with-python/how-to-6.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ If the Python package has been built with Neon acceleration, it will use the new
370370

371371
If this temporary buffer is not provided, the Python package will allocate it automatically. While you can use the same API, this is less efficient.
372372

373-
It is better to detect than the package have been compiled with Neon acceleration, allocate a temporary buffer and use it in the FFT calls.
373+
It is better to detect whether the package has been compiled with Neon acceleration, allocate a temporary buffer and use it in the FFT calls. This approach is closer to how the C API must be used.
374374

375375
```python
376376
if dsp.has_neon():

0 commit comments

Comments
 (0)