IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

Comment comparer deux fichiers son (.wav)


Sujet :

Delphi

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut Comment comparer deux fichiers son (.wav)
    Bonjour à tous,

    pour les besoins d'un projet de teste de son, je voudrais pouvoir comparer 2 fichiers son sur leur ressemblance, j'ai trouvé cette discussion trés interessante http://www.developpez.net/forums/d30...signaux-audio/ qui parle de la comparaison des spectre de fourier , mais je ne sais pas comment le faire par programmation

  2. #2
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 072
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 072
    Points : 15 462
    Points
    15 462
    Billets dans le blog
    9
    Par défaut
    Bonjour ! Ce que vous demandez n'est pas quelque chose de simple.

    Il y a un composant qui fait cela apparemment :

    http://www.3delite.hu/Object%20Pasca...onlibrary.html

    Le composant est basé sur la bibliothèque BASS.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour,

    la méthode fournier est une formule mathématique mais le problème c'est comment l'appliqué sur un fichier wav. j'ai trouvé que dans d'autres langages il existe une fonction "fft" qui donne directement le spectre de fournier mais j'ai rien trouvé pour delphi

  4. #4
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    merci @Roland Chastain pour votre réponse, mais j'arrive pas à exploiter le lien que vous m'avez donné.
    par contre j'ai trouvé cette unité de traitement de la transformé de fournier mais je ne sais pas comment l'appliquer à un fichier wav
    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
    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
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    // Gunnar Bolle, FPrefect@t-online.de
    // Simple FFT component
    // Feel free to use this code
    // Based upon a pascal routine from - Don Cross <dcross@intersrv.com>
    // Thanks Don, nice Job.
    // If you want to know more about FFT and its theorie visit
    // http://www.intersrv.com/~dcross
    // Thanks to Kees Huls for providing me the missing author information 
    //
    // Please note : I didn't have the time to write a sample application for this.
    //               Please do not ask me about how to use this one ...
    //               If you're aware of FFT you'll know how. Otherwise, try
    //               some of those neat Button components at DSP. They're quite easy
    //               to handle.
     
     
    unit DSXFastFourier;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes,math;
     
    procedure Register;
     
    type
    TComplex = Record
       Real : double;
       imag : double;
    end;
     
    TOnGetDataEvent = procedure(index : integer; var Value : TComplex) of Object;
     
    TComplexArray = array [0..0] of TComplex;
    PComplexArray = ^TComplexArray;
     
    EFastFourierError = class(Exception);
     
    TDSXFastFourier = Class(TComponent)
     
    private
        FNumSamples    : integer;
        FInBuffer      : PComplexArray;
        FOutBuffer     : PComplexArray;
        FOnGetData     : TOnGetDataEvent;
     
        function  IsPowerOfTwo ( x: word ): boolean;
        function  NumberOfBitsNeeded ( PowerOfTwo: word ): word;
        function  ReverseBits ( index, NumBits: word ): word;
        procedure FourierTransform ( AngleNumerator:  double );
        procedure SetNumSamples(value : integer);
        function  GetTransformedData(idx : integer) : TComplex;
     
        constructor
                  create(AOwner : TComponent);
        destructor
                  destroy;
     
    public
        procedure fft;
        procedure ifft;
        procedure CalcFrequency (FrequencyIndex: word);
     
    published
        property  OnGetData   : TOnGetDataEvent read FOnGetData write FOnGetData;
        property  NumSamples  : integer read FNumSamples write SetNumSamples;
        property  SampleCount : Integer read FNumSamples;
        property  TransformedData[idx : integer] : TComplex read GetTransformedData;
    end;
     
    implementation
     
    constructor TDSXFastFourier.Create(AOwner : TComponent);
    begin
       inherited create(AOwner);
    end;
     
    destructor TDSXFastFourier.Destroy;
    begin
      if Assigned(FInBuffer) then
          FreeMem(FinBuffer);
      if Assigned(FOutBuffer) then
          FreeMem(FOutBuffer);
    end;
     
     
    procedure TDSXFastFourier.SetNumSamples(value : integer);
    begin
     
       FNumSamples := value;
     
       if Assigned(FInBuffer) then
          FreeMem(FinBuffer);
     
       if Assigned(FOutBuffer) then
          FreeMem(FOutBuffer);
     
       try
         getMem(FInBuffer, sizeof(TComplex)*FNumSamples);
         getMem(FOutBuffer, sizeof(TComplex)*FNumSamples);
       except on EOutOfMemory do
         raise EFastFourierError.Create('Could not allocate memory for complex arrays');
       end;
     
    end;
     
    function  TDSXFastFourier.GetTransformedData(idx : integer) : TComplex;
    begin
      Result := FOutBuffer[idx];
    end;
     
    function TDSXFastFourier.IsPowerOfTwo ( x: word ): boolean;
    var   i, y:  word;
    begin
        y := 2;
        for i := 1 to 31 do begin
            if x = y then begin
                IsPowerOfTwo := TRUE;
                exit;
            end;
            y := y SHL 1;
        end;
     
        IsPowerOfTwo := FALSE;
    end;
     
     
    function TDSXFastFourier.NumberOfBitsNeeded ( PowerOfTwo: word ): word;
    var     i: word;
    begin
        for i := 0 to 16 do begin
            if (PowerOfTwo AND (1 SHL i)) <> 0 then begin
                NumberOfBitsNeeded := i;
                exit;
            end;
        end;
    end;
     
     
    function TDSXFastFourier.ReverseBits ( index, NumBits: word ): word;
    var     i, rev: word;
    begin
        rev := 0;
        for i := 0 to NumBits-1 do begin
            rev := (rev SHL 1) OR (index AND 1);
            index := index SHR 1;
        end;
     
        ReverseBits := rev;
    end;
     
     
    procedure TDSXFastFourier.FourierTransform ( AngleNumerator:  double);
    var
        NumBits, i, j, k, n, BlockSize, BlockEnd: word;
        delta_angle, delta_ar: double;
        alpha, beta: double;
        tr, ti, ar, ai: double;
    begin
        if not IsPowerOfTwo(FNumSamples) or (FNumSamples<2) then
            raise EFastFourierError.Create('NumSamples is not a positive integer power of 2');
     
        if not assigned(FOnGetData) then
           raise EFastFourierError.Create('You must specify an OnGetData handler');
     
        NumBits := NumberOfBitsNeeded (FNumSamples);
        for i := 0 to FNumSamples-1 do begin
            j := ReverseBits ( i, NumBits );
            FOnGetData(i,FInBuffer[i]);
            FOutBuffer[j] := FInBuffer[i];
        end;
        BlockEnd := 1;
        BlockSize := 2;
        while BlockSize <= FNumSamples do begin
            delta_angle := AngleNumerator / BlockSize;
            alpha := sin ( 0.5 * delta_angle );
            alpha := 2.0 * alpha * alpha;
            beta := sin ( delta_angle );
     
            i := 0;
            while i < FNumSamples do begin
                ar := 1.0;    (* cos(0) *)
                ai := 0.0;    (* sin(0) *)
     
                j := i;
                for n := 0 to BlockEnd-1 do begin
                    k := j + BlockEnd;
                    tr := ar*FOutBuffer[k].Real - ai*FOutBuffer[k].Imag;
                    ti := ar*FOutBuffer[k].Imag + ai*FOutBuffer[k].Real;
                    FOutBuffer[k].Real := FOutBuffer[j].Real - tr;
                    FOutBuffer[k].Imag := FOutBuffer[j].Imag - ti;
                    FOutBuffer[j].Real := FOutBuffer[j].Real + tr;
                    FOutBuffer[j].Imag := FOutBuffer[j].Imag + ti;
                    delta_ar := alpha*ar + beta*ai;
                    ai := ai - (alpha*ai - beta*ar);
                    ar := ar - delta_ar;
                    INC(j);
                end;
                i := i + BlockSize;
            end;
            BlockEnd := BlockSize;
            BlockSize := BlockSize SHL 1;
        end;
    end;
     
     
    procedure TDSXFastFourier.fft;
    begin
        FourierTransform ( 2*PI);
    end;
     
     
    procedure TDSXFastFourier.ifft;
    var
        i: word;
    begin
        FourierTransform ( -2*PI);
     
        (* Normalize the resulting time samples... *)
        for i := 0 to FNumSamples-1 do begin
            FOutBuffer[i].Real := FOutBuffer[i].Real / FNumSamples;
            FOutBuffer[i].Imag := FOutBuffer[i].Imag / FNumSamples;
        end;
    end;
     
     
    procedure TDSXFastFourier.CalcFrequency (FrequencyIndex: word);
    var
        k: word;
        cos1, cos2, cos3, theta, beta: double;
        sin1, sin2, sin3: double;
    begin
        FOutBuffer[0].Real := 0.0;
        FOutBuffer[0].Imag := 0.0;
        theta := 2*PI * FrequencyIndex / FNumSamples;
        sin1 := sin ( -2 * theta );
        sin2 := sin ( -theta );
        cos1 := cos ( -2 * theta );
        cos2 := cos ( -theta );
        beta := 2 * cos2;
        for k := 0 to FNumSamples-1 do begin
            sin3 := beta*sin2 - sin1;
            sin1 := sin2;
            sin2 := sin3;
            cos3 := beta*cos2 - cos1;
            cos1 := cos2;
            cos2 := cos3;
            FOutBuffer[0].Real := FOutBuffer[0].Real + FInBuffer[k].Real*cos3 - FInBuffer[k].Imag*sin3;
            FOutBuffer[0].Imag := FOutBuffer[0].Imag + FInBuffer[k].Imag*cos3 + FInBuffer[k].Real*sin3;
        end;
    end;
     
    procedure Register;
    begin
      RegisterComponents('Free', [TDSXFastFourier]);
    end;
     
    end.

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 55
    Points : 63
    Points
    63
    Par défaut
    Salut

    Pour faire le FFT d'un fichier wav, il y a la librairie BASS ici http://www.un4seen.com/

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour @francky23012301 et merci de participer à cette discussion.

    J'ai parcouru tout le lien que tu m'a fournit mais malheureusement aucun cas de fft ou de comparaison de fichiers wav

  7. #7
    Expert éminent sénior
    Homme Profil pro
    Analyste/ Programmeur
    Inscrit en
    Juillet 2013
    Messages
    4 630
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Analyste/ Programmeur

    Informations forums :
    Inscription : Juillet 2013
    Messages : 4 630
    Points : 10 556
    Points
    10 556
    Par défaut
    Si je ne dis pas de bêtises, la fft prend en entrée un tableau de fréquences.

    Le format wav est un format très ancien dont on peut extraire ces fréquences facilement (*)


    * -> du moins en lisant Wiki, cela semble être simple puisqu'il n'y a pas de compression. On prend chaque bloc et avec la fréquence échantillonnage et le "bitrate" ont connait le nombre et les valeurs des fréquences par seconde

  8. #8
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour,

    Mon but initiale est de pouvoir comparer 2 fichier wav , et le seul moyen c'est de comparer leurs spectre respectif est la seule fonction qui fait ça c'est la FFT qui n'existe pas sous delphi par contre elle existe sous c.

    le but de tout ça c'est que j'ai une base de données de sons(mots) différents et je voudrais les comparer par rapport au mots prononcer dans le micro.

  9. #9
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 037
    Points : 40 941
    Points
    40 941
    Billets dans le blog
    62
    Par défaut
    Bonjour
    Citation Envoyé par chekkal Voir le message
    Le but de tout ça c'est que j'ai une base de données de sons(mots) différents et je voudrais les comparer par rapport au mots prononcer dans le micro.
    ne serait-il pas plus simple d'utiliser les MSAgents ? tutoriel Michel Bardou
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  10. #10
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    Oui ou peut être même SAPI directement et passer par Soundex pour la reconnaissance des commandes.

  11. #11
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour,

    j'ai étudier les 2 méthode que vous m'avez proposés, et elle traite de la conversion d'un texte en parole, moi je voudrais faire une comparaison entre un son déjà existant et un son émit.

  12. #12
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 689
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 689
    Points : 13 118
    Points
    13 118
    Par défaut
    Citation Envoyé par chekkal Voir le message
    j'ai étudier les 2 méthode que vous m'avez proposés, et elle traite de la conversion d'un texte en parole, moi je voudrais faire une comparaison entre un son déjà existant et un son émit.
    Il faut lire plus bas, Speech Recognition.

  13. #13
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour @andnotor

    j'ai lu l'article mais malheureusement il est assez limité comme traitement. En effet, moi je veut avoir une reconnaissance vocale sur n'importe quelle voie et pas sur la voie d'une seule personne. C'est pour ça que la calcul mathématique de la FFT est efficace.

  14. #14
    Fxg
    Fxg est déconnecté
    Membre éclairé
    Homme Profil pro
    ingénieur financier
    Inscrit en
    Septembre 2003
    Messages
    510
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : ingénieur financier

    Informations forums :
    Inscription : Septembre 2003
    Messages : 510
    Points : 837
    Points
    837
    Par défaut
    Ce qui m'étonne, sans rentrer dans le débat technique sur la reconnaissance vocale, c'est qu'une simple recherche montre que ce sujet a été souvent traité sur le forum et donne de nombreux autres liens sur différents site.

    http://www.simdesign.nl/fft.html
    http://www.teworks.com/download.htm

    Bonne recherche

  15. #15
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour et merci de participer à la discussion.
    Concernant les liens que vous m'avez donné, voici les résultats:

    1er lien: il signale un virus à l'accé donc pas de suite.

    2eme lien: contient des exemple sur le traitement fréquentiel et les spectres

    3eme lien: traite du traitement du domaine temporel à la FFT mais pas du tout de la comparaison que je voudrais.

  16. #16
    Fxg
    Fxg est déconnecté
    Membre éclairé
    Homme Profil pro
    ingénieur financier
    Inscrit en
    Septembre 2003
    Messages
    510
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : ingénieur financier

    Informations forums :
    Inscription : Septembre 2003
    Messages : 510
    Points : 837
    Points
    837
    Par défaut
    Citation Envoyé par chekkal Voir le message
    merci @Roland Chastain pour votre réponse, mais j'arrive pas à exploiter le lien que vous m'avez donné.
    BASS Audio Recognition Library is a library (.dll) for use in Win32, Win64 (XP/Vista/7/8/10) and OSX32 software with BASS.
    Makes it easy to add audio recognition functionality to your application. This is not a speech recognition library! It compares files with a % similarity,
    Tu as essayé l'exemple fourni en delphi ?

    Concernant les liens fournis ils étaient juste pour illustrer la recherche ;-)

  17. #17
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour,

    j'ai essayé tous les démo données dans cette librairie, c'est vrai il ya un projet qui traite de ça mais il se compile pas, manque 2 fichiers "BASSAudioRecognitionDefs.dcu" et "BASS.dcu"

    Nom : essai.jpg
