forked from peterhinch/micropython-fourier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.py
75 lines (69 loc) · 1.84 KB
/
window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# window.py Window function
# Author: Peter Hinch
# 20th April 2015
# Now uses FPU mnemonics. Tests complete.
# Floating point version
# Applies a window function to an array of real samples before performing a DFT.
# removes the DC (zero frequency) component by averaging the sample set and
# subtracting from each sample, before multiplying the sample by the corrsponding
# coefficient and storing the result in the sample array.
# The coefficient array is unchanged.
import array, math
# Multiply each element in array 0 by the corresponding one in array 1, returning the
# result in array 0.
# r0: array 0 real data
# r1: array 1 window coefficients
# r2: length of arrays
@micropython.asm_thumb
def winapply(r0, r1, r2):
push({r0, r2})
mov(r3, 0)
vmov(s14, r3)
vcvt_f32_s32(s15, s14) # s15 holds value to set
label(LOOP1)
vldr(s14, [r0, 0])
vadd(s15, s14, s15)
add(r0, 4)
sub(r2, 1)
bgt(LOOP1)
pop({r0, r2})
vmov(s14, r2)
vcvt_f32_s32(s14, s14) # convert array length to float
vdiv(s13, s15, s14) # avg. in s13
label(LOOP)
vldr(s14, [r0, 0])
vsub(s15, s14, s13)
vldr(s14, [r1, 0])
vmul(s15, s14, s15)
vstr(s15, [r0, 0])
add(r0, 4)
add(r1, 4)
sub(r2, 1)
bgt(LOOP)
# Set all elements of a float array to an integer value
# r0: the array
# r1: value
# r2: length of array
@micropython.asm_thumb
def setarray(r0, r1, r2):
vmov(s14, r1)
vcvt_f32_s32(s15, s14) # Value in s15
label(LOOP)
vstr(s15, [r0, 0])
add(r0, 4)
sub(r2, 1)
bgt(LOOP)
# Copy elements of an integer array to a float array, converting
# r0: integer array
# r1: float array
# r2: length
@micropython.asm_thumb
def icopy(r0, r1, r2):
label(LOOP)
vldr(s14, [r0, 0])
vcvt_f32_s32(s15, s14)
vstr (s15, [r1, 0])
add(r0, 4)
add(r1, 4)
sub(r2, 1)
bgt(LOOP)