Autor Beitrag
dac424
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Sa 08.07.06 13:33 
Frage wie kann ich die Treshold auswerten sprich wenn der vorgegebene Wert übersteigt das eine andere procedur Aktiviert wird
ausblenden volle Höhe Delphi-Quelltext
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:
unit dspDTMF;

{
  The simple DTFM decoder implementation
  Author:  Eugen Tarasov

  Last modified - May, 2003
  Please send all suggestions and comments to author.

  e-mail: dsplab@teworks.com
  http://www.teworks.com

  Short instructions:
  1. Create the instance of TdspDTMF object
  2. Set the OnTone event. This event occurs when the tone is found.
  3. Call Initialization method before use decoder.
  4. Call the Put method to put the audio samples to decoder.
  5. Call Finalize method to process the remaining data in the decoder buffer.
  6. Free the decoder object.
}


interface

uses SysUtils, dspFFT, dspWindow;

const
  cMinDTFMSampleRate = 11025;
  cDefaultDTFMSampleRate = 11025;
  cSupportedSampleRates: Array[0..2] of Integer = (11025, 22050, 44100);
  cDTMFInvalidSampleRateMsg = 'Unsupported sample rate'#13#10'Please use: 11025, 22050 or 44100';

type
  EdspDTMFInvalidSampleRate = class(Exception);
  TdspOnTone = procedure(Sender: TObject; Tone: Char) of object;
  TdspDTMFArray = Array[0..3] of Single;
  PdspDTMFArray = ^TdspDTMFArray;

  TdspDTMF = class
  private
    FFT: TdspFFT;
    FOnTone: TdspOnTone;
    FSampleRate: Integer;
    FThreshold: Single;
    FSkipCnt, FCounter: Integer;
    FPos: Integer;
    FRow, FCol: Integer;
    FCols, FRows: TdspDTMFArray;

    procedure FSetSampleRate(V: Integer);
    procedure FindTones;

  public
    constructor Create;
    destructor Destroy; override;

    procedure Initialize;
    procedure Finilize;
    procedure Put(V: Single);

    property Threshold: Single read FThreshold write FThreshold;
    property SampleRate: Integer read FSampleRate write FSetSampleRate default cDefaultDTFMSampleRate;
    property OnTone: TdspOnTone read FOnTone write FOnTone;
  end;


implementation

constructor TdspDTMF.Create;
begin
  FFT:= TdspFFT.Create(nil);
  FFT.BufferSize:= 256;
  FFT.Window:= fwBlackman;
  SampleRate:= cDefaultDTFMSampleRate;
end;


destructor TdspDTMF.Destroy;
begin
  FFT.Free;
  inherited;
end;


procedure TdspDTMF.FSetSampleRate(V: Integer);
var
  Iz: Integer;
  Supported: Boolean;
begin
  if FSampleRate <> V then
  begin
    Supported:= false;
    for Iz:= Low(cSupportedSampleRates) to High(cSupportedSampleRates) do
      Supported:= Supported or (cSupportedSampleRates[Iz] = V);

    if not Supported then
      raise EdspDTMFInvalidSampleRate.Create(cDTMFInvalidSampleRateMsg)
    else begin
      FSampleRate:= V;
      FSkipCnt:= FSampleRate div cMinDTFMSampleRate;
    end;
  end;
end;


procedure TdspDTMF.Initialize;
begin
  FPos:= 0;
  FRow:= -1;
  FCol:= -1;
  FFT.Clear;
end;


procedure TdspDTMF.Finilize;
begin
  if FPos > 0 then FindTones;
end;


procedure TdspDTMF.Put(V: Single);
begin
  if FCounter mod FSkipCnt = 0 then
  begin
    FFT.RealIn[FPos]:= V;
    Inc(FPos);
    if FPos >= FFT.BufferSize then FindTones;
  end;
  Inc(FCounter);
end;