Affichages : 1382
Taille : 309,4 Ko

  18. #18
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour,

    j'ai beau cherché j'arrive pas à trouvé la solution. Par contre si quelqu'un peut m'aider à transformer ces 2 fonction écrite en c vers delphi ça sera génial
    D F T

    (Discrete Fourier Transform)

    F F T

    (Fast Fourier Transform)

    Written by Paul Bourke
    June 1993


    Introduction

    This document describes the Discrete Fourier Transform (DFT), that is, a Fourier Transform as applied to a discrete complex valued series. The mathematics will be given and source code (written in the C programming language) is provided in the appendices.

    Theory
    Continuous

    For a continuous function of one variable f(t), the Fourier Transform F(f) will be defined as:


    and the inverse transform as


    where j is the square root of -1 and e denotes the natural exponent


    Discrete

    Consider a complex series x(k) with N samples of the form


    where x is a complex number


    Further, assume that that the series outside the range 0, N-1 is extended N-periodic, that is, xk = xk+N for all k. The FT of this series will be denoted X(k), it will also have N samples. The forward transform will be defined as


    The inverse transform will be defined as


    Of course although the functions here are described as complex series, real valued series can be represented by setting the imaginary part to 0. In general, the transform into the frequency domain will be a complex valued function, that is, with magnitude and phase.


    The following diagrams show the relationship between the series index and the frequency domain sample index. Note the functions here are only diagramatic, in general they are both complex valued series.


    For example if the series represents a time sequence of length T then the following illustrates the values in the frequency domain.


    Notes

    The first sample X(0) of the transformed series is the DC component, more commonly known as the average of the input series.

    The DFT of a real series, ie: imaginary part of x(k) = 0, results in a symmetric series about the Nyquist frequency. The negative frequency samples are also the inverse of the positive frequency samples.

    The highest positive (or negative) frequency sample is called the Nyquist frequency. This is the highest frequency component that should exist in the input series for the DFT to yield "uncorrupted" results. More specifically if there are no frequencies above Nyquist the original signal can be exactly reconstructed from the samples.

    The relationship between the harmonics returns by the DFT and the periodic component in the time domain is illustrated below.



    DFT and FFT algorithm.
    While the DFT transform above can be applied to any complex valued series, in practice for large series it can take considerable time to compute, the time taken being proportional to the square of the number on points in the series. A much faster algorithm has been developed by Cooley and Tukey around 1965 called the FFT (Fast Fourier Transform). The only requirement of the the most popular implementation of this algorithm (Radix-2 Cooley-Tukey) is that the number of points in the series be a power of 2. The computing time for the radix-2 FFT is proportional to


    So for example a transform on 1024 points using the DFT takes about 100 times longer than using the FFT, a significant speed increase. Note that in reality comparing speeds of various FFT routines is problematic, many of the reported timings have more to do with specific coding methods and their relationship to the hardware and operating system.

    Sample transform pairs and relationships
    The Fourier transform is linear, that is
    a f(t) + b g(t) ---> a F(f) + b G(f)
    a xk + b yk ---> a Xk + b Yk

    Scaling relationship
    f(t / a) ---> a F(a f)
    f(a t) ---> F(f / a) / a
    Shifting
    f(t + a) ---> F(f) e-j 2 pi a f
    Modulation
    f(t) ej 2 pi a t ---> F(t - a)
    Duality
    Xk ---> (1/N) xN-k
    Applying the DFT twice results in a scaled, time reversed version of the original series.

    The transform of a constant function is a DC value only.

    The transform of a delta function is a constant

    The transform of an infinite train of delta functions spaced by T is an infinite train of delta functions spaced by 1/T.


    The transform of a cos function is a positive delta at the appropriate positive and negative frequency.


    The transform of a sin function is a negative complex delta function at the appropriate positive frequency and a negative complex delta at the appropriate negative frequency.


    The transform of a square pulse is a sinc function

    More precisely, if f(t) = 1 for |t| < 0.5, and f(t) = 0 otherwise then F(f) = sin(pi f) / (pi f)

    Convolution
    f(t) x g(t) ---> F(f) G(f)
    F(f) x G(f) ---> f(t) g(t)

    xk x yk ---> N Xk Yk

    xk yk ---> (1/N) Xk x Yk

    Multiplication in one domain is equivalent to convolution in the other domain and visa versa. For example the transform of a truncated sin function are two delta functions convolved with a sinc function, a truncated sin function is a sin function multiplied by a square pulse.

    The transform of a triangular pulse is a sinc2 function. This can be derived from first principles but is more easily derived by describing the triangular pulse as the convolution of two square pulses and using the convolution-multiplication relationship of the Fourier Transform.

    Sampling theorem
    The sampling theorem (often called "Shannons Sampling Theorem") states that a continuous signal must be discretely sampled at least twice the frequency of the highest frequency in the signal.

    More precisely, a continuous function f(t) is completely defined by samples every 1/fs (fs is the sample frequency) if the frequency spectrum F(f) is zero for f > fs/2. fs/2 is called the Nyquist frequency and places the limit on the minimum sampling frequency when digitising a continuous sugnal.

    If x(k) are the samples of f(t) every 1/fs then f(t) can be exactly reconstructed from these samples, if the sampling theorem has been satisfied, by


    where


    /*Normally the signal to be digitised would be appropriately filtered before sampling to remove higher frequency components. If the sampling frequency is not high enough the high frequency components will wrap around and appear in other locations in the discrete spectrum, thus corrupting it.

    The key features and consequences of sampling a continuous signal can be shown graphically as follows.

    Consider a continuous signal in the time and frequency domain.

    Sample this signal with a sampling frequency fs, time between samples is 1/fs. This is equivalent to convolving in the frequency domain by delta function train with a spacing of fs.


    If the sampling frequency is too low the frequency spectrum overlaps, and become corrupted.


    Another way to look at this is to consider a sine function sampled twice per period (Nyquist rate). There are other sinusoid functions of higher frequencies that would give exactly the same samples and thus can't be distinguished from the frequency of the original sinusoid.
    Code c : 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
    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
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
     
    */
    Appendix A. DFT (Discrete Fourier Transform)
    /*
       Direct fourier transform
    */
    int DFT(int dir,int m,double *x1,double *y1)
    {
       long i,k;
       double arg;
       double cosarg,sinarg;
       double *x2=NULL,*y2=NULL;
     
       x2 = malloc(m*sizeof(double));
       y2 = malloc(m*sizeof(double));
       if (x2 == NULL || y2 == NULL)
          return(FALSE);
     
       for (i=0;i<m;i++) {
          x2[i] = 0;
          y2[i] = 0;
          arg = - dir * 2.0 * 3.141592654 * (double)i / (double)m;
          for (k=0;k<m;k++) {
             cosarg = cos(k * arg);
             sinarg = sin(k * arg);
             x2[i] += (x1[k] * cosarg - y1[k] * sinarg);
             y2[i] += (x1[k] * sinarg + y1[k] * cosarg);
          }
       }
     
       /* Copy the data back */
       if (dir == 1) {
          for (i=0;i<m;i++) {
             x1[i] = x2[i] / (double)m;
             y1[i] = y2[i] / (double)m;
          }
       } else {
          for (i=0;i<m;i++) {
             x1[i] = x2[i];
             y1[i] = y2[i];
          }
       }
     
       free(x2);
       free(y2);
       return(TRUE);
    }
    Appendix B. FFT (Fast Fourier Transform)
    /*
       This computes an in-place complex-to-complex FFT 
       x and y are the real and imaginary arrays of 2^m points.
       dir =  1 gives forward transform
       dir = -1 gives reverse transform 
    */
    short FFT(short int dir,long m,double *x,double *y)
    {
       long n,i,i1,j,k,i2,l,l1,l2;
       double c1,c2,tx,ty,t1,t2,u1,u2,z;
     
       /* Calculate the number of points */
       n = 1;
       for (i=0;i<m;i++) 
          n *= 2;
     
       /* Do the bit reversal */
       i2 = n >> 1;
       j = 0;
       for (i=0;i<n-1;i++) {
          if (i < j) {
             tx = x[i];
             ty = y[i];
             x[i] = x[j];
             y[i] = y[j];
             x[j] = tx;
             y[j] = ty;
          }
          k = i2;
          while (k <= j) {
             j -= k;
             k >>= 1;
          }
          j += k;
       }
     
       /* Compute the FFT */
       c1 = -1.0; 
       c2 = 0.0;
       l2 = 1;
       for (l=0;l<m;l++) {
          l1 = l2;
          l2 <<= 1;
          u1 = 1.0; 
          u2 = 0.0;
          for (j=0;j<l1;j++) {
             for (i=j;i<n;i+=l2) {
                i1 = i + l1;
                t1 = u1 * x[i1] - u2 * y[i1];
                t2 = u1 * y[i1] + u2 * x[i1];
                x[i1] = x[i] - t1; 
                y[i1] = y[i] - t2;
                x[i] += t1;
                y[i] += t2;
             }
             z =  u1 * c1 - u2 * c2;
             u2 = u1 * c2 + u2 * c1;
             u1 = z;
          }
          c2 = sqrt((1.0 - c1) / 2.0);
          if (dir == 1) 
             c2 = -c2;
          c1 = sqrt((1.0 + c1) / 2.0);
       }
     
       /* Scaling for forward transform */
       if (dir == 1) {
          for (i=0;i<n;i++) {
             x[i] /= n;
             y[i] /= n;
          }
       }
     
       return(TRUE);
    }

  19. #19
    Expert confirmé
    Avatar de Sub0
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2002
    Messages
    3 573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2002
    Messages : 3 573
    Points : 4 219
    Points
    4 219
    Par défaut
    Bonjour.

    Si cela peut t'aider, j'ai retrouver ce post avec un code source Delphi :
    http://www.developpez.net/forums/d12...spectre-carte/

    bon courage!
    De retour parmis vous après 10 ans!!

  20. #20
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2010
    Messages
    945
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2010
    Messages : 945
    Points : 123
    Points
    123
    Par défaut
    Bonjour,

    J'ai testé l'exemple, mais il reçoit un tableau de byte avec un nbre de byte limité. Moi,je crée des fichiers wav avec une capacité de 8000 byte.

Discussions similaires

  1. Lire un fichier son wav... un peu d' aide svp
    Par pilouface dans le forum C
    Réponses: 10
    Dernier message: 13/05/2006, 16h36
  2. Comment comparer des fichiers sur Windows?
    Par programmerPhil dans le forum Autres Logiciels
    Réponses: 9
    Dernier message: 22/02/2006, 20h47
  3. Fonction c qui compare deux fichiers ???
    Par babyface dans le forum C
    Réponses: 4
    Dernier message: 19/11/2005, 13h07
  4. Comment comparer deux dates
    Par vodevil dans le forum Modules
    Réponses: 6
    Dernier message: 01/09/2005, 18h24
  5. comment comparer deux dates?
    Par billoum dans le forum C++Builder
    Réponses: 2
    Dernier message: 21/08/2004, 21h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo