Bonjour à tous,
J'aimerai un coup de main, je ne trouve pas la solution.
J'ai une fonction qu'on ma réaliser en MATLAB qui fonctionnait très bien. Je l'ai transformé en python avec un peu d'aide et je rencontre des soucis :
Ma fonction permet de chercher des PICS sur un signal et de me donner l'abscisse (signal provenant d'un CSV).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 # -*- coding: utf-8 -*- from matplotlib import pyplot as plt import numpy as np from pylab import * def search_peek(nbr_peek,signal,temps): ### INITIALISATION DES TABLEAUX ### list_peek = np.zeros(nbr_peek) list_index = np.zeros(nbr_peek) ### ORGANISATION DES POINTS ### index_sort_increasing = argsort(signal) index_sort_decreasing = np.flipud(index_sort_increasing) ### PREMIER PIC DETECTE ### index1 = index_sort_decreasing[0] list_peek[0]=index1 list_index[0]=signal[index1] indice = 1 n_peek =1 ### ON RECHERCHE LES PICS ### while(n_peek<nbr_peek): index_temp=index_sort_decreasing[indice] diff_gauche = signal[index_temp]-signal[index_temp-1], diff_droite = signal[index_temp+1]-signal[index_temp]; if(diff_gauche>0) and (diff_droite<0): list_peek[n_peek]= signal[index_temp] list_index[n_peek] = index_temp n_peek=n_peek+1; indice = indice+1 return list_index,list_peek ### ESSAIS ### temps1 =np.array([1,2,3,4,5,6,7,8,9,10]) signal1 = np.array([8,1,4,6,5,2,7,0,9,10]) list_1,peek_1 = search_peek(1,temps1,signal1) plt.plot(temps1,signal1) plt.plot((list_1+1),peek_1,'r*') show()
Quand je recherche un pic, je n'ai pas d'erreur mais quand j'en cherche plusieurs, j'ai une erreur d'indice.
Si vous voyez une erreur dans mon code..
Merci
Partager