8.1. Lab 2
La fonction peut être implémentée en langage Ptolemy de la façon suivante: (fichier $PTOLEMY/test/SDFTemplate.pl)///////////////// DEBUT DU LISTING //////////////////
defstar {
// GENERAL INFORMATION ON THE STAR
// the name of the star
name { Template }
// the domain SDF, BDF, CGC, ...
domain { SDF }
// a short description of the star function
desc { This template star just take an input
and output the same value if it lies between
the defined limits else it output the nearest
limit.
}
// this allows the use of SCCS or RCS
// version control systems
version { %W% %G% }
author { ma pomme }
copyright {
Copyright (c) 1996 - 2000 - Arnaud Laprevote and Alter Soft.
All rights declined.
To be used and modified by anybody.
Disclaimer of all warranty.
}
// Just to precise where it lies. It is just an indication
// and you can put wherever you like
location { My SDF library }
// Used to generate keywords for the automatic
// documentation generation.
// .Id is a nroff command
explanation {
.Id "Template star"
.Id "Threshold, limit"
}
// END OF GENERAL STAR INFORMATION DEFINITION
// START OF EXTERNAL VIEW DEFINITION
// Definition of an input
input {
// name of the input
name { input }
// data type that will come from the input
type { float }
// description of the input
desc { Input sample }
}
// Definition of an output
output {
name { output }
type { float }
}
// State definition
// A state is internal to a star.
// It may be set before a run.
// Afterthat the star may modify the value.
// It is typically used for star parameters
defstate {
name { Min }
type { float }
// A default value : very very useful
default { 0.0 }
desc { "Minimum value of the output" }
}
defstate {
name { Max }
type { float }
default { 1.0 }
desc { "Maximum value of the output" }
}
// END OF EXTERNAL VIEW DEFINITION
// STAR FUNCTION DEFINITION
// setup : executed once at the beginning of the run
setup {
/* In setup, go and wrapup, I can put classical
C comments */
} // end setup
// go, executed on each iteration of the system
go {
// Data declaration
float temporary;
// The current (numbered 0) data on the input
// is transfered to temporary
temporary = input%0;
// The function of the star itself
if (temporary < Min) temporary=Min;
else if (temporary > Max) temporary=Max;
// Temporary is sent on the output
output%0 << temporary;
} // end go
// wrapup : executed once at the end of the run
wrapup {
} // end of wrapup
// END OF STAR FUNCTION DEFINITION
} // end of SDFTemplate star
/////////////////// FIN DU LISTING /////////////////
8.2. Lab 3
8.2.1. Solution 1
Voici une des solutions possibles. Vous remarquerez que le changement de fréquence est réalisé dans le set-up au seul moyen de la fonction 'setSDFParams'. Le scheduler s'occupe du reste !////////////////// DEBUT DU LISTING ////////////////
defstar {
// GENERAL INFORMATION ON THE STAR
// the name of the star, to be used later
// within Ptolemy when defining the new star
name { SRateConversion }
// the domain SDF, BDF, CGC, ...
domain { SDF }
// a short description of the star function
desc { This star realises after linear interpolation
and a threhold function between 10 and 240,
a sampling rate down conversion by a factor 2
}
// this allows the use of SCCS or RCS
// version control systems
version { %W% %G% }
author { cathy }
copyright {
Copyright (c) 1996 - Arnaud Laprevote, Free and Alter Soft.
All rights declined.
To be used and modified by anybody.
Disclaimer of all warranty.
}
// Just to precise where it lies. It is just an indication
// and you can put wherever you like
location { My SDF library }
// Used to generate keywords for the automatic
// documentation generation.
// .Id is a nroff command
explanation {
.Id "Sampling rate"
.ID "Down conversion"
.Id "Threshold"
}
// END OF GENERAL STAR INFORMATION DEFINITION
// START OF EXTERNAL VIEW DEFINITION
// Definition of an input
input {
// name of the input
name { input }
// data type that will come from the input
type { int }
// description of the input
desc { Input sample }
}
// Definition of an output
output {
name { output }
type { int }
desc { Output sample }
}
// State definition
// A state is internal to a star.
// It may be set before a run.
// Afterthat the star may modify the value.
// It is typically used for star parameters
defstate {
name { Min }
type { int }
// A default value : very very useful
default { 10 }
desc { "Minimum value of the output" }
}
defstate {
name { Max }
type { int }
default { 240 }
desc { "Maximum value of the output" }
}
// END OF EXTERNAL VIEW DEFINITION
// STAR FUNCTION DEFINITION
// setup : executed once at the beginning of the run
setup {
// the following instruction:
// io_var.setSDFParam(multiplicity,max_offset)
// define the 'multiplicity' of the input or output
// variable, which corresponds to the number of particles
// consumed or produced for the given porthole;
// 'max_offset' is the maximum value that offset can take
// in any expression of the form 'name%offset';
// most of the time max_offset = multiplicity - 1
input.setSDFParams(2,1);
output.setSDFParams(1,0);
} // end setup
// go, executed on each iteration of the system
go {
// Data declaration
int input1, input2, result;
// The current (numbered 0) data on the input
// is transfered to temporary
input1= input%0;
input2= input%1;
// Interpolation and general filter loop
result= (input1 + input2) / 2;
// Threshold
// 'result' has to be between Min and Max
result= (result < Min) ? Min : ((result > Max) ? Max : result );
// Temporary is sent on the output
output%0 << result;
} // end go
// wrapup : executed once at the end of the run
wrapup {
// nothing to do
} // end of wrapup
// END OF STAR FUNCTION DEFINITION
} // end of SDFSRateConversion star
Pout tester votre bloc l'insérer dans un schéma, lui appliquer un signal d'entrée et analyser le signal de sortie. Un exemple est donné ci-dessous, avec le résultat de la simulation.
Solution 1: définition d'une nouvelle étoile.
8.2.2. Solution 2
Cette solution utilise les modules de base suivant:- dans la palette 'Signal Processing', l'étoile 'FIR'
- dans la palette 'Non Linear Functions', l'étoile 'Limiter'
- dans la palette 'Control', l'étoile 'DownSampler'
Malheureusement ces modules n'existent pas avec des données de type entier. Il faut donc faire la simulation en virgule fixe ou en virgule flottante avec des pas de 1.0.
Le schéma de simulation est donné ci-dessous, ainsi que les paramètres des différents blocs.
8.2.3. Solution 3
Cette solution n'utilise que les modules de base suivant:- dans la palette 'Signal Processing', l'étoile 'FIR'
- dans la palette 'Non Linear Functions', l'étoile 'Limiter'
En effet il est possible de définir dans la bloc 'FIR' utilisé pour la solution 2 un facteur de sous échantillonage (qui sera appliqué après le filtre linéaire. Dans des cas de figure plus compliqués où une personnalisation du traitement ou du contrôle des opérations s'avère nécessaire, ce filtre ne pourra être utilisé.
De meme que pour la solution 2, les blocs ne sont pas disponibles avec une précision entière. Selon la précision souhaitée, il faudrait utiliser des convertisseurs de type: float / int out int / float .
8.3. Lab 4
L'étoile peut être implémentée de la manière suivante ://////////////////DEBUT DU LISTING //////////////////
defstar {
name { Interlace }
domain { SDF }
version { %W% %G% }
author { AL }
copyright{
}
location { SDF User library }
desc {
Filtre une image (applique une matrice de filtrage sur l'image).
}
// permet de faire un ou plusieurs include de fichiers
hinclude { "Matrix.h" "iostream.h" }
input {
name { input }
type { FLOAT_MATRIX_ENV }
desc { Image en entree (niveau de gris) }
}
input {
name { parity }
type { int }
desc { Parity selected }
}
output {
name { output }
type { FLOAT_MATRIX_ENV }
desc { Image en sortie (niveau de gris) }
}
output {
name { parity_out }
type { int }
desc { Parity of output picture }
}
go {
int i,j;
int current_parity;
int line_parity;
/* Une "Matrice de flottant" est un type de donnee particulier */
/* Elle passe d'une etoile a une autre a l'interieur d'une */
/* enveloppe. Pour etre utilisee, l'image doit etre extraite */
/* de l'enveloppe. Ce qui suit est du C++, le reste d'une etoile */
/* peut etre totalement ecrit en C pur. */
Envelope envp;
// Application de la fonction get Message
// a l'objet input%0 pour recuperer l'enveloppe.
(input%0).getMessage (envp);
// On affecte le contenu de l'enveloppe a une variable
const FloatMatrix *imD = (const FloatMatrix*) envp.myData();
// Creation et initialisation de l'image resultat a la bonne taille
FloatMatrix* imgData = new FloatMatrix(int(imD->numRows()/2), imD->numCols());
cout << "imgData->numRows" << imgData->numRows() << "";
cout << "imgData->numCols" << imgData->numCols() << "";
cout << "imD->numRows" << imD->numRows() << "";
cout << "imD->numCols" << imD->numCols() << "";
// La parite
current_parity =(int(parity%0)%2);
cout << "current_parity" << current_parity;
// Pointeur de parcours des pixels de sortie
double* d = &(imgData->entry(0));
double* input_image_pointer = &(imD->entry(0));
for (i = 0; i < imD->numRows(); i++) {
cout << " " << i;
line_parity = i%2;
for (j = 0; j < imD->numCols(); j++) {
if ( line_parity == current_parity ) {
if ( j == 0 ) {
cout << i << " parity of " << current_parity;
}
// cout << i << j ;
*d++ = *input_image_pointer;
}
input_image_pointer++;
} // end for j
cout << "";
}// implicit end for i
// L'image resultat est mise dans une enveloppe
Envelope envp2(*imgData);
// L'enveloppe est envoyee a la sortie output
output%0 << envp2;
parity_out%0 << current_parity;
} // end go
} // end Interlace
8.4. Lab 5
L'erreur vient du fait que les valeurs limites pour les indices de ligne i et j sont trop élévées: d'où débordement de la mémoire allouée. En effet i prend la valeur 360, alors que i devrait être compris entre 0 et 359. De même pour j.Remplacer les lignes 88 et 89:
for (i = 0; i <= sy ; i++)for (j = 0; j <= sx ; j++) {
par:
for (i = 0; i < sy ; i++)for (j = 0; j < sx ; j++) {
De même, le test sur les indices pos_x et pos_y est faux. Mais ici l'erreur n'apparaît pas directement. D'où l'intérêt d'utiliser un débuggueur pour lancer des routines de vérification et examiner l'évolution des variables au fur et à mesure de l'exécution.
Remplacer alors la ligne 105:
(pos_y<=sy)&&par
(pos_y<sy)&&Enfin remplacer la ligne 108:
(pos_x<=sx)par
(pos_x<sx)Et vérifier le résultat !
![]() |
Précédent | Suivant | Plan | 13/03/00 | PTOLAB |