procedure TdspDTMF.FindTones;
  procedure LocateTones;
     function GetFreqAmp(Freq: Single): Single;
     const Step = 11025 / 256;
     var Pos: Integer;
     begin
       Pos:= Round(Freq / Step);
       Result:= FFT.RealOut[Pos];
     end;

     function FindPeak(Data: PdspDTMFArray; var Position: Integer): Boolean;
     var Iz: Integer;
     begin
       Position:= 0;
       for Iz:= 1 to 3 do
         if Data[Position] < Data[Iz] then Position:= Iz;

       Result:= true;
       for Iz:= 0 to 3 do
         if Iz <> Position then Result:= Result and (Data[Iz] * 3 < Data[Position]);

       Result:= Result and (Data[Position] > FThreshold);
     end;

  const Tones: Array[0..3, 0..3] of Char = (
    ('1', '4', '7', '*'),
    ('2', '5', '8', '0'),
    ('3', '6', '9', '#'),
    ('A', 'B', 'C', 'D'));
  var Col, Row: Integer;
  begin
    FCols[0]:= GetFreqAmp(1209);
    FCols[1]:= GetFreqAmp(1336);
    FCols[2]:= GetFreqAmp(1477);
    FCols[3]:= GetFreqAmp(1633);

    FRows[0]:= GetFreqAmp(697);
    FRows[1]:= GetFreqAmp(770);
    FRows[2]:= GetFreqAmp(852);
    FRows[3]:= GetFreqAmp(941);

    if FindPeak(@FCols, Col) and FindPeak(@FRows, Row) and
       (Col <> -1) and (Row <> -1) then
    begin
      if (Row <> FRow) or (Col <> FCol) then
      begin
        FCol:= Col; FRow:= Row;
        if Assigned(FOnTone) then FOnTone(Self, Tones[FCol, FRow]);
      end;
    end else
    begin
      FRow:= -1;
      FCol:= -1;
    end;
  end;
begin
  FFT.FFT;
  FFT.CalculateMagnitudes;
  LocateTones;
  FFT.Clear;
  FPos:= -1;
end;

end.


DTMF.Threshold:= 1500; // Set amplitude threshold
dieser wert wird in der 1 Unit eingegeben
versuche so den Schwellwert der Soundkarte heraus zu bekommen
und ein vergleich zwischen Rauschen und Sprache zu unterscheiden.

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Di 11.07.06 08:04 
Mensch DAC, du bist doch schon länger hier und weißt doch das bei komplizierten Themen auch ein wenig mehr Text not tut damit es anderen nicht so schwer fällt sich rein zu finden :(

Du willst also den Rauschabstand erfahren?
Wie wäre es, wenn du hier ansetzt

ausblenden Delphi-Quelltext
1:
2:
3:
4:
var Col, Row: Integer;  
  begin  
  //<--Hier-->
    FCols[0]:= GetFreqAmp(1209);


Weil der DTMF Befehlsdekodierer probiert doch die einzelnen Töne zu finden und schaut in dem Stream ob ein Ton mit einer bestimmten Frequenz einen gewissen Ausschlag hat. Ich habe keine Ahnung davon aber müsstest du nicht erstmal die umliegenden Frequenzen checken um das Grundrauschen raus zu kriegen?

Oder du setzt hier an if Assigned(FOnTone) then FOnTone(Self, Tones[FCol, FRow]); weiß ja nicht genau, was du vor hast ;)
dac424 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 12.07.06 20:41 
Titel: Rauschen
ganz einfach ich möchte wenn reine Sprache ist oder Töne das meine STRG Taste emulirt gedrückt wird solte aber rauschen (nur rauschen so wie es bei einem Funkgerät ist)
soll die Taste auf gar keinen Fall emuliert werden. und noch etwas ich habe das problem wenn man die Taste für DTMF drückt wird sie Mehr mal ausgewertet und nicht nur einmal.

Beispiel:

Ich drücke DTMF Ton 2 nun wird bei meiner auswertung 2222222222222222 Angezeigt was Falsch ist ich habe ja nur 1x gedrückt.