DFT reel, imaginaire et module au carré fonctionnels

This commit is contained in:
Jules-Ian Barnavon 2023-04-12 10:50:58 +02:00
parent fff4c2afea
commit 4844fceba3
2 changed files with 116 additions and 11 deletions

View file

@ -1,6 +1,18 @@
PRESERVE8
THUMB
IMPORT LeSignal
EXPORT DFT_ModuleAuCarre
EXPORT DFT_reel
EXPORT DFT_imag
;int DFT_ModuleAuCarre( short int * Signal64ech, char k){
; int acumReel = 0;
; int acumImag = 0;
; for (int i= 0; i< 64; i++){
; acumReel += Signal64ech[i]*TabCos[(i*k)%64];
; }
; return acumReel;
;}
; ====================== zone de réservation de données, ======================================
;Section RAM (read only) :
@ -21,10 +33,97 @@
area moncode,code,readonly
; écrire le code ici
DFT_reel proc
;int DFT_ModuleAuCarre( short int * Signal64ech, char k){
push {r4, r5, r6, r7}
; int acumReel = 0;
ldr r5,=TabCos
mov r2,#0 ; r2 = acumReel
mov r7, #63
mov r3,#0 ; r3 = i
boucle1
; for (int i= 0; i< 64; i++){
mul r4,r3,r1 ; = i*k
and r4,r7 ;= i*k%64
ldrsh r6, [r5,r4,LSL #1]; r6 = TabCos[(i*k)%64]
ldrsh r4, [r0,r3,LSL #1]; r4 = Signal64ech[i];
mul r4, r4,r6
add r2, r4
add r3, #1
cmp r3,#63
ble boucle1
mov r0, r2
; acumReel += Signal64ech[i]*TabCos[(i*k)%64];
; }
; return acumReel;
;}
pop {r4,r5,r6,r7}
bx lr
ENDFUNC
DFT_imag proc
;int DFT_ModuleAuCarre( short int * Signal64ech, char k){
push {r4, r5, r6, r7}
; int acumReel = 0;
ldr r5,=TabSin
mov r2,#0 ; r2 = acumReel
mov r7, #63
mov r3,#0 ; r3 = i
boucle2
; for (int i= 0; i< 64; i++){
mul r4,r3,r1 ; = i*k
and r4,r7 ;= i*k%64
ldrsh r6, [r5,r4,LSL #1]; r6 = TabCos[(i*k)%64]
ldrsh r4, [r0,r3,LSL #1]; r4 = Signal64ech[i];
mul r4, r4,r6
add r2, r4
add r3, #1
cmp r3,#63
ble boucle2
mov r0, r2
; acumReel += Signal64ech[i]*TabCos[(i*k)%64];
; }
; return acumReel;
;}
pop {r4,r5,r6,r7}
bx lr
ENDFUNC
DFT_ModuleAuCarre proc
;int DFT_ModuleAuCarre( short int * Signal64ech, char k){
push {lr}
push {r4}
push {r0}
push {r1}
bl DFT_reel
mov r4,r0
pop {r1}
pop {r0}
bl DFT_imag
asr r4, #16
asr r0, #16
mul r4,r4
mul r0,r0;utiliser multiplication longue (smul?) et garder uniquement le registre de poids fort
add r0,r4
pop{r4}
pop{pc}
ENDFUNC
;Section ROM code (read only) :
AREA Trigo, DATA, READONLY
; codage fractionnaire 1.15

View file

@ -3,19 +3,23 @@
#include "DriverJeuLaser.h"
#include "stdio.h"
extern int DFT_ModuleAuCarre(short int* , char);
extern int DFT_reel(short int* , char);
extern int DFT_imag(short int* , char);
extern short int LeSignal[];
extern short int TabCos[];
extern short int TabSin[];
int resultat_reel, resultat_imag, resultat_module_carre;
int DFT_ModuleAuCarre( short int * Signal64ech, char k){
int acumReel = 0;
int acumImag = 0;
for (int i= 0; i< 64; i++){
acumReel += Signal64ech[i]*TabCos[(i*k)%64];
acumImag += Signal64ech[i]*TabSin[(i*k)%64];
}
return acumReel*acumReel + acumImag*acumImag;
}
//void DFT_ModuleAuCarre( short int * Signal64ech, char k, long int * resultat){
// int acumReel = 0;
// int acumImag = 0;
// for (int i= 0; i< 64; i++){
// acumReel += Signal64ech[i]*TabCos[(i*k)%64];
// acumImag += Signal64ech[i]*TabSin[(i*k)%64];
// }
// *resultat = acumReel*acumReel + acumImag*acumImag;
//}
int main(void)
{
@ -29,8 +33,10 @@ CLOCK_Configure();
resultat_reel = DFT_reel(LeSignal,17);
resultat_imag = DFT_imag(LeSignal,17);
resultat_module_carre =DFT_ModuleAuCarre(LeSignal,17);
printf("%d\n", DFT_ModuleAuCarre(LeSignal,17));
//============================================================================