Fixed-point signal processor xed-point DSP Festkomma-Signalprozessor Fixed-point signal processor
xed-point DSP xed-point DSP
c Hanspeter Hochreutener c Hans Peter Hochreutener
Zentrum für Signalverarbeitung und Nachrichtentechnik, ZHW Center for Signal Processing and Telecommunications, ZHW
9. 9. Juni 2007 June 2007
Was ist bei xed-point DSPs speziell? What is on xed-point DSPs special?
Die Over ow- und Quantisierungs-Problematik wird aufgezeigt. The over ow and quantization problem is presented.
Die fractional -Zahlenformate, die sättigende Arithmetik, The fractional number formats that saturating arithmetic,
Guard-Bits und Compiler-Intrinsics werden vorgestellt. Guard bits and compiler intrinsics are presented.
Das Vorgehen für die Implementation von FIR- und IIR-Filtern und The procedure for the implementation of FIR and IIR filters and
das Skalieren von Signalen und Koe zienten wird im Detail beschrieben. Scaling of signals and coe cients is described in detail.
Performance-Messungen und Optinmierungs-Tipps runden den Text ab. Performance measurements and Optinmierungs tips round off the text.
Literatur Literature
[von Grünigen] Daniel Ch. von Grünigen, Digitale Signalverarbeitung , 3. [By Grünigen] Daniel Ch of Grünigen, Digital Signal Processing, 3rd Au age, Fachbuchverlag Au age, textbook publisher
Leipzig, ISBN3-446-22861-6 Leipzig, ISBN3-446-22861-6
[Kuo] Sen M. Kuo, Bob H. Lee; Real-Time Digital Signal Processing , John Wiley & sons, ISBN [Kuo] Sen M. Kuo, Bob H. Lee, Real-Time Digital Signal Processing, John Wiley & Sons, ISBN
0-470-84137-0 0-470-84137-0
[Matlab] Matlab-Hilfe zu den Befehlen tf2sos und lternorm [Matlab] Matlab using the commands and tf2sos lternorm
[TMS320C55x] TMS320C55x Optimizing C/C++ Compiler User's Guide , Texas Instruments, [TMS320C55x] TMS320C55x Optimizing C / C + + Compiler User's Guide, Texas Instruments,
spru281f.pdf, http://www.ti.com/litv/pdf/spru281f spru281f.pdf, http://www.ti.com/litv/pdf/spru281f
1 1
Inhaltsverzeichnis Contents
1 Besonderheiten von Festkomma-DSPs A special fixed-point DSPs
3 3
1.1 Fliesskomma- oder Festkomma-DSP? 01/01 floating point or fixed-point DSP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3
1.2 Quantisierung und Überlauf (over ow) . 2.1 Quantization and overflow (over ow). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3
1.2.1 Quantisierung bei der Analog-Digital-Wandlung . 1.2.1 quantization in the analog-digital conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3
1.2.2 Quantisierung der Filterkoe zienten . 1.2.2 Quantization of the air cleaner coefficient. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 4
1.2.3 Quantisierung und Überlauf beim Rechnen . 1.2.3 Quantization and overflow in arithmetic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 4
1.3 Festkomma-Zahlenformat und -Arithmetik . 1.3 Fixed-point number formats and arithmetic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 5
1.3.1 Die fractional -Zahlenformate . 1.3.1 The fractional number formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 5
1.3.2 Sättigende Arithmetik . 1.3.2 Saturating arithmetic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 6
1.3.3 Guard-Bits . 1.3.3 Guard bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7 7
1.3.4 Compiler-Intrinsics . 1.3.4 compiler intrinsics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7 7
1.4 Skalierung von Signalen und Filterkoe zienten . 4.1 Scaling of signals and air cleaner coefficient. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8 8
1.4.1 Filter-Normen l 1.4.1 Filter rules l
2 2
, l , L
∞ ∞
und l and l
1 1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8 8
2 Implementation von FIR-Filtern 2 Implementation of FIR filters
9 9
2.1 Skalierung des Eingangs- und des Ausgangssignals . 2.1 Scaling of the input and the output signal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9 9
2.2 Q15-Skalierung der Filterkoe zienten . 2.2 Q15-scaling coefficient of air cleaner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9 9
2.3 Überlauf von Zwischenresultaten vermeiden . 2.3 About running of intermediate results to avoid. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10 10
3 Implementation von IIR-Filtern 3 Implementation of IIR Filters
11 11
3.1 Skalierung eines einzelnen Biquads . 1.3 Scaling of a single biquads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11 11
3.2 Skalierung einer Kaskade von Biquads: schrittweises Vorgehen . 2.3 scaling of a cascade of biquads: step by step approach. . . . . . . . . . . . . . . . . . . . . . . . .
12 12
3.3 Beispiel: IIR-Implementation mit Compiler-Intrinsics auf dem TMS320C55x . 3.3 Example: IIR implementation with compiler intrinsics on the TMS320C55x. . . . . . . . .
16 16
3.3.1 Performance-Messung und mögliche Verbesserungen . 3.3.1 Performance measurement and possible improvements. . . . . . . . . . . . . . . . . . . . . . . . . . .
18 18
A DSP-C-Code für das IIR-Biquad-Filter in Direktform II A DSP-C code for the IIR biquad filter in direct form II
20 20
B Verzeichnisse B Directories
24 24
Tabellenverzeichnis List of Tables
24 24
Abbildungsverzeichnis List of Figures
24 24
Listings Listings
24 24
2 2
1 Besonderheiten von Festkomma-DSPs A special fixed-point DSPs
1.1 Fliesskomma- oder Festkomma-DSP? 01/01 floating point or fixed-point DSP?
Eine Festkommazahl hat den Dezimalpunkt immer an der gleichen Stelle. A fixed-point number has the decimal point is always the same in place. Üblich ist es den Dezi- Usual, it is the decimal
malpunkt an die vorderste Stelle zu setzen, womit sich ein Zahlenbereich von −1 ≤ zahl < +1 decimal point to the forefront set, which results in a range of -1 ≤ number <+1
ergibt. results.
Eine detaillierte De nition der Festkomma-Formate nden Sie im Abschnitt 1.3.1. A detailed de nition of the fixed-point formats can be in the section 1.3.1.
DSP-Eigenschaft DSP property
Fliesskomma Floating point
Festkomma Fixed-point
Wortbreite Word length
32 Bit (8 Bit Exponent) 16-24 Bit (intern 32-40 Bit) 32-bit (8 bit exponent) 16-24 bit (internal 32-40 bit)
Numerische Stärke Numerical strength
grosser Dynamikumfang hohe Genauigkeit large dynamic range, high accuracy
kein Überlauf no overflow
schnell quickly
Algorithmen- Algorithms
C, C,
Assembler, Assembler,
Implementation Implementation
Assembler Assembler
Compiler-Intrinsics, C Compiler intrinsics, C
Chip äche, Stromverbrauch höher Äch chip, power consumption is higher
niedriger lower
und Hardware-Kosten and hardware costs
Entwicklungs-Aufwand Development effort
geringer low
grösser greater
Schwierigkeit Difficulty
richtige Skalierung right scale
Tabelle 1: Vergleich von Fliesskomma- und Festkomma-DSP Table 1: Comparison of floating point and fixed-point DSP
Aus den wichtigsten Eigenschaften und Unterschieden in der Tabelle ist erkennbar, dass die Wahl From the main characteristics and differences in the table shows that the choice
Festkomma- oder Fliesskomma-DSP stark vom Einsatzgebiet und den Stückzahlen abhängt. Fixed-point or floating point DSP heavily on the application area and the volume depends.
1.2 Quantisierung und Überlauf (over ow) 2.1 Quantization and overflow (over ow)
In jedem digitalen System werden Zahlen durch eine endliche Anzahl Bits dargestellt. In any digital system numbers are a finite number of bits represented by. Dadurch ent- This creates
stehen Rundungsfehler (= Quantisierungsfehler). are rounding errors (= quantization error). Wenn der zulässige Zahlenbereich überschritten If the permissible range exceeded
wird, liegt ein Überlauf (over ow) vor. is, there is an overflow (over ow) before.
1.2.1 Quantisierung bei der Analog-Digital-Wandlung 1.2.1 quantization in the analog-digital conversion
Ein (analoger, zeitkontinuierlicher) Spannungsverlauf wird auf eine (digitale, zeitdiskrete) Zahlenfolge A (analog, continuous-time) voltage profile is a (digital, discrete-time) sequence
abgebildet. shown. Die möglichen Zahlenwerte sind durch die Anzahl Bits des AD-Wandlers gegeben. The possible numerical values are the number of bits given by the AD converter. Die The
analoge Spannung muss auf den nächsten Zahlenwert gerundet werden. analog voltage must be rounded to the next value on. Dieser Rundungsfehler ist This rounding error is
zufällig und wirkt sich wie ein Rauschsignal aus (Quantisierungsrauschen). random and acts as a noise signal (quantization).
Für ein Sinus-Signal das W Bit eines DA-Wandler ausnutzt berechnet sich das Signal-to-Noise-Ratio For a sinusoidal signal, the W-bit DA converter utilizes a calculated signal-to-noise ratio
(SNR) zu: (SNR) to:
SNR ≈ W · 6dB SNR ≈ heat 6dB
(1) (1)
Beispiel: Example:
16-Bit-AD-Wandler mit Eingangs-Spannungsbereich: ±2.5V 16-bit AD converter with input voltage range: ± 2.5V
Sinus-Signal-Amplitude: ±0.1V Sine signal amplitude: ± 0.1V
Ausgenutzt wird Utilization is
0.1V 0.1V
2.5V 2.5V
= 0.04 = = 0.04 =
1 1
25 25
≈ ≈
1 1
2 2
5 5
⇒ −5Bit ⇒-5 bits
Die 5 höchstwertigen Bits des AD-Wandlers werden nicht genutzt, da er nur zu ungefähr The 5 most significant bits of the AD converter is not used, since it only to about
1 1
25 25
ausgesteuert wird. is modulated.
SNR ≈ (16 − 5) · 6dB = 66dB SNR ≈ (16 - 5) · 6dB = 66dB
3 3
Der AD-Wandler soll möglichst gut ausgesteuert werden. The AD converter should be controlled as well.
Übersteuern des AD-Wandlers muss aber unbedingt vermieden werden. Overload of the AD converter, but absolutely must be avoided.
Die Aussteuerung des Eingangssignals lässt sich über die Referenzspannung des AD-Wandlers oder The modulation of the input signal can be above the reference voltage of the AD converter or
über einen vorgeschalteten analogen Verstärker oder Spannungsteiler anpassen. an upstream analog amplifier or voltage divider to adjust.
Die Aussteuerung des Ausgangssignals lässt sich über die Referenzspannung des DA-Wandlers oder The modulation of the output signal can be adjusted on the reference voltage of the DA-converter or
über einen nachgeschalteten analogen Verstärker oder Spannungsteiler anpassen. a downstream analog amplifier or voltage divider to adjust.
1.2.2 Quantisierung der Filterkoe zienten 1.2.2 Quantization of the air cleaner coefficient
Auch die Filterkoe zienten werden in einem DSP durch eine endliche Anzahl Bits dargestellt. The air cleaner is a DSP coefficients by a finite number of bits shown in FIG. Da- Da-
durch werden die Nullstellen und Pole leicht verschoben. by the zeros and poles are easily moved.
Insbesondere Pole und Nullstellen in der Nähe von z = 1 (tiefe Frequenzen) und bei z = -1 (hohe In particular, poles and zeros near z = 1 (low frequency) and at z = -1 (high
Frequenzen in der Nähe von fs/2) sind stark betro en [von Grünigen, Kap. 6.4.3]. Frequencies near fs / 2) are highly Betro en [of Grünigen, Section 6.4.3].
Für ein stabiles System müssen alle Pole innerhalb des z-Einheitskreises liegen. For a stable system all poles of the z-unit circle within. Falls Pole in der If poles in the
Nähe des Einheitskreises liegen, besteht die Gefahr, dass sie durch Quantisierung ausserhalb zu Near the unit circle, there is a risk that they belong due to quantization
liegen kommen und zu einem instabilen System führen. are come and cause an unstable system.
Weil nur IIR-Filter Pole besitzen, betri t das Quantisierungsproblem die FIR-Filter in einem viel Since IIR filters have poles only operated the t Quantisierungsproblem the FIR filter in a much
geringeren Ausmass. lesser extent.
Massnahmen bei IIR-Filtern: Measures in IIR filters:
• Möglichst tiefe Abtastfrequenz fs wählen, damit die Pole möglichst weit auseinan- • If possible, choose low sampling frequency fs so that the poles far apart as possible-
derrücken. . Derrücken
• Biquad-Kaskaden (second order sections) verwenden, damit sich ein Quantisie- • biquad cascading second order sections) use (so that a quantization
rungsfehler nur auf ein einziges Polpaar auswirkt. tion error affects only a single pair of poles.
1.2.3 Quantisierung und Überlauf beim Rechnen 1.2.3 Quantization and overflow in arithmetic
Bei der Addition von Festkomma-Zahlen kann der Betrag des Resultats > 1 werden (over ow). The addition of fixed-point numbers, the amount of the result> 1 (over ow). Bei In
normaler Arithmetik hat das Resultat in diesem Fall ein falsches Vorzeichen, was gravierende Auswir- normal arithmetic, the result in this case, a wrong sign, with serious effects
kungen auf das Signal hat. has effects on the signal. Festkomma-DSPs entschärfen das Problem mit sättigender Arithmetik. Fixed-point DSPs defuse the problem with saturating arithmetic.
Bei der Multiplikation von Festkomma-Zahlen kann kein Überlauf auftreten, aber das Resultat kann In the multiplication of fixed-point numbers may overflow not occur, but what a result
sehr klein werden. be very small. Diese Quantisierung verschlechtert das SNR. This quantization degrades the SNR.
Signale und Koe zienten müssen so skaliert werden, dass der Zahlenbereich (ohne over- Signals and coe cients must be scaled so that the range (without over-
ow) möglichst voll ausgenutzt wird (siehe Abschnitt 1.4). ow) can be utilized fully as possible (see Section 1.4).
Um Rundungsfehler bei Zwischenresultaten zu vermeiden, können diese mit mehr Bits In order to avoid rounding errors in intermediate results, these with more bits
gespeichert werden (Datentyp long statt int oder Guard-Bits verwenden). stored (data type long instead of int or use bits Guard).
4 4
1.3 Festkomma-Zahlenformat und -Arithmetik 1.3 Fixed-point number formats and arithmetic
1.3.1 Die fractional -Zahlenformate 1.3.1 The fractional number formats
Die Erklärungen gelten für 16-Bit-Zweierkomplement-Zahlen, die übelicherweise in xed-Point-DSPs The statements are valid for 16-bit two's complement numbers that übelicherweise in xed-point DSPs
verwendet werden. be used. Das erste Bit ist das Vorzeichenbit. The first bit is the sign bit.
Im Speicher ist für eine Zahl ein Bitmuster aus 16 Bit abgelegt. The memory bit is a bit pattern for a number of 16 stored. Je nach Datentyp wird dieses Bit- Depending on the data type of this bit
Muster unterschiedlich interpretiert. Interpreted in different patterns. Dank der Typisierung bei der Variablen-Deklaration kann der the typing of the variable declaration can Thanks
Compiler sicherstellen, dass eine Variable immer gleich interpretiert wird. Compiler to ensure that a variable is interpreted the same forever. Wenn ein Bitmuster einmal If a bit pattern once
zB als int und einmal als oat interpretiert würde, wäre das Resultat unbrauchbar. such as int, and as interpreted would oat once, the result would be unusable.
Bit-Muster Bit pattern
Dezimal-Wert Decimal value
b b
0 0
b b
1 1
b b
2 2
b b
3 3
b b
4 4
... ... b b
14 14
b b
15 15
−b -B
0 0
· 2 × 2
15 15
+ b + B
1 1
· 2 × 2
14 14
+ ... + ... + b + B
14 14
· 2 × 2
1 1
+ b + B
15 15
· 2 × 2
0 0
Tabelle 2: int-Zahlenformat Table 2: int-number format
Bei FestkommavZahlen gibt es eine Schwierigkeit. In FestkommavZahlen there is a difficulty. Wenn zwei 16-Bit-Zahlen miteinander multipliziert If two 16-bit numbers are multiplied together
werden, entsteht eine 32-Bit-Zahl. , there arises a 32-bit number. Wie soll dieses Resultat nun in einer 16-Bit-Variablen gespeichert As a result of this is now a 16-bit variables stored in
werden? be? Bei den MAC-Operationen (multiply and accumulate) im DSP gibt es sehr viele Multi- In the MAC operations (multiply and accumulate) in the DSP, there are many multi-
plikationen. complications. Um damit einfacher umgehen zu können, hat man das fractional -Zahlenformat mit thus easier to work around, can you have the fractional number format
einem Wertebereich von ±1 de niert. with values ranging from ± 1 de ned. Multipliziert man zwei solche fractional-Zahlen miteinander ist Multiplying two such fractional numbers is another
das Resultat ebenfalls im Wertebereich von ±1 und kann problemlos weiterverwendet werden. the result also in the range of ± 1 and can be reused easily. DSPs DSPs
haben spezielle Hardware-Multiplizierer, welche direkt mit fractional-Zahlen arbeiten. have special hardware multiplier directly with fractional numbers which work.
Bit-Muster Bit pattern
Dezimal-Wert Decimal value
b b
0 0
b b
1 1
b b
2 2
b b
3 3
b b
4 4
... ... b b
14 14
b b
15 15
−b -B
0 0
· 2 × 2
0 0
+ b + B
1 1
· 2 × 2
−1 -1
+ ... + ... + b + B
14 14
· 2 × 2
−14 -14
+ b + B
15 15
· 2 × 2
−15 -15
Tabelle 3: Q15-fractional-Zahlenformat Table 3: Q15-fractional number format
Ein Vergleich der Tabellen 2 und 3 zeigt, dass es im gespeicherten Bitmuster keinen Unterschied A comparison of Tables 2 and 3 shows that there is no difference in the stored bit pattern
gibt. There. Letztlich ist die Stelle des Dezimalpunktes eine reine Konvention, welche der Programmierer Ultimately, the decimal point of a pure convention, which the programmer
beachten muss. must be observed. Ein Bitmuster kann also je nach Bedarf als Integer- oder als Q15-Wert interpretiert A bit pattern can therefore as required or as an integer value interpreted as Q15-
werden. be.
Die Position des Dezimalpunktes wird in den Variablen nicht gespeichert. The position of the decimal point is not stored in the variables. Der Program- The Program
mierer ist selbst dafür verantwortlich, dass bei Festkomma-Zahlen das Bit=MMuster programmer is responsible for ensuring that, when fixed-point numbers, bit = MMuster
im Speicher richtig verwendet wird. properly used is in memory.
Die Tabelle 4 zeigt erläuternde Beispiele: Table 4 shows illustrative examples:
Das Q0.15-Format bedeutet kein Vorkommabit und 15 Nachkommabits. The Q0.15 format means no Vorkommabit and 15 Nachkommabits. Oft spricht man abgekürzt One often speaks in abbreviated form
vom Q15-Format. the Q15 format. Der Wertebereich umfasst ±1. The range is ± 1
Im Texas-Instruments-DSP TMS320C55x entspricht der zu int kompatible Datentyp DATA dem In Texas Instruments' TMS320C55x DSP corresponding to the compatible data type int to the DATA
Q15-Format. Q15 format.
Das Q1.14-Format (kurz Q14) hat 1 Vorkomma- und 14 Nachkommabits. The Q1.14 format (Q14 short) has 1 to 14 places before Nachkommabits. Der Wertebereich ist ±2. The range is ± 2
Das Q15.0-Format hat 15 Vorkomma- und keine Nachkommabits; das ist das normale int-Format mit Q15.0 The format has 15 places before and no Nachkommabits, that's the normal format with int
einem Wertebereich von −32 768..32 767 with values ranging from -32 768th .32 767
Das Q0.31-Format (kurz Q31) hat kein Vorkommabit und 31 Nachkommabits. The Q0.31 format (Q31 short) has no Vorkommabit and 31 Nachkommabits. Der Quantisierungs- The quantization
fehler ist also 2 error is thus 2
16 16
mal kleiner als beim Q0.15-Format. times smaller than in Q0.15 format. Der Wertebereich umfasst ±1. The range is ± 1
5 5
Binär Binary
Hexadezimal Integer-Wert Q15-Wert Hexadecimal integer value Q15
0000000000000000 0000 0000000000000000 0000
0 0
0 0
0000000000000001 0001 0000000000000001 0001
1 1
0.0000305... 0.0000305 ...
1111111111111111 FFFF 1111111111111111 FFFF
-1 -1
-0.0000305... -0.0000305 ...
0111111111111111 7FFF 0111111111111111 7FFF
32'767 32'767
0.9999695... 0.9999695 ...
1000000000000000 80000 1000000000000000 80 000
-32'768 -32 '768
-1 -1
0100000000000000 4000 0100000000000000 4000
16'384 16'384
0.5 0.5
0110000000000000 6000 0110000000000000 6000
24'576 24'576
0.75 0.75
1110000000000000 C000 1110000000000000 C000
-8'192 -8 '192
-0.25 -0.25
Tabelle 4: Festkomma-Zahlenformate Table 4: Fixed-point number formats
Im Texas-Instruments-DSP TMS320C55x entspricht der zu long kompatible Datentyp LDATA In Texas Instruments' TMS320C55x DSP corresponds to the long-compatible data type ldata
dem Q31-Format. the Q31 format.
Umwandlung Operation Conversion operation
Bemerkung Note
Q0.15 ⇒ int Q0.15 ⇒ int
intZahl = Q0.15Zahl·2 intZahl Q0.15Zahl × 2 =
15 15
int ⇒ Q0.15 int ⇒ Q0.15
Q0.15Zahl = intZahl/2 Q0.15Zahl = intZahl / 2
15 15
Q0.15 ⇒ Q1.14 Q1.14Zahl = Q0.15Zahl 1 Q0.15 Q1.14 ⇒ Q1.14Zahl Q0.15Zahl = 1
um 1 Position nach rechts schieben 1 position to the right to push
Q1.14 ⇒ Q0.15 Q0.15Zahl = Q1.14Zahl 1 Q1.14 Q0.15 ⇒ Q0.15Zahl Q1.14Zahl = 1
Over ow, falls Betrag ≥ 1 Over ow, if the amount ≥ 1
Q0.15 ⇒ Q0.31 Q0.31Zahl = Q0.15Zahl 16 um 16 Position nach links schieben Q0.15 Q0.31 ⇒ Q0.31Zahl Q0.15Zahl = 16 at 16 position to the left
Q0.31 ⇒ Q0.15 Q0.15Zahl = Q0.31Zahl 16 letzte 16 Bits abschneiden Q0.31 Q0.15 Q0.15Zahl = ⇒ Q0.31Zahl last 16 bits cut 16
Tabelle 5: Zahlenformate umwandeln/umrechnen/uminterpretieren Table 5: Convert to convert / / reinterpret number formats
1.3.2 Sättigende Arithmetik 1.3.2 Saturating arithmetic
Mit den Q15- und Q31-Zahlenformaten ist ein Überlauf bei der Multiplikation ausgeschlossen. With the Q15 and Q31-number format is an overflow in the multiplication excluded. Bei In
Addition und Subtraktion sind Überläufe hingegen weiterhin möglich. Addition and subtraction are overflows, however, still possible. Das vorderste Bit des Resultats The first bit of the result
hat im Speicher keinen Platz, was einem massiven Fehler gleichkommt. has no place in the memory of what amounts to a massive mistake.
Die Tabelle 6 illustriert den Sachverhalt beispielhaft: Table 6 illustrates the situation as an example:
Operation (Q15) Operation (Q15)
mit Überlauf with overflow
mit Sättigung with saturation
0100000000000000 + 0100000000000000 1000000000000000 0100000000000000 + 0100000000000000 1000000000000000
0111111111111111 0111111111111111
0.5 + 0.5 0.5 + 0.5
-1.0 Vorzeichenbit! -1.0 Sign!
0.9999695... 0.9999695 ...
0110000000000000 + 0110000000000000 1100000000000000 0110000000000000 + 0110000000000000 1100000000000000
0111111111111111 0111111111111111
0.75 + 0.75 0.75 + 0.75
-0.5 -0.5
0.9999695... 0.9999695 ...
1100000000000000 + 1100000000000000 1000000000000000 1100000000000000 + 1100000000000000 1000000000000000
1000000000000000 1000000000000000
-0.5 + (-0.5) -0.5 + (-0.5)
-1.0 noch im Zahlenbereich -1.0 -1.0 Still in range -1.0
1010000000000000 + 1010000000000000 0100000000000000 1010000000000000 + 1010000000000000 0100000000000000
1000000000000000 1000000000000000
-0.75 + (-0.75) -0.75 + (-0.75)
0.5 0.5
-1.0 -1.0
Tabelle 6: Vergleich Überlauf und sättigende Arithmetik Table 6: Comparison of overflow and saturating arithmetic
DSPs haben ein over ow -Bit, das gesetzt wird, wenn der Zahlenbereich überschritten wird. DSPs have an over ow-bit that is set when the range is exceeded. Wenn If
das saturate -bit gesetzt ist, erscheint bei over ow der maximal darstellbare Wert mit dem richtigen the bit is set to saturate appear in ow over the maximum representable value with the right
Vorzeichen. Sign. Aus der Tabelle 6 ist erkennbar, dass der Fehler beim gesättigten Wert viel kleiner ist From Table 6 shows that the error is much less saturated value
und auf jeden Fall das Vorzeichen stimmt! and in any case, the sign of true!
6 6
Bei Filteralgorithmen mit vielen MAC-Operationen muss unbedingt von der sättigenden Arithme- When filtering algorithms with many MAC operations is essential from the saturating arithmetic
tik Gebrauch gemacht werden. tics made use of. Überläufe von Zwischenresultaten erzeugen so lediglich ein etwas Overflows of intermediate results thus produce only a slightly
schlechteres SNR. worse SNR.
Sättigende Arithmetik gibt es in C leider nicht! Saturating arithmetic is unfortunately not in C! Mit DSPs gibt es zwei Möglichkeiten With the DSPs, there are two possibilities
von der sättigenden Arithmetik Gebrauch zu machen: saturating arithmetic to make use of the:
• Programmieren in Assembler • Programming in assembler
• Benutzen von Compiler-Intrinsics • Use of compiler intrinsics
1.3.3 Guard-Bits 1.3.3 Guard bits
Bei richtig skalierten Signalen und Filterkoe zienten können Zwischenresultate ausserhalb ±1 vor- scaled signals and air cleaner can really coefficient for intermediate results outside ± 1 prior-
kommen, auch wenn das Schlussresultat innerhalb ±1 liegt. come, and the final result within ± 1 is when. Bei Festkomma-DSPs sind die internen For fixed-point DSPs are the internal
Register deshalb meist 8 Bit länger. Register therefore mostly 8 bit longer. Es können also mindestens 256 Additionen/Subtraktionen aus- It may therefore at least 256 additions / subtractions from-
geführt werden, bevor das Register überläuft. be made before the register overflows.
Die Guard-Bits sind Bestandteil der DSP-internen Register und können deshalb nur in The guard bits are part of the DSP's internal registers and can therefore only
Assembler-Programmen genutzt werden. Assembler programs can be used.
1.3.4 Compiler-Intrinsics 1.3.4 Compiler Intrinsics
Spezielle Fähigkeiten der DSPs, wie sättigende Arithmetik und MAC-Operationen, können in Stan- Special skills of DSPs, such as saturating arithmetic and MAC operations can, in Stan-
dard-C nicht abgebildet werden. standard-C are not shown. Und programmieren in Assembler ist aber sehr aufwändig. And program in assembly language is very complicated.
Die Compiler-Intrinsics stellen eine einfache Möglichkeit dar, um einen Teil der DSP-Spezialitäten The compiler intrinsics provide is a simple way to keep part of the DSP-specialties
aus einem C-Programm nutzen zu können. a C program to be able to exploit. Wenn Assembler-Code oder Compiler-Intrinsics verwendet When assembly code or compiler intrinsics used
werden, ist der Code mit anderen DSPs nicht mehr kompatibel. will be the code with other DSPs no longer compatible.
In der Tabelle 7 sind die meist gebrauchten Compiler-Intrinsics für den DSP TMS320C55x aufgeführt. In Table 7 are the most common TMS320C55x intrinsics compiler for the DSP listed.
Bemerkung: Der Q15-Datentyp int ist kompatibel zu DATA und long zu LDATA . Note: Q15 data type int is compatible with DATA and long to ldata.
Compiler-Intrinsic Compiler Intrinsic
Beschreibung Description
int _sadd(int src1, int src2); _sadd int (int src1, int src2);
gesättigte Q15-Summe der Operanden Q15-saturated sum of the operands
long _lsadd(long src1, long src2); _lsadd long (long src1, long src2);
dito für Q31 ditto for Q31
int _ssub(int src1, int src2); _ssub int (int src1, int src2);
gesättigte Di erenz src1 - src2 saturated di erence src1 - src2
long _lssub(long src1, long src2); _lssub long (long src1, long src2);
dito für Q31 ditto for Q31
int _smpy(int src1, int src2); _smpy int (int src1, int src2);
gesättigtes Q15-fractional-Produkt saturated fractional-Q15 product
long _lsmpy(int src1, int src2); long _lsmpy (int src1, int src2);
dito für Q31 ditto for Q31
long _smac(long src1, int src2, int src3); gesättigte Q31-Summe von src1 + Produkt src2*src3 _smac long (long src1, int src2, int SRC3), Q31-saturated sum of src1 + src2 * Product SRC3
long _smas(long src1, int src2, int src3); gesättigte Q31-Di erenz von src1 - Produkt src2*src3 _smas long (long src1, int src2, int SRC3); saturated Q31-di erence of src1 - src2 * Product SRC3
int _sshl(int src1, int src2); _sshl int (int src1, int src2);
gesättigtes Q15-Resultat von (src1 src2) Q15-saturated result of (src1 src2)
long _lsshl(long src1, int src2); _lsshl long (long src1, int src2);
dito für Q31 ditto for Q31
int _shrs(int src1, int src2); _shrs int (int src1, int src2);
gesättigtes Q15-Resultat von (src1 src2) Q15-saturated result of (src1 src2)
long _lshrs(long src1, int src2); _lshrs long (long src1, int src2);
dito für Q31 ditto for Q31
Tabelle 7: Oft verwendete TMS320C55x-Compiler-Intrinsics Table 7: Often used TMS320C55x compiler intrinsics
Eine vollständige Liste für diesen DSP ndet sich in [TMS320C55x, Kapitel 6.5.4]. For a complete list for the DSP Raft in [TMS320C55x, Chapter 6.5.4].
7 7
1.4 Skalierung von Signalen und Filterkoe zienten 4.1 Scaling of signals and air cleaner coefficient
Die Eingangs-Signale vom AD-Wandler müssen so skaliert werden, dass sie in den Datentyp passen, The input signals from the AD converter must be scaled so that they fit into the type of data,
der für die Speicherung und Rechnung verwendet wird. the storage and accounting is used for.
Die Filter-Koe zienten müssen so skaliert werden, dass die (Zwischen-) Resultate ein möglichst The filter coe cients must be scaled so that the (interim) results, a possible
gutes SNR aufweisen ohne überzulaufen. have good SNR without overflowing. Ev. Ev. müssen Eingangssignale und Zwischenresultate skaliert need to input signals and intermediate results scaled
werden, bevor der nächste Verarbeitungs-Schritt erfolgt. be before next processing step, the. Sporadisches Überlaufen kann akzeptiert Sporadic spillover can accept
werden, wenn mit sättigender Arithmetik gearbeitet wird. be when saturating arithmetic is working with.
Die Ausgangs-Signale zum DA-Wandler müssen so skaliert werden, dass sie den DA-Wandler mög- The output signals to D / A converter must be scaled so that they DAC possible the-
lichst gut aussteuern. disqualify well as possible. Überlaufen muss unbedingt verhindert werden, da durch das Modulo-Verhalten It is essential to prevent overflow, since the modulo behavior
der Ausgang von einem Anschlag zum anderen springen würde. Starting from a stop to the other would jump.
Die genaue Vorgehensweise beim Skalieren hängt von der Filterart und der verwendeten Struktur ab. The exact procedure depends on the filter type and scale of the structure used on.
In den nächsten Abschnitten wird es exemplarisch aufgezeigt für FIR-Filter in Direktform und für In the next sections it is shown exemplary for FIR filters in direct form and for
IIR-Filter mit Biquad-Kaskaden in Direktform II. IIR filter with cascaded biquad direct form II in
1.4.1 Filter-Normen l 1.4.1 Filter rules l
2 2
, l , L
∞ ∞
und l and l
1 1
Für die weiteren Betrachtungen wird, wo nichts anderes angegeben wurde, das fractional-Zahlenfor- For the further considerations is where otherwise specified, the fractional-Zahlenfor-
mat mit −1 ≤ zahl < +1 angenommen. mat with -1 ≤ <number adopted +1.
Das Ausgangssignal eines Digital lters ist die Faltung des Eingangssignals mit der Impulsantwort. The output signal of a digital lter is the convolution of the input signal with the impulse response.
y[n] = h[n] ∗ x[n] = y [n] = h [n] x * [n] =
N N
∑ Σ
k=0 k = 0
h[k] · x[n − k] h [k] • X [n - k]
(2) (2)
Da das Eingangssignal |x[n]| < 1 ist, ist |y[n]| ≤ als obige Summe. Since the input signal | x [n] | <1 is, | y [n] | ≤ than the above sum.
l l
1 1
= =
N N
∑ Σ
k=0 k = 0
|h[k]| | H [k] |
(3) (3)
Wenn die Eingangsfolge x[n] durch die l If the input sequence x [n] by the l
1 1
-Norm des Filters dividiert wird, ist ein Zah- -Norm of the filter is divided, is a pay-
lenüberlauf beim Ausgangssignal y[n] für jede beliebige Eingangsfolge ausgeschlossen. the output signal y [n] for any input sequence lenüberlauf excluded.
Falls l If l
1 1
< 1 ist, wird durch die Skalierung des Eingangssignals mit s = 1/l <1 is, by scaling the input signal with s = 1 / l
1 1
das SNR verschlechtert. the SNR is degraded.
Da die l Since the l
1 1
-Norm den worst-case-Fall abdeckt, der praktisch kaum vorkommt, wurden zwei weitere Standard worst-case covering the case, which hardly happens in practice, two other
Normen de niert. De ned standards.
l∞ = max l ∞ = max
(f) (F)
∣ |
∣ |
∣ |
H(e H (e
j·2π·f·Ts j * 2π × F × T
) )
∣ |
∣ |
∣ |
(4) (4)
Wenn die Eingangsfolge x[n] durch die l∞-Norm (= Tschebysche -Norm) des Filters If the input sequence x [n] by the l ∞-norm (= Tschebysche standard) of the filter
dividiert wird, ist ein Zahlenüberlauf beim Ausgangssignal y[n] für jedes stationäre is divided, is a numerical overflow in the output signal y [n] for each patient
Sinussignal ausgeschlossen. Sine signal excluded.
l l
2 2
= =
√ √
√ √
√ √
√ √
N N
∑ Σ
k=0 k = 0
h h
2 2
[k] [K]
(5) (5)
Wenn die Eingangsfolge x[n] durch die l If the input sequence x [n] by the l
2 2
-Norm des Filters dividiert wird, erreicht man -Norm of the filter is divided reached,
das beste SNR. the best SNR.
8 8
l l
2 2
≤ l∞ ≤ l ≤ l ∞ ≤ l
1 1
(6) (6)
Die Wahl der Filternorm, resp. The choice of the filter standard, respectively. des Skalierungsfaktors für die Eingangsfolge ist immer ein Kompro- the scaling factor for the input sequence is always a compromise
miss. miss. Kleinere Filternorm verbessert das SNR und erhöht die Wahrscheinlichkeit eines Überlaufs. Smaller standard filter improves the SNR and increases the likelihood of an overflow.
Die l The l
2 2
- und die l∞-Filternormen können mit dem Matlab-Befehl lternorm berechnet werden. - And the l ∞-filter standards can command lternorm be calculated with the Matlab. Die The
l l
1 1
-Norm lässt sich im Matlab so berechnen: sum(abs(h)) Standard can be calculated in Matlab as follows: sum (abs (h))
2 Implementation von FIR-Filtern 2 Implementation of FIR filters
wird exemplarisch aufgezeigt für FIR-Filter in der Direktform. is shown exemplary for FIR filter in direct form.
b b
0 0
z z
-1 -1
x[n-1] x [n-1]
z z
-1 -1
x[n-2] x [n-2]
z z
-1 -1
x[nN] x [nN]
b b
1 1
b b
2 2
b b
N-1 N-1
b b
N N
x[n-(N-1)] x [n-(N-1)]
y[n] y [n]
g g
out out
x[n] x [n]
g g
in in
FIR-Filter in Direktform FIR filter in direct form
Abbildung 1: FIR-Filter in Direktform Figure 1: FIR filter in direct form
Auf die Bestimmung der b-Koe zienten der Übertragungs-Funktion H(z) wird hier nicht eingegan- The determination of the b-coe cients of the transfer function H (z) is not here eingegan-
gen. Es wird angenommen dass die Filterkoe zienten bereits bestimmt wurden. It is believed that Gen. air cleaner, the coefficients have been determined. Die Ausgangsfolge The output sequence
berechnet sich mit Hilfe der folgenden Di erenzengleichung: calculated using the following di erenzengleichung are:
y[n] = b[n] ∗ x[n] = y [n] = b [n] * x [n] =
N N
∑ Σ
k=0 k = 0
b[k] · x[n − k] b [k] • X [n - k]
(7) (7)
2.1 Skalierung des Eingangs- und des Ausgangssignals 2.1 Scaling of the input and the output signal
Zuerst die gewünschte Filternorm gemäss Abschnitt 1.4 berechnet. First, the desired filter norm according to Section 1.4 calculated. Falls die Norm > 1 ist, muss If the standard is a> must
das Eingangssignal mit g the input signal with g
in in
= 1/Norm skaliert werden, damit das Ausgangssignal nicht zu stark = 1/Norm be scaled to the output signal is not too strong
überläuft/sättigt. overflow / saturates.
Falls AD- resp. If AD, respectively. DA-Wandler einen anderen Zahlenbereich aufweisen als bei der Rechnung verwendet DA converter has a different number range are used in the bill as
wird, kann das mit g is capable of using g
in in
resp. respectively. g g
out out
angepasst werden. be adjusted.
2.2 Q15-Skalierung der Filterkoe zienten 2.2 Q15-scaling coefficient of air cleaner
Der Q-15-Zahlenbereich ist −1 ≤ zahl < 1. The Q-15-speed range is -1 ≤ number <1 Alle Filterkoe zienten müssen diese Bedingung erfüllen. Air cleaner coefficients must all meet this condition.
Anderenfalls müssen die Filter-Koe zienten skaliert werden mit s = 1/max(|b Otherwise, the filter coe cients are scaled with s = 1/max (| b
k k
|). |). Diese Skalierung This scaling
kann rückgängig gemacht werden, indem der Ausgang mit g can be undone by the output of g
out out
= s multipliziert wird. = S is multiplied.
Oft wird s auf die nächste 2er-Potenz gerundet, da die Rückskalierung so durch eine einfache Schie- S is often the next power of 2 rounded to as the scaling back so by a simple sliding-
beoperation statt einer Multiplikation mit g beoperation instead of a multiplication with g
out out
erledigt werden kann. can be done.
9 9
2.3 Überlauf von Zwischenresultaten vermeiden 2.3 About running of intermediate results to avoid
Einhalten der Filternorm sagt nur etwas aus über das fertig berechnete Ausgangssignal. Compliance with the standard filter says something only about the finished calculated output signal. Es verhindert It prevents
nicht, dass Zwischenresultate überlaufen können. not that interim results can overflow. ZB können in der Gleichung 7 die ersten Produkte For example, in the equation 7, the first products
eine positive Zahl ergeben und die letzten eine negative. give a positive number and the last one negative. Das Resultat kann im zulässigen Wertebereich The result is within the permissible range of values
liegen, auch wenn Zwischensummen ausserhalb liegen. lie, even when subtotals are outside.
Es gibt drei Massnahmen, die einen Überlauf bei den Zwischensummen verhindern: There are three measures, an overflow in the subtotals prevent:
• Anwenden der l • applying the l
1 1
-Norm verhindert prinzipiell einen Überlauf, verschlechtert aber das SNR Standard principle prevents an overflow, but deteriorates the SNR
Listing 1: FIR-Code-Ausschnitt für den TMS320C55x Listing 1: FIR code snippet for the TMS320C55x
DATA x , y ; DATA x, y;
// x [ n ] und y [ n ] , DATA = Q15 / / X [n] and y [n], DATA = Q15
LDATA temp = 0; Ldata temp = 0;
// Zwischenresultat , LDATA = Q31 / / Intermediate result ldata = Q31
DATA b [ . DATA b [. . . . . ] ; ];
// b−Koeffizienten , DATA = Q15 / / B-coefficients, DATA = Q15
DATA buffer [ . DATA buffer [. . . . . ] ; ];
// verzögerte x−Werte / / Delayed x values
. . . . . .
// for−S chleife Differenzen−Gleichung / / For S-chleife difference equation
temp = _smac(temp , b [ k ] , buffer [ n−k ] ) ; // temp = temp+b [ k ]∗ x [n−k ] , sättigend _smac temp = (temp, b [k], buffer [n-k]) / / temp = temp + b [k]] * x [n-k, satisfying
. . . . . .
// Ende for−S chleife Differenzen−Gl . / / End for-S chleife Difference Eq.
y = temp >> 16; y = temp>> 16;
// Q31 => Q15 / / Q31 => Q15
• Aufsummieren in den DSP-internen Registern mit Guard-Bits. • summing up in the DSP's internal registers with guard bits. Üblich sind 8 Guard-Bits, was Usual, 8 Guard bits, which
einen Überlauf bis zu 256 Koe zienten theoretisch und praktisch auch für Filter höherer Ord- an overflow of up to 256 coe cient theoretical and practical for higher-order filter
nung ausschliesst. excludes planning. Dazu muss man den Algorithmus in Assembler programmieren. This requires you to program the algorithm in assembly language.
• Zwischenresultate speichern im Q8.23-Format. • Interim results are saved in Q8.23 format. Die 8 Vorkommabits wirken wie die Guard-Bits The 8 Vorkommabits act as the guard bits
und die (gegenüber Q15) zusätzlichen 8 Nachkommabits verhindern spürbare Quantisierungs- and (compared to Q15) additional 8 Nachkommabits prevent significant quantization
fehler. error.
Listing 2: FIR-Code-Ausschnitt für den TMS320C55x mit Überlauf-Schutz Listing 2: FIR code for the TMS320C55x-neck with overflow protection
DATA x , y ; DATA x, y;
// x [ n ] und y [ n ] , DATA = Q15 / / X [n] and y [n], DATA = Q15
LDATA zwischen = 0 , temp = 0; Ldata between = 0, temp = 0;
// Zwischenresultate , LDATA = Q31 / / Intermediate results, ldata = Q31
DATA b [ . DATA b [. . . . . ] ; ];
// b−Koeffizienten , DATA = Q15 / / B-coefficients, DATA = Q15
DATA buffer [ . DATA buffer [. . . . . ] ; ];
// verzögerte x−Werte / / Delayed x values
. . . . . .
// for−S chleife Differenzen−Gleichung / / For S-chleife difference equation
temp = _lsmpy(b [ k ] , buffer [ n−k ] ; temp = _lsmpy (b [k], buffer [n-k];
// temp = b [ k ] ∗ x [n−k ] , sättigend / / Temp = b [k] * x [n-k], satisfying
temp = temp >> 8; temp = temp>> 8;
// Q31 => Q8.23 / Q31 => Q8.23 /
zwischen = _lsadd ( zwischen , temp ) ; between = _lsadd (between, temp);
// zwischen = zwischen+temp , sättigend / / Between = between + temp, filling
. . . . . .
// Ende for−S chleife Differenzen−Gl . / / End for-S chleife Difference Eq.
zwischen = _lshrs ( zwischen , 8); between = _lshrs (between, 8);
// Q8.23 => Q31, sättigend / Q8.23 => Q31 /, satisfying
y = zwischen >> 16; y = between>> 16;
// Q31 => Q15 / / Q31 => Q15
Das ist weniger e zient als Assembler-Programmierung, aber viel e zienter als Rechnen mit That is less e cient assembly programming, but much more e cient than a calculation with
oat auf einem Festkomma-DSP. oat on a fixed-point DSP.
Bei der Implementation des (langen) Verzögerungsbu ers in einem FIR-Filter muss unbedingt ein In the implementation of the (long) Verzögerungsbu first in a FIR filter must necessarily
Ringbu er verwendet werden. Ringbu he used. Statt so viele Variabeln zu kopieren, wie das Filter lang ist, muss bloss Instead of variables to copy as many as the filter is long, it just
ein Pointer inkrementiert und eine Modulo-Operation druchgeführt werden. a pointer is incremented and a modulo operation will druchgeführt.
10 10
3 Implementation von IIR-Filtern 3 Implementation of IIR Filters
wird exemplarisch aufgezeigt für IIR-Filter mit Biquad-Kaskaden in Direktform II. is shown exemplary for IIR filter with cascaded biquad direct form II in
Auf die Bestimmung der b- und a-Koe zienten der Übertragungs-Funktion H(z) wird hier nicht The determination of the b-and a-coe cients of the transfer function H (z) is not
eingegangen. received. Es wird angenommen dass die Filterkoe zienten bereits bestimmt wurden. It is believed that the air cleaner coefficients have been determined.
Die Ausgangsfolge berechnet sich mit Hilfe der folgenden Di erenzengleichung: The output sequence is calculated using the following di erenzengleichung with:
y[n] = y [n] =
N N
∑ Σ
k=0 k = 0
b[k] · x[n − k] − b [k] • X [n - k] -
M M
∑ Σ
k=1 k = 1
a[k] · y[n − k] a [k] * y [n - k]
(8) (8)
Die Skalierung der Signale und Filterkoe zienten beein ussen sich gegenseitig, weil vergangene Aus- The scaling of the signals and air cleaner coefficients have to influence each other, because in the past training
gangssignale in die Berechnung ein iessen (IIR-Filter sind rekursiv). output signals are recursive filter) into a Jesse (the calculation IIR.
Quantisierungsfehler wirken sich weniger stark aus, wenn IIR-Filter als Biquad-Kaskade (second or- Quantization have strong impacts less if IIR filter as a cascade biquad (second or-
der sections) implementiert werden, weil sich ein Quantisierungsfehler so nur auf jeweils ein Polpaar the sections will be implemented), since a quantization error so only on one pair of poles
auswirken kann. can have.
Die Biquads können in Direktstruktur I, in Direktstruktur II oder in transponierter Direktstruktur The biquads may direct in structure I, structure II in direct or transposed direct structure
II realisiert werden. II can be realized. Im Folgenden wird die Direktstruktur II verwendet, da sie durch Matlab-Tools The following structure is used to direct II, since they are Matlab tools
am Besten unterstützt wird. support is best at.
Aus den b- und a-Koe zienten der Übertragungs-Funktion H(z) können mit dem Matlab-Befehl From the b-and a-coe cients of the transfer function H (z) can use the Matlab command
tf2sos die Filterkoe zienten der Biquads berechnet werden. tf2sos the coefficient of the air cleaner biquads be calculated.
x[n] x [n]
y[n] y [n]
z z
-1 -1
b b
11 11
b b
01 01
-a -A
11 11
z z
-1 -1
b b
21 21
-a -A
21 21
w w
1 1
[n] [N]
w w
1 1
[n-1] [N-1]
w w
1 1
[n-2] [N-2]
z z
-1 -1
b b
12 12
b b
02 02
-a -A
12 12
z z
-1 -1
b b
22 22
-a -A
22 22
w w
2 2
[n] [N]
w w
2 2
[n-1] [N-1]
w w
2 2
[n-2] [N-2]
y y
1 1
[n] [N]
y y
2 2
[n] [N]
g g
in in
g g
out out
Abbildung 2: IIR-Filter mit Biquad-Kaskaden in Direktform II Figure 2: IIR filter with cascaded biquad direct form II in
Die Berechnung eines einzelnen Biquads erfolgt mit diesen Formeln: The calculation of a single biquads done with these formulas:
w[n] = w [n] =
x[n] − a x [n] - a
1 1
· w[n − 1] − a ⋅ w [n - 1] - a
2 2
· w[n − 2] ⋅ w [n - 2]
y[n] = b y [n] = b
0 0
· w[n] + b ⋅ w [n] + b
1 1
· w[n − 1] + b ⋅ w [n - 1] + b
2 2
· w[n − 2] ⋅ w [n - 2]
(9) (9)
3.1 Skalierung eines einzelnen Biquads 1.3 Scaling of a single biquads
Sowohl bei der Berechnung von w[n] als auch von y[n] kann ein Überlauf auftreten. Both in the calculation of w [n] and y [n] can overflow occur.
Da a As a
0 0
immer 1 ist, können a is always 1, to a
1 1
und a and a
2 2
nicht skaliert werden, ohne die Lage der Pole zu verändern. not be scaled without changing the position of the poles. Ein A
Überlauf bei der Berechnung von w[n] kann deshalb nur vermieden werden, wenn das Eingangssignal Overflow in the calculation of w [n] can therefore be avoided only when the input signal
richtig skaliert wird. is scaled correctly.
Diese Einschränkung gibt es bei den b-Koe zienten nicht. This restriction is there for the b-coe cients not. Sie können so skaliert werden, dass der They can be scaled so that the
Ausgang y[n] und das Zwischenresultat w[n] des nächsten Biquads nicht überlaufen. Output y [n] and the intermediate result w [n] of the next biquads not busy.
11 11
Aus dem Nenner einer Biquad-Übertragungsfunktion können die Pole berechnet werden. From the denominator of a biquad transfer function, the poles are calculated. Für einen For a
stabilen Biquad mit reellen Koe zienten müssen die konjugiert komplexen Pole im z-Einheitskreis stable biquad coe cients must be real with the complex conjugate poles in the z-unit circle
liegen und es gilt: lie and we have:
1 + a 1 + a
1 1
· z • Z
−1 -1
+ a + A
2 2
· z • Z
−2 -2
= (1 − p · z = (1 - p * z
−1 -1
) · (1 − p ) * (1 - p
∗ *
· z • Z
−1 -1
) p = Pol ) P = Pol
a a
0 0
= 1 = 1
a a
1 1
= −(p + p = - (P + p
∗ *
) = −2 · (p) ) = -2 * (P)
|a | A
1 1
| < 1 + a | <1 + a
2 2
< 2 <2
(10) (10)
a a
2 2
= p · p = P * p
∗ *
= |p| = | P |
2 2
|a | A
2 2
| < 1 | <1
Das heisst, das a This means that a
1 1
für übliche Filter nicht im Q15-Format gespeichert werden kann! not in the Q15-format can be saved for conventional filters!
Lösung: Alle Koe zienten werden halbiert und im Q15-Format abgespeichert und der Algorithmus Solution: All coe cients are halved and Q15 format and stored in the algorithm
entsprechend modi ziert. modi ed accordingly.
Da die b-Filterkoe zienten vor dem Abspeichern halbiert werden, muss |b Since the b-coefficient air cleaner are halved, before saving has | b
k k
| < 2 erfüllt sein. | <2 are satisfied.
Das Eingangssignal x[n] wird mit 1/4 skaliert, um einen Überlauf bei den Zwischenresultaten und The input signal x [n] is fourth with scaled to an overflow at the intermediate results and
bei w[n] zu vermeiden. [N] w to avoid. Beim Ausgangssignal y[n] wird die Skalierung rückgängig gemacht. The output signal y [n] the scaling is reversed.
Wenn man für das Zwischenresultats das Format Q31 verwendet, gehen keine Bits verloren und das If one of the intermediate result format Q31 used to go and no bits lost
SNR wird nicht verschlechtert. SNR is not degraded.
Die Gleichung 9 wird modi ziert zu: The equation 9 is modi ed to:
w[n] = w [n] =
2 · (x[n]/4 − a 2 * (x [n] / 4 - a
1 1
/2 · w[n − 1] − a / 2 * w [n - 1] - a
2 2
/2 · w[n − 2]) / 2 * w [n - 2])
y[n] = 4 · (b y [n] = 4 × (b
0 0
/2 · w[n] + b / 2 * w [n] + b
1 1
/2 · w[n − 1] + b / 2 * w [n - 1] + b
2 2
/2 · w[n − 2]) / 2 * w [n - 2])
(11) (11)
Das Vorgehen beim Halbieren aller Filterkoe zienten kann aus einem anderen Blickwinkel auch so halving of the air cleaner can approach The coefficient from a different angle so
beschrieben werden (das Resultat ist genau das selbe): be described (the result is exactly the same):
• alle Koe zienten als Q1.14 abspeichern (entspricht den Halbieren) • all coe cients Q1.14 save as (corresponding to halving)
• Eingangssignal x[n] durch 4 dividieren temp = (long)x[n]<<14 (Q0.15 zu Q2.29 wandeln) • Input signal x [n] divided by 4 temp = (long) 14 (Q0.15 Q2.29 to convert) x n] <[<
• Zwischenresultat temp für die Berechnung von w[n] in Q2.29 = Resultat der Multiplikation • intermediate result temp for the calculation of w [n] in Q2.29 = result of the multiplication
von zwei Q1.14-Zahlen Q1.14 of two numbers
• Verzögerungskette w[n] mit 2 multiplizieren w[n] = temp>>15 (Q2.29 zu Q1.14 wandeln) • Delay chain w [n] with 2 multiply w [n] = temp>> 15 (Q2.29 Q1.14 to convert)
• Zwischenresultat temp für die Berechnung von y[n] in Q2.29 = Resultat der Multiplikation von • intermediate result temp for the calculation of y [n] = Q2.29 result of multiplication of
zwei Q1.14-Zahlen Q1.14 two figures
• Ausgangssignal y[n] mit 4 multiplizieren y[n] = temp>>14 (Q2.29 zu Q0.15 wandeln) • output signal y [n] with 4 multiply y [n] = temp>> 14 (Q2.29 Q0.15 to convert)
3.2 Skalierung einer Kaskade von Biquads: schrittweises Vorgehen 2.3 scaling of a cascade of biquads: step by step approach
Für jeden Biquad muss die Skalierung einzel durchgerechnet werden, damit nirgends ein untolerier- For each biquad must be calculated by scaling the individual, it is nowhere a untolerier-
barer Überlauf entsteht. adjustable overflow occurs.
Für Biquad-Kaskaden in Direktform II kann man dazu den Matlab-Befehl tf2sos verwenden (aber For biquad cascades in direct form II can be to use the Matlab command tf2sos (but
nicht für andere Realisierungsstrukturen). not for other implementation structures).
Das schrittweise Vorgehen wird Anhand des Matlab-Listings erläutert. The stepwise procedure is explained on the basis of Matlab listings.
Es folgen das Listing, die Ausgabe des Skript und anschliessend die Erklärungen. Following are the listing, the output of the script and then the statements.
Listing 3: Biquad-Kaskaden in Direktform II skalieren: iirsos.m Listing 3: Cascade biquad direct form II in scale: iirsos.m
1 % Biquad−Kaskade entwerfen 1% biquad cascade design
2 % und F ilterkoeffizienten für Festkomma−DSP berechnen 2% F ilterkoeffizienten fixed-point DSP charge for
3 % ( c ) Hanspeter Hochreutener , ZHW, 22.4.2007 3% (c) Hans Peter Hochreutener, ZHW, 22/04/2007
4 % 4%
12 12
5 % Abgespeichert werden : 5% is stored:
6 % 6%
7 % Die Filter −Koeffizienten der Biquads 7% The filter coefficients of the biquad
8 % a11 , a21 , b01 , b11 , b21 , a12 , a22 , b02 , b12 , b22 , . 8% a11, a21, b01, b11, b21, a12, a22, b02, b12, b22,. . . . .
9 % im Q1.14−Format in dieser Reihenfolge 9% in Q1.14 format in this order
10 % in der Datei coef . 10% in the file coef. h h
11 % 11%
12 % Die Skalierung des Eingangs− und des Ausgangssignals 12% The scale of the input and output signal
13 % gin , gout % Gin 13, gout
14 % als Anzahl Bit−S hifts ( positiv = links , negativ = rechts schieben ) 14% as the number of bit hift S (= left, negative = right slide positive)
15 % in der Datei gain . 15% gain in the file. h h
16 16
17 clc ; clear ; close all ; 17 clc, clear, close all;
18 format compact ; format short ; 18 compact format, short format;
19 19
20 Nbiq = 4; 20 Nbiq = 4;
% Anzahl Biquad−Kaskaden % Number biquad cascade
21 [ b , a ] = ellip (2∗Nbiq ,1 ,40 ,0.2) 21 [b, a] = ellip (2 * Nbiq, 1, 40, 0.2)
% Filter −Koeffizienten berechnen % Filter coefficients calculated
22 figure ( 1 ) ; freqz (b , a ) ; 22 figure (1); freqz (b, a);
% Frequenzgang anzeigen zur Kontrolle % Go to control frequency response
23 title ( ' Frequenzgang mit genauen Filter −Koeffizienten ' ) ; 23 title ('frequency response with precise filter coefficients');
24 24
25 % Auswählen der Filternorm : Tschebyscheff oder L2 25% selecting the standard filters: Chebyshev or L2
26 % und umwandeln in ins Biquad−Kaskaden ( second order sections ) 26% and convert into the cascade biquad (second-order sections)
27 %[ sos , g ] = tf2 sos (b , a , ' up ' , ' inf ' ) 27% [sos, g] = tf2 sos (b, a, 'up', 'inf')
% Tschebyscheff : Minimiert Overflow−Wahrs . % Chebyshev: Minimize overflow Likely.
28 [ sos , g ] = tf2sos (b , a , 'down ' , 'two ' ) % L2 : Minimiert Signal−to−Noise−Ratio SNR 28 [sos, g] = tf2sos (b, a, 'down', 'two')% L2: Minimizes signal-to-noise ratio SNR
29 29
30 % Skalierung des Eingangssignals vor der Kaskade 30% scaling of the input signal before the cascade
31 gin = 0; 31 gin = 0;
% I nitialisieren : Gain am Eingang = 2^0 = 1 % I nitialisieren: Gain the input = 2 ^ 0 = 1
32 while (g < 1) 32 while (g <1)
% Eingangssignal skalieren % Input scale
33 33
g = g ∗2; g = g * 2;
% mit einer 2er−Potenz % With a power of 2
34 34
gin = gin −1; gin gin = -1;
% Eingangssignal um Faktor 2 abschwächen % Input signal factor of 2 to weaken
35 end 35 end
36 36
37 % Skalierung der b−Filter −koeffizienten der Biquads 37% scaling of the b-filter coefficients of biquads
38 for i = 1: Nbiq 38 for i = 1: Nbiq
% Alle Biquads skalieren % All biquads scale
39 39
sos ( i , 1 : 3 ) = sos ( i , 1 : 3 ) ∗ g ; sos (i, 1: 3) = sos (i, 1: 3) * g;
% b−Koeffizienten des Biquads anpassen % B-coefficients biquads adjust the
40 40
g = max(abs( sos ( i , 1 : 3 ) ) ) ; g = max (abs (sos (i, 1: 3)));
% grössten b−Koeffizienten bestimmen % Largest b-coefficients determine
41 41
if (g > 1.9) if (g> 1.9)
% fallsb−Koeff . % Fallsb Coeff. ausserhalb Q1.14−Format outside Q1.14 format
42 42
g = g /1.9; g = g / 1.9;
% diese Verstärkung g kompensiert %, This gain offset g
43 43
sos ( i , 1 : 3 ) = sos ( i , 1 : 3 ) / g ; sos (i, 1: 3) = sos (i, 1: 3) / g;
% in diesem Biquad (b−Koeff . anpassen ) und % This biquad (b-. Coeff adapt) and
44 44
% im folg . % In success. Biquad ( nächster for−Durchgang ) Biquad (nearest for-pass)
45 45
else else
% sonst % Otherwise
46 46
g = 1; g = 1;
% keine Anpassung der Verstärkung nötig %, No adjustment of the gain necessary
47 47
end end
48 end 48 end
49 49
50 % Skalierung des Ausgangssignals nach der Kaskade 50% scaling of the output signal to the cascade
51 gout = 0; 51 gout = 0;
% I nitialisieren : Gain am Ausgang = 2^0 = 1 % I nitialisieren: gain at output = 2 ^ 0 = 1
52 while (g > 1) 52 while (g> 1)
% Ausgangssignal skalieren % Output scaling
53 53
g = g /2; g = g / 2;
% mit einer 2er−Potenz % With a power of 2
54 54
gout = gout+1; gout = gout +1;
% Ausgangssignal um Faktor 2 verstärken % Output increase by a factor of 2
55 end 55 end
56 56
57 sos (Nbiq , 1 : 3 ) = sos (Nbiq , 1 : 3 ) ∗ g ; Sos 57 (Nbiq, 1: 3) = sos (Nbiq, 1: 3) * g;
% b−Koeff . % B-coeff. des letzten Biquads anpassen the last biquads Customize
58 58
59 gin , gout , sos 59 gin, gout, sos
% Zum Vergleich ausgeben % Compared to spend
60 60
13 13
61 sos_dsp = round( sos ∗2^14) 61 sos_dsp = round (sos * 2 ^ 14)
% Koeffizienten umrechnen ins Q1.14−Format % Coefficients converted into Q1.14 format
62 62
63 [ b_dsp , a_dsp ] = sos2tf ( sos_dsp /2^14 , 2^( gin+gout )) 63 [b_dsp, a_dsp] = sos2tf (sos_dsp / 2 ^ 14, 2 ^ (+ gin gout))
% Zurückrechnen auf die ÜTF % Convert back to the ÜTF
64 figure ( 2 ) ; freqz (b_dsp , a_dsp ) ; 64 figure (2); freqz (b_dsp a_dsp);
% Frequenzgang anzeigen zur Kontrolle % Go to control frequency response
65 title ( ' Frequenzgang mit skalierten Filter −Koeffizienten ' ) ; 65 title ('frequency response with a scaled filter coefficients');
66 66
67 dlmwrite( ' gain . h ' , [ gin , gout ] ) ; 67 dlmwrite ('gain h.', [Gin, gout]);
% Skalierung Ein− und Ausgang speichern % Scale the input and output store
68 % sos_dsp = [ sos_dsp (: ,5:6) , sos_dsp ( : , 1 : 3 ) ] ; % Umsortieren der Koeffizienten 68% sos_dsp = [sos_dsp (:, 5:6), sos_dsp (:, 1: 3)];% reorder the coefficients
69 % dlmwrite ( ' coef . h ' , sos_dsp ) ; 69% dlmwrite ('h coef.', Sos_dsp);
% Koeffizienten in Header−Datei speichern % Coefficients in header file store
70 % dlmwrite : Zeilenumbrüche statt , am Zeilenende => geht nicht für C−Import 70% dlmwrite: instead of line breaks, => is not the end of the line for C-Import
71 fid = fopen( ' coef . h ' , 'w' ) ; 71 fid = fopen ('h coef.', 'W');
% Also von "Hand" ausgeben }−( So% of "source" output} - (
72 for i = 1: Nbiq−1 72 for i = 1: Nbiq-1
73 73
fprintf ( fid , '%i , %i , %i , %i , %i , ' , . . . fprintf (fid, '% i,% i,% i,% i,% i,'...
74 74
sos_dsp ( i ,5) , sos_dsp ( i ,6) , sos_dsp ( i ,1) , sos_dsp ( i ,2) , sos_dsp ( i , 3 ) ) ; sos_dsp (i, 5), sos_dsp (i, 6), sos_dsp (i, 1), sos_dsp (i, 2), sos_dsp (i, 3));
75 end; 75 end;
76 i = Nbiq ; 76 i = Nbiq;
% Am Schluss Newline statt Komma % At the end point instead of newline
77 fprintf ( fid , '%i , %i , %i , %i , %i \n ' , . . . 77 fprintf (fid, '% i,% i,% i,% i,% i \ n',...
78 78
sos_dsp ( i ,5) , sos_dsp ( i ,6) , sos_dsp ( i ,1) , sos_dsp ( i ,2) , sos_dsp ( i , 3 ) ) ; sos_dsp (i, 5), sos_dsp (i, 6), sos_dsp (i, 1), sos_dsp (i, 2), sos_dsp (i, 3));
79 fclose ( fid ) ; 79 fclose (fid);
Nach dem Listing mit der Ausgabe des Skripts folgt dessen Beschreibung. After listing with the output of the script follows the description.
Listing 4: Ausgabe des Matlab-Skripts 3 Listing 4: Output of Matlab scripts 3
1 % Resultate des Skripts iirsos .m 1% results of the script iirsos. M
2 2
3 % Für folgende Befehlszeilen /Parameter : 3% for the following command line / parameters:
4 4
5 Nbiq = 4; 5 Nbiq = 4;
% Anzahl Biquad−Kaskaden % Number biquad cascade
6 [ b , a ] = ellip (2∗Nbiq ,1 ,40 ,0.2) 6 [b, a] = ellip (2 * Nbiq, 1, 40, 0.2)
% Filter −Koeffizienten berechnen % Filter coefficients calculated
7 [ sos , g ] = tf2sos (b , a , 'down ' , 'two ' ) % L2 : Minimiert Signal−to−Noise−Ratio SNR 7 [sos, g] = tf2sos (b, a, 'down', 'two')% L2: Minimizes signal-to-noise ratio SNR
8 8
9 % erscheint diese Ausgabe : 9% seems this issue:
10 10
11 b = 11 b =
12 12
0.0154 −0.0733 0.0154 -0.0733
0.1811 0.1811
−0.2917 -0.2917
0.3397 0.3397
−0.2917 -0.2917
0.1811 −0.0733 0.1811 -0.0733
0.0154 0.0154
13 a = 13 a =
14 14
1.0000 −6.4154 18.9395 −33.3652 38.2328 −29.1270 14.3989 −4.2251 1.0000 -6.4154 18.9395 -33.3652 38.2328 -29.1270 14.3989 -4.2251
0.5646 0.5646
15 sos = 15 sos =
16 16
1.1828 1.1828
−1.8934 -1.8934
1.1828 1.1828
1.0000 1.0000
−1.6129 -1.6129
0.9937 0.9937
17 17
1.3677 1.3677
−2.1528 -2.1528
1.3677 1.3677
1.0000 1.0000
−1.6091 -1.6091
0.9656 0.9656
18 18
0.5825 0.5825
−0.8319 -0.8319
0.5825 0.5825
1.0000 1.0000
−1.6027 -1.6027
0.8695 0.8695
19 19
0.2476 0.2476
−0.0372 -0.0372
0.2476 0.2476
1.0000 1.0000
−1.5907 -1.5907
0.6767 0.6767
20 g = 20 g =
21 21
0.0661 0.0661
22 gin = = 22 gin
23 23
−4 -4
24 gout = Gout = 24
25 25
0 0
26 sos = 26 sos =
27 27
1.1869 1.1869
−1.9000 -1.9000
1.1869 1.1869
1.0000 1.0000
−1.6129 -1.6129
0.9937 0.9937
28 28
1.2071 1.2071
−1.9000 -1.9000
1.2071 1.2071
1.0000 1.0000
−1.6091 -1.6091
0.9656 0.9656
29 29
0.6955 0.6955
−0.9932 -0.9932
0.6955 0.6955
1.0000 1.0000
−1.6027 -1.6027
0.8695 0.8695
30 30
0.2476 0.2476
−0.0372 -0.0372
0.2476 0.2476
1.0000 1.0000
−1.5907 -1.5907
0.6767 0.6767
31 sos_dsp = 31 sos_dsp =
32 32
19447 19447
−31130 -31130
19447 19447
16384 16384
−26427 -26427
16280 16280
33 33
19778 19778
−31130 -31130
19778 19778
16384 16384
−26363 -26363
15821 15821
14 14
34 34
11394 11394
−16272 -16272
11394 11394
16384 16384
−26258 -26258
14246 14246
35 35
4057 4057
−609 -609
4057 4057
16384 16384
−26063 -26063
11087 11087
36 b_dsp = 36 b_dsp =
37 37
0.0154 −0.0733 0.0154 -0.0733
0.1811 0.1811
−0.2917 -0.2917
0.3397 0.3397
−0.2917 -0.2917
0.1811 −0.0733 0.1811 -0.0733
0.0154 0.0154
38 a_dsp = 38 a_dsp =
39 39
1.0000 −6.4155 18.9397 −33.3655 38.2330 −29.1270 14.3988 −4.2250 1.0000 -6.4155 18.9397 -33.3655 38.2330 -29.1270 14.3988 -4.2250
0.5646 0.5646
Das schrittweise Vorgehen wird Anhand des Matlab-Listings 3 und der Ausgabe für ein konkretes The gradual approach is the basis of Matlab Listings 3 and the output for a specific
Beispiel erläutert. Example illustrates.
1. 1. Für die gewünschte Übertragungsfunktion H(z) werden die b- und a-Filterkoe zienten für die For the desired transfer function H (z), the b-and a-coefficients for the air cleaner
Di erenzengleichung 8 bestimmt. Tues erenzengleichung determined eighth
Im Beispiel wurde in der Zeile 20 des Matlab-Skripts festgelegt, dass 4 Biquads einge- In the example, the row 20 of the Matlab scripts set in that 4-be biquads
setzt werden und in Zeile 21 die Koe zienten für ein elliptisches Tiefpass-Filter mit shall be in line 21 and the coefficients of an elliptic low pass filter with
1dB Rippel im Durchlass- und 40dB Dämpfung im Sperrbereich mit einer Grenzfre- 1 dB ripple in the passband and 40dB attenuation in the stop band with a cut-off
quenz von 0.2*fs/2 berechnet. 0.2 * fs / 2 frequency computed.
Die Filterkoe zienten sind in der Ausgabe in den Zeilen 11-14 aufgelistet. The air cleaner of the output coefficients are listed in the rows 11-14.
2. 2. Nun muss man sich für eine Filternorm entscheiden. Now has to choose one for a standard filter.
Und aus den b- und a-Koe zienten der Übertragungsfunktion werden die Koe zienten sos And from the b-and a-coe cients of the transfer function coe cients, the sos
(b01 b11 b21, 1, a11, a21; b02 b12 b22, 1, a12, a22; ...) der Biquads berechnet. (B01 b11 b21, 1, a11, a21, b22, 1, a12, a22, b12 ... b02) biquads calculated.
Mit dem Faktor g muss das Eingangssignal multipliziert werden, um einen Over ow im ersten the factor g, the input signal must be multiplied with to an over ow in the first
Biquad zu verhindern. biquad to prevent.
Im Skript kann man wählen zwischen Zeile 27 für die Tschebysche -Norm l In the script, you can choose between line 27 for the standard Tschebysche l
∞ ∞
oder or
Zeile 28 für die l Line 28 for the l
2 2
-Norm. Standard. Gewählt wurde die l Selected, the l
2 2
-Norm, welche das SNR optimiert. Standard, which the SNR is optimized.
Die berechneten sos und g nden sich in der Ausgabe in den Zeilen 15-21. The calculated sos and g be in the output in lines 15-21.
3. 3. g ist der Faktor, mit dem das Eingangssignal skaliert werden muss, um einen Überlauf im ersten g is the factor that scales the signal to the input must be an overflow in the first
Biquad zu vermeiden. biquad to avoid.
Für die Implementation ist es günstiger die Skalierung mit der nächstgelegenen 2er-Potenz zu For the implementation, it is better to scale using the nearest power of 2 to
machen, da statt der Multiplikation nur eine Schiebeoperation durchgeführt werden muss. To make this the best multiplication only a shift operation to be performed. Die The
veränderte Skalierung muss bei den b-Koe zienten des ersten Biquads berücksichtigt werden. scaling has changed in the b-coe cients of the first biquads be considered.
Im Skript wird der Faktor für die Eingangsskalierung in den Zeilen 31-35 bestimmt. In the script, 31-35, the scaling factor for the input on lines determined.
Aus den Zeilen 20-23 der Ausgabe sieht man, dass statt 0.0661 2 From lines 20-23 of the output we see that instead of 0.0661 2
−4 -4
= 0.0625 verwen- = 0.0625-use
det wird. is det.
Die abgeänderte Skalierung wird in der Zeile 39 des Skripts im ersten Biquad einbe-
rechnet.
4. 4. Der Betrag der a-Koe zienten ist für einen stabilen Biquad immer < 2.
Das tri t für die b-Koe zienten nicht unbedingt zu. Ist in einem Biquad ein b-Koe zient zu
gross, werden die b-Koe zienten entsprechend skaliert und die b-Koe zienten des nachfolgen-
den Biquads entsprechend angepasst.
In der Ausgabe auf Zeile 17 sieht man, dass der Koe zient b11 -2.1528 zu gross ist.
Das Skalieren der b-Koe zienten für alle Biquads geschieht in den Zeilen 38-48. In In
den Zeilen 41-42 wird der Betrag der Koe zienten auf 1.9 begrenzt; damit entstehen
beim Runden keine Probleme.
Die Zeilen 26-30 der Ausgabe zeigen, dass nun alle Koe zienten im erlaubten Zah-
lenbereich liegen.
5. 5. Das verbleibende g ist der Faktor mit dem das Ausgangssignal skaliert werden muss.
Wie bei der Eingangsskalierung wird wieder die nächstgelegene 2er-Potenz gesucht. Die verän-
derte Skalierung muss bei den b-Koe zienten des letzten Biquads berücksichtigt werden.
15 15
Im Skript wird der Faktor für die Ausgangsskalierung in den Zeilen 51-57 bestimmt.
Die Zeilen 22-30 der Ausgabe enthalten nun die skalierten Koe zienten.
6. 6. Für die Realisierung auf einen Festkomma-DSP müssen die Koe zienten ins Q1.14-Format
umgerechnet werden (Q1.14 entspricht Q0.15 mit halbierten Koe zienten).
In der Skriptzeile 61 werden die Koe zienten mit 2
14 14
multipliziert und gerundet.
Ausgabe der quantisierten Koe zienten in der Zeile 31-35.
7. 7. Man muss unbedingt kontrollieren, ob die quantisierten Koe zienten den richtigen Frequenz-
gang ergeben.
Im Skript werden die Frequenzgänge in den Zeilen 22-23 und 63-65 gezeichnet, was
eine schnelle visuelle Kontrolle erlaubt.
In der Ausgabe können die Zeilen 36-39 mit 11-14 verglichen werden.
8. 8. Zum Schluss werden die Koe zienten für den DSP umsortiert abgespeichert. Sie lassen sich so
in den C-Code des DSPs einbinden.
Siehe Skriptzeilen 67-79.
3.3 Beispiel: IIR-Implementation mit Compiler-Intrinsics auf dem TMS320C55x
Zuerst eine Implementaion in C mit oat-Variabeln.
Listing 5: Ausschnitt: DSP-C-Code mit oat-Variabeln
/∗ Implementation der IIR−Biquad−Kaskade in Direktform II ∗/
/∗ mit float −Arithmetik als Referenz−Implementaion ∗/
/∗ float muss auf einem Fixed−Point−DSP SW−mässig emuliert wird ∗/
/∗ und ist deshalb extrem ineffizient ∗/
DSK5510_LED_on( 1 ) ;
// Start Zeitmessung Floating−Point
q15tofl (&sample_in_r , &ftemp , 1);
//
Q15 => float
/∗ C−Code für die Vergleichs −Implementation mit float in C ∗/
ftemp = ftemp ∗ fgain [ 0 ] ;
//
Eingang skalieren mit gin
for ( biq = 0; biq < Nbiq ; biq++) {
//
Alle Biquads abarbeiten
biq3 = biq ∗3;
biq5 = biq ∗5;
//
Für Array−Indexierung
/∗ Werte um einen Takt verzögern ; wäre besser mit Ringbuffer ∗/
fw [ biq3 +2] = fw [ biq3 +1];
//
w(n−2) = w(n−1)
fw [ biq3 +1] = fw [ biq3 ] ;
//
w(n−1) = w(n)
/∗ w[ n ] = x [ n ] −a1∗w[n−1] −a2∗w[n−2] ∗/
// temp = temp − a1∗w[n−1]
ftemp = ftemp − fcoef [ biq5 ] ∗ fw [ biq3 +1];
// w[ 0 ] = temp − a2∗w[n−2]
fw [ biq3 ] = ftemp − fcoef [ biq5 +1] ∗ fw [ biq3 +2];
/∗ y [ n ] = 4∗( b0∗w[ n ] +b1∗w[n−1] + b2∗w[n−1]) ∗/
// temp = b0∗w[ n ]
ftemp = fcoef [ biq5 +2] ∗ fw [ biq3 ] ;
// temp = temp + b1∗w[n−1]
ftemp = ftemp + fcoef [ biq5 +3] ∗ fw [ biq3 +1];
// temp = temp + b2∗w[n−2]
ftemp = ftemp + fcoef [ biq5 +4] ∗ fw [ biq3 +2];
/∗ temp = Ausgang dieses Biquads = Eingang des nächsten Biquads ∗/
} }
ftemp = ftemp ∗ fgain [ 1 ] ;
//
Ausgang skalieren mit gout
fltoq15 (&ftemp , &sample_out_r , 1);
//
float => Q15
DSK5510_LED_off ( 1 ) ;
// Stop Zeitmessung Floating−Point
16 16
Die oat-Implementation ist mit 13 Zeilen Code sehr übersichtlich und kompakt. Aber auf einem
Fixed-Point-DSP muss die oat-Arithmetik software-mässig emuliert werden und das Filter ist etwa
100 mal langsamer als handoptimierter Assembler-Code! C-Code ist also nur geeignet als erster
Approach oder wenn man Rechenpower zum Versauen hat.
Es folgt der Ausschnitt aus dem DSP-Code implementiert mit Compiler-Intrinsics. Das vollständige
C-File be ndet sich im Anhang.
Listing 6: Ausschnitt: DSP-C-Code für das IIR-Biquad-Filter in Direktform II
/∗ Implementation der IIR−Biquad−Kaskade in Direktform II ∗/
/∗ mit sättigender Arithmetik und Compiler−I ntrinsics ∗/
DSK5510_LED_on( 0 ) ;
// Start Zeitmessung Fixed−Point
/∗ Formale Beschreibung
Q−Format−Sichtweise ∗/
// Eingang mit " gin " skalieren
x = Q0.15
// temp = 2^gin ∗ x [ n]/4
skalieren + Q0.15 zu Q2.29
temp = ( long ) sample_in_l<<(gain [0]+14); //
Q2.29
for ( biq = 0; biq < Nbiq ; biq++) {
//
Alle Biquads abarbeiten
biq3 = biq ∗3;
biq5 = biq ∗5;
//
Für Array−Indexierung
/∗ Werte um einen Takt verzögern ; wäre besser mit Ringbuffer ∗/
w[ biq3 +2] = w[ biq3 +1];
//
w(n−2) = w(n−1)
w[ biq3 +1] = w[ biq3 ] ;
//
w(n−1) = w(n)
/∗ w[ n ] = 2∗( x [ n]/4 −a1∗w[n−1] −a2∗w[n−2]) ∗/
// temp = temp − a1∗w[n−1]
Q2.29 = Q2.29 − Q1.14∗Q1.14
temp = _smas(temp , coef [ biq5 ] , w[ biq3 +1]);
// temp = temp − a2∗w[n−2]
Q2.29 = Q2.29 − Q1.14∗Q1.14
temp = _smas(temp , coef [ biq5 +1] , w[ biq3 +2]);
// temp = temp∗2
Q2.29 zu Q1.30 wandeln
temp = _lsshl (temp , 1 ) ;
// w[ 0 ] = temp
Q1.30 zu Q1.14 wandeln
w[ biq3 ] = temp >>16;
/∗ y [ n ] = 4∗( b0∗w[ n ] +b1∗w[n−1] + b2∗w[n−2]) ∗/
// temp = b0∗w[ n ]
Q2.29 = Q1.14∗Q1.14
temp = _lsmpy( coef [ biq5 +2] , w[ biq3 ] ) ;
// temp = temp + b1∗w[n−1]
Q2.29 = Q2.29 + Q1.14∗Q1.14
temp = _smac(temp , coef [ biq5 +3] , w[ biq3 +1]);
// temp = temp + b2∗w[n−2]
Q2.29 = Q2.29 + Q1.14∗Q1.14
temp = _smac(temp , coef [ biq5 +4] , w[ biq3 +2]);
/∗ temp = Ausgang dieses Biquads = Eingang des nächsten Biquads ∗/
} }
// Ausgang mit "gout" skalieren
// temp = 2^gout ∗ temp∗4
skalieren + Q2.29 zu Q0.31
temp = _lsshl (temp , gain [1]+2);
// y [ n ] = temp
Q0.31 zu Q0.15 wandeln
sample_out_l = temp >>16;
DSK5510_LED_off ( 0 ) ;
// Stop Zeitmessung Fixed−Point
Die Implementation mit Compiler-Intrinsics hat etwa gleich viele Code-Zeilen wie die oat-Imple-
mentation, läuft aber 17 mal schneller! Man muss allerdings sehr genau auf die Skalierung der Signale
und Filter-Koe zienten und die verwendeten fractional -Daten-Formate achten.
Der vollständige C-Code mit Compiler-Intrinsics be ndet sich im Anhang.
Nach der Implementation muss man sich vergewissern, dass das DSP-Filter den Anforderungen ent-
spricht. speaks. Das wurde mit einem Multiträger-Signal (bestehend aus 31 logarithmisch verteilten Sinussi-
gnale) veri ziert. Ein Vergleich der nachfolgenden Bilder bestätigt die Korrektheit der Implementa-
tion. tion.
17 17
10 10
-3 -3
10 10
-2 -2
10 10
-1 -1
10 10
0 0
-60
-50
-40
-30
-20
-10 -10
0 0
10 10
Normalized Frequency (×π rad/sample)
Magnitude (dB)
Magnitude Response (dB)
(a) Matlab-Entwurf
10 10
1 1
10 10
2 2
10 10
3 3
10 10
4 4
-60
-50
-40
-30
-20
-10 -10
0 0
10 10
Frequenz-Spektrum
Frequenz in Hz
Amplitudengang dB
(b) Messung am DSP-Board
Abbildung 3: Entworfener und gemessener Frequenzgang des IIR-Filters
3.3.1 Performance-Messung und mögliche Verbesserungen
Die Zahlenangaben beziehen Sich auf die im Beispiel realisierte Kaskade mit 4 Biquads und sample-
weiser Berechnung.
Die Implementierung mit Compiler-Intrinsics und ohne Ringbu er benötigt ca. 540 Zyklen (2.7µs).
Zum Vergleich:
Die optimierte DSP-Library Assembler-Funktion iircas5.asm benötigt 85 Zyklen (0.4µs). Achtung: Note:
Diese iircas -Funktionen der DSP-Library können mit Koe zienten |a
1 1
| > 1 nicht umgehen, da
alle Koe zienten im Q15-Format erwartet werden. Es gibt eine ino zielle Funktion iircas52.asm
welche das Problem mit Q1.14-Koe zienten löst.
Zum Vergleich:
Die C-Implementation mit oat-Variablen benötigt ca. 8500 Zyklen (42µs), da die oat-Arithmetik
auf einem Festkomma-DSP SW-mässig emuliert werden muss. Mit dieser Implementation ist eine
Samplingrate von 48kHz also bei Weitem nicht erreichbar.
Verbesserungsmöglichkeiten gegenüber der Variante Compiler-Intrinsics ohne Ringbu er :
• Compiler-Optimierung maximieren im Menu Project -> Build Options... -> Compiler -> Basic
-> Opt.Level -> File (-o3) spart 1/3 ein.
Der gleiche Source-Code läuft nun in 360 Zyklen (1.8µs).
• Ringbu er für den Verzögerungsbu er. (Einsparung unbekannt, da nicht getestet.)
• Ringbu er-Länge auf die nächste Zweier-Potenz aufrunden. Die Modulo-Operation für den
Pointer kann dann durch eine sehr viel e zienteres Bitweises-And ersetzt werden. Es folgt eine
massive Einsparung an Rechenzeit, dafür wird etwas mehr Speicherplatz benötigt.
• Anstelle der for-Schleife den Code pro Biquad einmal kopieren und die Array-Indices voraus-
berechnen. calculated. Der Compiler setzt die feste Adresse in den Code ein; deshalb bringt ein Ringbu er
hier keinen Vorteil. Es werden ca. 200 Zyklen (1.0µs) benötigt.
• Daten und Filter-Koe zienten in verschiedenen Speicherbereichen ablegen, damit der DSP
diese parallel statt sequenziell einlesen kann.
• Bei symmetrischen und assymmetrischen FIR-Filtern wird jede Multiplikation zweimal aus-
geführt. Wenn an Stelle der Direktform I die Linear-Phasen-Struktur verwendet wird, kann
18 18
die Rechenzeit unter Umständen halbiert werden (siehe Compiler-Intirnsic-Befehle _ rs und
_ rsn).
• Durch Inline-Assembler in der for-Schleife und ausnutzen der zweiten MAC-Einheit des DSPs
könnte die Rechenzeit (theoretisch) auf ca. 40 Zyklen (0.2µs) gesenkt werden!
19 19
A DSP-C-Code für das IIR-Biquad-Filter in Direktform II
Listing 7: DSP-C-Code für das IIR-Biquad-Filter in Direktform II
1 /∗
2 2
∗
Digitale Signal−Verarbeitung
3 3
∗
Beispiel −Implementation einer IIR−Biquad−Kaskade
4 4
∗
mit Compiler−I ntrinsics und sättigender Arithmetik
5 5
∗
Hanspeter Hochreutener , ZHW, April 2007
6 6
∗/
7 7
8 /∗
9 9
∗
Gleichungen für transponierte Direktstruktur 2:
10 10
∗
w[ n ] = x [ n ] −a1∗w[n−1] −a2∗w[n−2];
11 11
∗
y [ n ] = b0∗w[ n ] +b1∗w[n−1] + b2∗w[n−1];
12 12
∗
Da abs [ a1 ] < 2 , ist a1 oft ausserhalb des Q0.15− Zahlenbereichs .
13 13
∗
Alle Filter −Koeffizienten müssen deshalb halbiert (= Q1.14) vorliegen :
14 14
∗
A1 = a1/2 , A2 = a2/2 , B0 = b0 /2 , B1 = b1 /2 , B2 = b2/2
15 15
∗
Das ergibt folgende Gleichungen :
16 16
∗
w[ n ] = 2∗( x [ n ] −A1∗w[n−1] −A2∗w[n−2]);
// Faktor 2 der Koeff . kompensieren
17 17
∗
y [ n ] = B0∗w[ n ] +B1∗w[n−1] + B2∗w[n−1];
18 18
∗
Nun entsteht ein Overflow−Problem bei 2∗x [ n ] .
19 19
∗
x [ n ] wird deshalb mit 1/4 skaliert und y [ n ] anschliessend r ü ckskaliert .
20 20
∗
Das ergibt für die Implementation schlussendlich diese Gleichungen :
21 21
∗
w[ n ] = 2∗( x [ n]/4 −a1∗w[n−1] −a2∗w[n−2]);
22 22
∗
y [ n ] = 4∗( b0∗w[ n ] +b1∗w[n−1] + b2∗w[n−1]);
23 23
∗/
24 24
25 /∗
26 26
∗
Die System−Konfiguration ist in der Datei tone . cdb gespeichert .
27 27
∗
Zum Editieren /Ansehen Projektansicht öffen mit Menupukt View −> Project
28 28
∗
Die Datei tone . cdb liegt im Projektordner "DSP/BIOS Config"
29 29
∗
Aus dieser Konfig.−Datei werden beim Compilieren versch . Dateien erzeugt .
30 30
∗/
31 #include " tonecfg . h"
32 32
33 /∗
34 34
∗
std . h und log . h werden benötigt für Logging
35 35
∗/
36 #include " std . h"
37 #include " log . h"
38 38
39 /∗
40 40
∗
Libraries für die Hardware des Evaluation−Boards
41 41
∗/
42 #include "dsk5510 . h"
// Library für das Evaluation−Board
43 #include "dsk5510_aic23 . h"
// Library zum Ansprechen des Codecs , AD/DA−Wandler
44 #include "dsk5510_led . h"
// Library zum Ansteuern der LEDs
45 #include "dsk5510_dip . h"
// Library zum Auslesen der DIP−Schalter
46 46
47 /∗
48 48
∗
Libraries für Berechnungen und Signal−Verarbeitung
49 49
∗/
50 #include "math . h"
// Mathematische Funktionen
51 #include "tms320 . h"
// Definit . für den Q15−Datentyp der DSP−Library
52 #include " dsplib . h"
// DSP−Library mit optimierten Filtern , etc .
53 #include "dsplib_c . h"
// DSP−Library mit Filtern für komplexe Signale
20 20
54 54
55 55
56 /∗
57 57
∗
Globale Variabeln
58 58
∗/
59 59
60 DSK5510_AIC23_Config config = {
// Codec Konfiguration
61 61
0x0017 , // 0 DSK5510_AIC23_LEFTINVOL
Left line input channel volume
62 62
0x0017 , // 1 DSK5510_AIC23_RIGHTINVOL Right line input channel volume
63 63
0x00d8 , // 2 DSK5510_AIC23_LEFTHPVOL
Left channel headphone volume
64 64
0x00d8 , // 3 DSK5510_AIC23_RIGHTHPVOL Right channel headphone volume
65 65
0x0011 , // 4 DSK5510_AIC23_ANAPATH
Analog audio path control
66 66
0x0000 , // 5 DSK5510_AIC23_DIGPATH
Digital audio path control
67 67
0x0000 , // 6 DSK5510_AIC23_POWERDOWN Power down control
68 68
0x0043 , // 7 DSK5510_AIC23_DIGIF
Digital audio interface format
69 69
0x0081 , // 8 DSK5510_AIC23_SAMPLERATE Sample rate control
70 70
0x0001
// 9 DSK5510_AIC23_DIGACT
Digital interface activation
71 };
72 DSK5510_AIC23_CodecHandle hCodec ;
// Codec−Adresse
73 73
74 Int16 dip [ 4 ] ;
// Zustand der DIP−Schalter
75 Int16 led [ 4 ] = {0 , 0 , 0 , 0};
// Zustand der LEDs
76 76
77 DATA sample_in_l , sample_in_r ;
// Eingelesene Samples vom AD−Wandler
78 DATA sample_out_l , sample_out_r ;
// Auszugebende Samples zum DA−Wandler
79 79
80 int nr ;
// Hilfsvariable , Schleifenzähler
81 DATA sample ;
// Hilfsvariable , Samples
82 82
83 /∗
84 84
∗
Variabeln für das IIR−F ilter
85 85
∗/
86 #define Nbiq 4
// Anzahl der Biquads in der Kaskade
87 87
88 // Filter −Koeffizienten aus Datei einlesen , Q1.14−Format
89 // Reihenfolge : a11 , a21 , b01 , b11 , b21 , a12 , a22 , b02 , b12 , b22 , . . . . .
90 DATA coef [5∗ Nbiq ] = {
91 91
#include " . . / matlab/ coef . h"
92 };
93 93
94 // Skalierungsfaktoren für Eingangs− und Ausgangssignal einlesen
95 // Anzahl Bit−S hifts ( positiv = links , negativ = rechts schieben )
96 DATA gain [ 2 ] = {
97 97
#include " . . / matlab/ gain . h"
98 };
99 99
100 DATA w[3∗ Nbiq ] ;
// Buffer für die Verzögerungskette w[ n ]
101 101
102 LDATA temp ;
// Hilfsvar . mit doppelter Anzahl Bits für Zwischenresultate
103
104 int biq ;
// Laufvariable , enthält die aktuelle Biquad−Nummer
105 int biq3 , biq5 ; // Hilfsvariabeln , damit Index
nicht immer neu berechnet wird
106 106
107 /∗
108 108
∗
Hauptprogramm
109
∗/
21 21
110 110
111 void main ()
112 {
113 113
// Lokale Variablen deklarieren und initialisiseren
114 114
115 115
DSK5510_init ( ) ;
// Board−Treiber initialisieren
116 116
DSK5510_LED_init ( ) ;
// LED−Treiber initialisieren
117 117
DSK5510_DIP_init ( ) ;
// Treiber für DIP−Schalter initialis .
118 118
119
hCodec = DSK5510_AIC23_openCodec(0 , &config ) ;
// Codec starten
120 120
while (DSK5510_AIC23_read16(hCodec , &sample ) ) ;
// AD−Wandler−Buffer leeren
121 121
122 122
for ( nr = 0; nr < 3∗Nbiq ; nr++) {
123 123
w[ nr ] = 0;
// Verzögerungskette löschen
124 124
} }
125 125
126
/∗
127 127
∗
Hauptschleife , wird mit der Samplingfrequenz abgearbeitet
128 128
∗
Es wird je ein Sample vom linken und rechten AD−Wandler−Kanal gelesen ,
129 129
∗
verarbeitet ,
130 130
∗
und zum linken und rechten DA−Wandler−Kanal ausgegeben
131 131
∗/
132 132
while (1) {
// Endlos−S chleife
133 133
134 134
// Daten vom AD−Wandler (Codec) einlesen
135 135
while ( ! DSK5510_AIC23_read16(hCodec , &sample_in_l ) ) ; // linker Kanal
136 136
while ( ! DSK5510_AIC23_read16(hCodec , &sample_in_r ) ) ; // rechter Kanal
137 137
138 138
// Beispiel für Logging
139 139
LOG_printf(&trace , " links : %d
rechts : %d" , sample_in_l , sample_in_r ) ;
140 140
141 141
142 142
/∗ Implementation der IIR−Biquad−Kaskade in Direktform II ∗/
143
/∗ mit sättigender Arithmetik und Compiler−I ntrinsics ∗/
144 144
DSK5510_LED_on( 0 ) ;
// Start Zeitmessung Fixed−Point
145
/∗ Formale Beschreibung
Q−Format−Sichtweise ∗/
146 146
// Eingang mit " gin " skalieren
x = Q0.15
147 147
// temp = 2^gin ∗ x [ n]/4
skalieren + Q0.15 zu Q2.29
148 148
temp = ( long ) sample_in_l<<(gain [0]+14); //
Q2.29
149 149
for ( biq = 0; biq < Nbiq ; biq++) {
//
Alle Biquads abarbeiten
150 150
biq3 = biq ∗3;
biq5 = biq ∗5;
//
Für Array−Indexierung
151 151
/∗ Werte um einen Takt verzögern ; wäre besser mit Ringbuffer ∗/
152 152
w[ biq3 +2] = w[ biq3 +1];
//
w(n−2) = w(n−1)
153 153
w[ biq3 +1] = w[ biq3 ] ;
//
w(n−1) = w(n)
154 154
/∗ w[ n ] = 2∗( x [ n]/4 −a1∗w[n−1] −a2∗w[n−2]) ∗/
155 155
// temp = temp − a1∗w[n−1]
Q2.29 = Q2.29 − Q1.14∗Q1.14
156 156
temp = _smas(temp , coef [ biq5 ] , w[ biq3 +1]);
157 157
// temp = temp − a2∗w[n−2]
Q2.29 = Q2.29 − Q1.14∗Q1.14
158
temp = _smas(temp , coef [ biq5 +1] , w[ biq3 +2]);
159
// temp = temp∗2
Q2.29 zu Q1.30 wandeln
160 160
temp = _lsshl (temp , 1 ) ;
161
// w[ 0 ] = temp
Q1.30 zu Q1.14 wandeln
162 162
w[ biq3 ] = temp >>16;
163
/∗ y [ n ] = 4∗( b0∗w[ n ] +b1∗w[n−1] + b2∗w[n−2]) ∗/
164 164
// temp = b0∗w[ n ]
Q2.29 = Q1.14∗Q1.14
165 165
temp = _lsmpy( coef [ biq5 +2] , w[ biq3 ] ) ;
22 22
166
// temp = temp + b1∗w[n−1]
Q2.29 = Q2.29 + Q1.14∗Q1.14
167 167
temp = _smac(temp , coef [ biq5 +3] , w[ biq3 +1]);
168 168
// temp = temp + b2∗w[n−2]
Q2.29 = Q2.29 + Q1.14∗Q1.14
169 169
temp = _smac(temp , coef [ biq5 +4] , w[ biq3 +2]);
170 170
/∗ temp = Ausgang dieses Biquads = Eingang des nächsten Biquads ∗/
171 171
} }
172 172
// Ausgang mit "gout" skalieren
173 173
// temp = 2^gout ∗ temp∗4
skalieren + Q2.29 zu Q0.31
174 174
temp = _lsshl (temp , gain [1]+2);
175
// y [ n ] = temp
Q0.31 zu Q0.15 wandeln
176 176
sample_out_l = temp >>16;
177 177
DSK5510_LED_off ( 0 ) ;
// Stop Zeitmessung Fixed−Point
178 178
179 179
180
sample_out_r = sample_out_l ;
181 181
182 182
if ( ! DSK5510_DIP_get(0)) {
// F ilter überbrücken mit Schalter 0
183 183
sample_out_l = sample_in_l ;
184 184
sample_out_r = sample_in_r ;
185 185
} }
186 186
187 187
// Daten zum Da−Wandler (Codec) ausgeben
188
while ( ! DSK5510_AIC23_write16(hCodec , sample_out_l ) ) ; // linker Kanal
189 189
while ( ! DSK5510_AIC23_write16(hCodec , sample_out_r ) ) ; // rechter Kanal
190 190
191 191
} }
// Endlos−S chleife : Ende
192 192
193 193
/∗ Close the codec ∗/
194 194
DSK5510_AIC23_closeCodec(hCodec ) ;
// Codec schliessen
195 195
// wird nie erreicht , wegen while (1)
196 }
197 197
198 198
199 /∗
200 200
∗
Funktionen
201 201
∗/
23 23
B Verzeichnisse
Tabellenverzeichnis
1 1
Vergleich von Fliesskomma- und Festkomma-DSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3
2 2
int-Zahlenformat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 5
3 3
Q15-fractional-Zahlenformat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 5
4 4
Festkomma-Zahlenformate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 6
5 5
Zahlenformate umwandeln/umrechnen/uminterpretieren . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 6
6 6
Vergleich Überlauf und sättigende Arithmetik . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6 6
7 7
Oft verwendete TMS320C55x-Compiler-Intrinsics . . . . . . . . . . . . . . . . . . . .
7 7
subsection
Abbildungsverzeichnis List of Figures
1 1
FIR-Filter in Direktform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9 9
2 2
IIR-Filter mit Biquad-Kaskaden in Direktform II . . . . . . . . . . . . . . . . . . . .
11 11
3 3
Entworfener und gemessener Frequenzgang des IIR-Filters . . . . . . . . . . . . . . .
18 18
Listings
1 1
FIR-Code-Ausschnitt für den TMS320C55x . . . . . . . . . . . . . . . . . . . . . . .
10 10
2 2
FIR-Code-Ausschnitt für den TMS320C55x mit Überlauf-Schutz . . . . . . . . . . .
10 10
3 3
Biquad-Kaskaden in Direktform II skalieren: iirsos.m . . . . . . . . . . . . . . . . . .
12 12
4 4
Ausgabe des Matlab-Skripts 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14 14
5 5
Ausschnitt: DSP-C-Code mit oat-Variabeln . . . . . . . . . . . . . . . . . . . . . . .
16 16
6 6
Ausschnitt: DSP-C-Code für das IIR-Biquad-Filter in Direktform II . . . . . . . . . .
17 17
7 7
DSP-C-Code für das IIR-Biquad-Filter in Direktform II . . . . . . . . . . . . . . . .
20 20
24 24