Signal Processing Correlation Convolução conv 8212 discreta convolução 1-D. Conv2 8212 discreta 2-D convolução. Convol2d 8212 discreta 2-D convolução, usando fft. Corr 8212 correlação covariância hank 8212 covariância à matriz hankel xcorr 8212 Calcula discreta auto ou correlação cruzada Filtros analpf 8212 criam filtros passa-baixa analógicos buttmag 8212 Transmissão de potência de uma cascata de filtro Butterworth 8212 realização em cascata do filtro dos coeficientes cheb1mag 8212 resposta do tipo Chebyshev 1 filtro cheb2mag 8212 resposta do tipo 2 Chebyshev filtro convol 8212 convolução ell1mag 8212 magnitude do filtro elíptico eqfir 8212 minimax aproximação do filtro FIR eqiir 8212 Design de seus filtros faurre 8212 computação de filtro por algoritmo Faurre simples ffilt 8212 coeficientes de FIR passa-baixa filtsinc 8212 Amostras do filtro de função sinc 8212 filtra uma seqüência de dados usando um filtro digital findfreq 8212 compatibilidade de parâmetros para projeto de filtro elíptico frmag 8212 magnitude de filtros FIR e IIR fsfirlin 8212 design de FIR, filtros de fase linear, grupo de técnica de amostragem de freqüência 8212 atraso de grupo para filtro digital Hilbert 8212 Análise de tempo discreto Computação de sinal de um sinal real usando a transformada Hilbert 8212 iir filtro digital iirgroup 8212 retrasão grupal Lp IIR filtragem otimização iirlp 8212 Lp IIR filtro otimização kalm 8212 Kalman atualização lev 8212 Yule-Walker equações (Levinson0039s algoritmo) levin 8212 Toeplitz sistema solver por Levinson algoritmo (Multidimensional) lindquist 8212 Lindquist0039s algoritmo remez 8212 Remez algoritmo de troca para a aproximação chebyshev ponderada de uma função contínua com uma soma de cosenos. Remezb 8212 Minimax aproximação da resposta de magnitude srfaur 8212 algoritmo de raiz quadrada srkf 8212 raiz quadrada filtro de Kalman sskf 8212 filtro de Kalman de estado estacionário syredi 8212 Design de filtros iir, sistema de interface de código syredi 8212 atualização de observação trans 8212 passagem baixa para outra transformada de filtro wfir 8212 filtros FIR de fase linear wfirgui 8212 Interface gráfica de usuário que pode ser usada para projetar interativamente wfir filtros wiener 8212 Wiener estimativa wigner 8212 0039time-frequency0039 wigner janela de espectro 8212 cálculo janela simétrica de vários tipos yulewalk 8212 design de filtro de mínimos quadrados zpbutt 8212 Butterworth analógico Filtro zpch1 8212 Filtro analógico Chebyshev zpch2 8212 Filtro analógico Chebyshev filtro zoom elíptico zpell 8212 Como fazer um filtro elíptico 8212 Como projetar um filtro elíptico (analógico e digital) Identificação frfit 8212 resposta de freqüência ajuste lattn 8212 solução recursiva de equações normais lattp 8212 Identificação da parte MA de um processo ARMA vetorial Mrfit 8212 resposta de freqüência ajuste phc 8212 Representação Markoviana rpem 8212 Predição Recursiva - Erro estimativa de minimização Diversos bilt 8212 transformação bilineira ou biquadrática SISO sistema dado por uma representação de zeropoles sinc. 8212 função sinc sinc. Ou Dirichlet kernel Espectral estimativa cepstrum 8212 cepstrum cálculo cspect 8212 frente e verso cruzada - estimativa espectral entre 2 sinais de tempo discretos usando o método de correlação czt 8212 algoritmo de transformação z de chirp intdec 8212 Altera a taxa de amostragem de um sinal mese 8212 estimativa espectral de entropia máxima pspect 8212 estimativa cruzada entre dois sinais discretos usando a média de Welch0039s Método periodograma. Transforma a transformação discreta de cosseno discreta idct 8212. Idst 8212 Transformação de seno discreta inversa. Ifft 8212 Transformação de Fourier rápida inversa. Fft2 8212 transformação de Fourier rápida de duas dimensões 8212 reorganiza a saída de fft, movendo a freqüência zero para o centro do espectro hilb 8212 Aproximação de FIR para um filtro de transformação de Hilbert ifftshift 8212 inverso de detrend de fftshift 8212 remova tendência linear constante, linear ou por partes de Um vetor xcov 8212 Calcula covariância automática ou cruzada discreta Scilab Enterprises Copyright (c) 2011-2015 (Empresas Scilab) Copyright (c) 1989-2012 (INRIA) Copyright (c) 1989-2007 (ENPC) com contribuidores Última atualização: Wed Jun 15 08:27:37 CEST 2016 Artigos de processamento de sinal digital Referência DSP Terminologia de filtro digital De: RG Lyons, COMPRENDENDO O PROCESSAMENTO DE SINAL DIGITAL. (Apêndice F - páginas 494-505). Cópia 1997 de Addison Wesley Longman Inc. Reproduzida com permissão de Addison Wesley Longman. Todos os direitos reservados. O primeiro passo para se familiarizar com os filtros digitais é aprender a falar o idioma usado no negócio de filtros. Felizmente, o vocabulário dos filtros digitais corresponde bastante bem com a língua materna usada para filtros contínuos (analógicos). Também não precisamos desaprobar nada que já conheçamos. Este material é uma introdução à terminologia de filtros digitais. Allpass filter - um filtro IIR cuja resposta de magnitude é unidade em toda a sua faixa de freqüência, mas cuja resposta de fase é variável. Os filtros Allpass normalmente são anexados em uma disposição em cascata seguindo um filtro IIR padrão, H1 (z), como mostrado na Figura F-1. Figura F-1 Uso típico de um filtro allpass. Um filtro allpass, Hap (z), pode ser projetado de tal forma que sua resposta de fase compensa ou iguala. A resposta de fase não linear de um filtro IIR original. 1-3 Assim, a resposta de fase do filtro combinado, Hcombined (z), é mais linear que o original H1 (z), e isso é particularmente desejável nos sistemas de comunicação. Neste contexto, um filtro allpass às vezes é chamado de equalizador de fase. Atenuação - uma perda de amplitude, normalmente medida em dB, incorrida por um sinal depois de passar por um filtro digital. A atenuação do filtro é a relação, a uma dada freqüência, da amplitude do sinal na saída do filtro sobre a amplitude do sinal na entrada do filtro, definida como, como é geralmente o caso, para uma dada freqüência, a amplitude de saída da O filtro é menor do que a amplitude de entrada, tornando a razão na Eq. (F-1) menos de um e a atenuação é um número negativo. Filtro de rejeição de banda - um filtro que rejeita (atenua) uma banda de frequência e passa uma faixa de freqüência mais baixa e maior. A Figura F-2 (a) representa a resposta de freqüência de um filtro de rejeição de banda ideal. Esse tipo de filtro às vezes é chamado de filtro de entalhe. Figura F-2 Símbolos de filtro e respostas de freqüência: (a) Filtro de rejeição de banda (b) Filtro de passagem de banda. Filtro de passagem de banda - Um filtro, como mostrado na Figura F-2 (b), que passa uma faixa de freqüência e atenua as freqüências acima e abaixo dessa faixa. Largura de banda - poucos termos no processamento de sinal têm mais definições do que esta. Bem, defina a largura de banda como a largura da frequência da banda passante de um filtro. Para um filtro passa-baixa, a largura de banda é igual à freqüência de corte. Para um filtro de passagem de banda, a largura de banda é normalmente definida como a diferença de freqüência entre os pontos superior e inferior de -3 dB. Função Bessel - uma função matemática usada para produzir a resposta de fase mais linear de todos os filtros IIR sem consideração da resposta da magnitude da freqüência. Especificamente, os projetos de filtros com base nas funções do Bessel têm atraso de grupo maximamente constante. (Modelagem de funções do Bessel com software de computador, não recomendado para o coração fraco, geralmente resulta em uma lição significativa de humildade.) Função de Butterworth - uma função matemática usada para produzir respostas de magnitude de filtro maximamente planas sem consideração de linearidade de fase ou variações de atraso de grupo . Os desenhos de filtros baseados em uma função Butterworth não possuem ondulação de amplitude na banda passante ou na banda de parada. Infelizmente, para uma determinada ordem de filtro, os projetos da Butterworth possuem a maior região de transição das funções de design de filtros mais populares. Filtros em cascata - a implementação de um sistema de filtragem onde vários filtros individuais estão conectados em série. Ou seja, a saída de um filtro conduz a entrada do seguinte filtro como ilustrado na Figura F-1. Freqüência do centro (fo) - a freqüência no ponto médio de um filtro de passagem de banda. A figura F-2 (b) mostra a fo freqüência central de um filtro de passagem de banda. Função Chebyshev - uma função matemática usada para produzir banda passiva, ou stopband, ondulações restritas dentro de limites fixos. Existem famílias de funções Chebyshev com base na quantidade de ondulação, como 1 dB, 2 dB e 3 dB de ondulação. Os filtros Chebyshev podem ser projetados para ter uma resposta de freqüência com ondulações na passband e passbands planas (Chebyshev Type I), ou passbands planos e ondulações na banda de parada (Chebyshev Type II). Os filtros Chebyshev não podem ter ondulações tanto na banda passante como na faixa de parada. Os filtros digitais baseados nas funções de Chebyshev têm uma roda de região de transição mais acentuada, mas mais características de resposta de fase não-linear do que, digamos, filtros Butterworth. Coeficientes - Veja Coeficientes de filtro. Freqüência de corte - a freqüência de banda passiva superior para filtros passa-baixa e a freqüência de banda passiva inferior para filtros de passagem alta. Uma freqüência de corte é determinada pelo ponto -3 dB de uma resposta de magnitude do filtro em relação a um valor máximo de banda passante. A Figura F-3 ilustra a freqüência de corte fc de um filtro passa-baixa. Figura F-3 Uma resposta de freqüência de filtro digital de passagem baixa. A amplitude relativa da barreira é de -20 dB. Decibels (dB) - uma unidade logarítmica de atenuação, ou ganho, usada para expressar a tensão ou energia relativa entre dois sinais. Para os filtros, utilizamos decibéis para indicar os níveis de sinal de frequência (-3 dB) e stopband (-20 dB) como ilustrado na Figura F-3. Filtro de decimento - um filtro FIR digital de baixa passagem cuja taxa de amostra de saída é menor que a taxa de amostragem de entrada de filtros. Para evitar problemas de alias, a taxa de amostra de saída não deve violar os critérios de Nyquist. Filtro digital - processo computacional ou algoritmo, transformando uma sequência discreta de números (a entrada) em outra seqüência discreta de números (a saída) com um espectro de domínio de freqüência modificado. A filtragem digital pode ser na forma de uma rotina de software que opera em dados armazenados na memória do computador ou pode ser implementada com hardware digital dedicado. Função Elíptica - uma função matemática usada para produzir o deslocamento mais acentuado para um determinado número de torneiras de filtro. No entanto, filtros projetados usando funções elípticas, também chamados de filtros Cauer. Têm a linearidade de fase mais pobre das funções de projeto de filtro IIR mais comuns. A ondulação na banda passante e na faixa de parada são iguais aos filtros elípticos. Atraso do envelope - Veja o atraso do grupo. Coeficientes de filtro - o conjunto de constantes, também chamado de pesos de toque. Usado para se multiplicar em valores de amostra de sinal retardado dentro de uma estrutura de filtro digital. O design do filtro digital é um exercício na determinação dos coeficientes de filtro que renderão a resposta de freqüência de filtro desejada. Para um filtro FIR, os coeficientes do filtro são, por definição, a resposta ao impulso do filtro. Ordem de Filtro - um número que descreve o maior exponente no numerador ou denominador da função de transferência de domínio z de um filtro digital. Para os filtros FIR, não há denominador na função de transferência e a ordem do filtro é meramente o número de toques usados na estrutura do filtro. Para os filtros IIR, a ordem do filtro é igual ao número de elementos de atraso na estrutura do filtro. Geralmente, quanto maior a ordem do filtro, melhor será o desempenho da resposta da magnitude da frequência do filtro. Filtro de Resposta de Impulso Finito (FIR) - define uma classe de filtros digitais que possui apenas zeros no plano z. As principais implicações disso são que os filtros FIR são sempre estáveis e possuem respostas de fase linear (desde que os coeficientes dos filtros sejam simétricos). Para uma determinada ordem de filtro, os filtros FIR têm um roll-off de região de transição muito mais gradual do que os filtros IIR digitais. Frequency Magnitude Response - uma descrição do domínio da frequência de como um filtro interage com os sinais de entrada. A resposta de magnitude da frequência na Figura F-3 é uma curva de atenuação do filtro (em dB) versus frequência. Associado a uma resposta de magnitude dos filtros é uma resposta de fase. Atraso de grupo - definido como a derivada de uma fase de filtros em relação à freqüência, G-D oslash D f, ou a inclinação de uma curva de resposta de fase Hoslash (m). O conceito de atraso em grupo merece uma explicação adicional além de uma definição simples. Para um filtro ideal, a fase será linear e o atraso do grupo seria constante. O atraso de grupo, cuja unidade de medida é o tempo em segundos, também pode ser pensado como o atraso do tempo de propagação do envelope de um sinal modulado de amplitude à medida que passa através de um filtro digital. (Neste contexto, o atraso do grupo geralmente é chamado de atraso do envelope.) A distorção de atraso de grupo ocorre quando sinais em diferentes freqüências levam diferentes quantidades de tempo para passar por um filtro. Se o atraso do grupo for denotado G, então a relação entre o atraso do grupo, um incremento de fase de D oslash e um incremento de frequência de Df é Raised-Cosine e Fórmulas de Coseno-Raised-Cosine Perguntas frequentes sobre o Processamento do Sinal Digital FIR Filter FAQ FIR Filter Basics FIR Propriedades do Filtro FIR Filter Design FIR Filtração Implementação IIR Filtro Perguntas frequentes IIR Princípios básicos do filtro Multirate FAQ Multirate Basics Interação de decimentos 3.4.3 O que posso generalizar a partir desse exemplo A tabela sugere as seguintes observações gerais sobre as interpoladoras FIR: Como a razão de interpolação é quatro (L4 ), Existem quatro quotsub-filtersquot (cujos conjuntos de coeficientes são marcados aqui com cores correspondentes). Estes sub-filtros são chamados oficialmente quotpolyphase filtersquot. Para cada entrada, calculamos as saídas L ao fazer os cálculos B básicos de L, cada um usando um conjunto diferente de coeficientes. O número de torneiras por filtro polifásico é 3 ou, expresso como uma fórmula: NpolyNtotal L. Os coeficientes de cada filtro polifásico podem ser determinados ignorando cada coeficiente Lth, começando nos coeficientes 0 a L-1, para calcular as saídas correspondentes 0 até L-1. Alternativamente, se você reorganizou seus coeficientes antecipadamente em ordem quotscrambledquot como esta: h0, h4, h8, h1, h5, h9, h2, h6, h10, h3, h7, h11, então você poderia apenas passar por eles em ordem. Nós insintimos aqui no fato de que N deveria ser um múltiplo de L. Isso não é absolutamente necessário, mas se N não é um múltiplo de L, a complicação adicional de usar um não múltiplo de L geralmente não vale a pena. Então, se o número mínimo de torneiras que sua especificação de filtro requer não é um múltiplo de L, sua melhor aposta geralmente é apenas aumentar N para o próximo múltiplo de L. Você pode fazer isso, adicionando alguns coeficientes de valor zero para O fim do filtro, ou re-projetando o filtro usando o maior valor de N. 3.4.4 Que poupança computacional ganho usando um interpolador FIR Uma vez que cada saída é calculada usando apenas coeficientes NL (ao invés de N coeficientes), você obtém uma quantidade computacional global de quotsavings (N - NL) por saída. Uma maneira simples de pensar a quantidade de computação necessária para implementar um interpolador FIR é que é igual à computação necessária para um filtro N-tap interoperante que opera na taxa de entrada. Com efeito, você deve calcular os filtros L usando as torneiras NL cada, de modo que N total torneiras calculadas por entrada. 3.4.5 Quanta economia de memória eu ganho usando um interpolador FIR Comparado com a implementação direta da interpolação, subindo o sinal, enchendo-o com zeros L-1. Depois, filtrando-o, você economiza memória por um fator de (L-1) L. Em outras palavras, você não precisa armazenar quotupsamplesquot de desconto zero L-1 por amostra de entrada real. 3.4.6 Como eu projeto um interpolador FIR Use seu método de design de FIR favorito. Os critérios de design são: 3.5 Implementação 3.5.1 Como implemento um interpolador FIR Uma FIR interpolante é realmente a mesma que uma FIR regular, exceto que, para cada entrada, você calcula L saídas por entrada usando filtros L polifásicos, cada um com NL Torneiras. Mais especificamente: Armazene uma amostra na linha de atraso. (O tamanho da linha de atraso é NL.) Para cada um dos conjuntos de coeficientes de polifa de L, calcule uma saída como a soma dos produtos dos valores da linha de atraso e dos coeficientes do filtro. Mude a linha de atraso em um para abrir espaço para a próxima entrada. Além disso, assim como com FIRs comuns, os buffers circulares podem ser usados para eliminar o requisito de mudar literalmente os dados na linha de atraso. 3.5.2 Onde posso obter o código fonte para implementar um interpolador FIR em C Iowegians O ScopeFIR vem com um conjunto livre de algoritmos de multirate, incluindo as funções de interpolação FIR em C. Basta baixar e instalar o arquivo de distribuição ScopeFIR. 3.5.3 Onde posso obter código de montagem para implementar um interpolador FIR Os principais fornecedores de DSP fornecem exemplos de interpoladores FIR em seus livros de dados e notas de aplicativos, então verifique seus sites. 3.5.4 Como faço para testar um interpolador FIR Você pode testar uma FIR interpoladora na maioria das formas em que você pode testar uma FIR comum: um caso especial de uma interpoladora é uma FIR comum. Quando dado um valor de 1 para L, um interpolador deve atuar exatamente como uma FIR comum. Você pode então fazer testes de impulso, passo e seno assim como você pode em uma FIR comum. Se você colocar um seno cuja freqüência se encontra dentro da banda passadeira dos interpoladores, a saída deve estar livre de distorção (uma vez que o filtro atinge o estado estacionário) e a freqüência da saída deve ser a mesma que a freqüência da entrada, em termos de Hz absoluto. Você pode usar um teste de resposta passo a passo. Dada uma entrada de passo com valor de unidade, cada grupo de saídas L deve ser o mesmo que as somas dos coeficientes dos filtros polifásicos individuais L, uma vez que o filtro atingiu o estado estacionário. Resampling 4.1 Noções básicas 4.1.1 O quotresamplingquot quotResampling significa combinar interpolação e decimação para alterar a taxa de amostragem por um fator racional. 4.1.2 Por que ressaltar A remutação geralmente é feita para interfacear dois sistemas que possuem diferentes taxas de amostragem. Se a proporção de duas taxas de sistemas for um número inteiro, decimação ou interpolação pode ser usada para alterar a taxa de amostragem (dependendo se a taxa está sendo diminuída ou aumentada) caso contrário, interpolação e decimação devem ser usadas em conjunto para alterar a taxa A Exemplos de exemplos práticos e bem conhecidos do fato de que o equipamento de áudio profissional usa uma taxa de amostragem de 48 kHz, mas o equipamento de áudio do consumidor usa uma taxa de 44,1 kHz. Portanto, para transferir música de uma gravação profissional para um CD, a taxa de amostragem deve ser alterada por um fator de: (44100 48000) (441 480) (147 160) Não há fatores comuns em 147 e 160, então devemos parar Factoring nesse ponto. Portanto, neste exemplo, interpolaremos por um fator de 147, então, dizemos por um fator de 160. 4.1.3 Qual é o fator quotresamplingquot O fator de interpolação é simplesmente a razão da taxa de saída para a taxa de entrada. Dado que o fator de interpolação é L e o fator de decimação é M, o fator de reimplexão é L M. No exemplo acima, o fator de reimampling é 147 160 0.91875 4.1.4 Existe uma restrição no fator de reamostragem que eu posso usar Sim. Como sempre, os critérios de Nyquist devem ser atendidos em relação à taxa de amostragem de saída resultante, ou o alias resultará. Em outras palavras, a taxa de saída não pode ser inferior ao dobro da freqüência mais alta (de interesse) do sinal de entrada. 4.1.5 Quando o reescrevimento, eu sempre preciso de um filtro sim. Uma vez que a reimampling inclui interpolação, você precisa de um filtro de interpolação. Caso contrário, as imagens criadas pela parte de preenchimento zero da interpolação permanecerão, e o sinal interpolado não será igual ao original. Da mesma forma, uma vez que o reescrevimento inclui a dizimação, você, aparentemente, precisa de um filtro de decimação. Ou você. Como o filtro de interpolação está em linha com o filtro de decimação, você poderia apenas combinar os dois filtros convolvendo seus coeficientes para um único filtro para usar para decimar. Melhor ainda, uma vez que ambos são filtros de passagem baixa, basta usar o filtro que tenha a menor freqüência de corte como filtro de interpolação. 4.1.6 Como eu projeto o filtro de reescalonamento Como sugerido acima: Determine a freqüência de corte do filtro de decimação (como explicado na Parte 2: Decimação). Determine a freqüência de corte do filtro de interpolação (como explicado na Parte 3: Interpolação) Use a menor das duas freqüências de corte para projetar o filtro de reamonetagem. 4.2 Multistaque 4.2.1 Posso reescrever em múltiplos estágios Sim, mas há algumas restrições: se os fatores de interpolação ou de decimação são números primos, você não poderá decompor as partes do resamplificador em etapas. Você deve preservar os critérios de Nyquist em cada etapa, ou então o alias resultará. Ou seja, nenhuma etapa pode ter uma taxa de saída que é menos do que o dobro da maior freqüência de interesse. 4.2.2 Cool. Mas por que incomodar com tudo isso. Assim como com a interpolação e a decimação, os requisitos computacionais e de memória da filtragem de remateamento às vezes podem ser grandemente reduzidos usando múltiplos estágios. 4.3 Implementação 4.3.1 Como implemento o reescalonamento A implementação direta do reescremento é fazer a interpolação por um fator de L, depois a decimação por um fator de M. (Você deve fazê-lo nessa ordem, caso contrário, o decimador removeria parte Do sinal desejado - o que o interpolador não conseguiu restaurar.) 4.3.2 É a implementação direta eficiente. Não. O problema é que, para fatores de ressamamento próximos de 1,0, o fator de interpolação pode ser bastante grande. Por exemplo, no caso descrito acima de mudar da taxa de amostragem de 48 kHz para 44,1 kHz, a proporção é apenas 0,91875, no entanto, o fator de interpolação é 147. Além disso, você está filtrando o sinal duas vezes: uma vez no interpolador e uma vez no Dizimador. No entanto, um dos filtros tem uma largura de banda maior do que o outro, então o filtro de largura de banda maior é redundante. 4.3.3 Então, o que é a cura Apenas combine as vantagens computacionais e de memória que as implementações do interpolador FIR e do decimador podem fornecer. (Se você ainda não entende isso, certifique-se de ler e entender a Parte 2: Decimação e Parte 3: Interpolação antes de continuar.) Primeiro, revise brevemente o que torna a interpolação e decimação de FIRs eficientes: quando interpolando por um fator de L, você Só precisa calcular 1L das torneiras FIR por saída do interpolador. Ao dizimar por um fator de M, você só precisa calcular uma saída para cada entrada de M decimador. Então, combinando essas idéias, calcularemos apenas as saídas que realmente precisamos, usando apenas um subconjunto dos coeficientes de interpolação para calcular cada saída. Isso torna possível implementar de forma eficiente até mesmo reabsorventes de FIR que possuem grandes fatores de interpolação ou de decimação. A parte complicada é descobrir quais os filtros polifásicos a serem aplicados para quais entradas, para calcular as saídas desejadas, em função de L e M. Existem várias maneiras de fazer isso, mas eles estão todos além do nosso alcance aqui. 4.3.4 Onde posso obter o código-fonte para implementar um decimador FIR em C Iowegians O ScopeFIR vem com um conjunto de algoritmos de multirate grátis, incluindo as funções de ressampling FIR em C. Basta baixar e instalar o arquivo de distribuição ScopeFIR. 4.3.5 Como faço para testar um resamplificador FIR O método mais óbvio é colocar um seno cuja freqüência esteja dentro da banda passante dos reprografadores. Se um seno não distorcido sair, isso é um bom sinal. Note, no entanto, que, tipicamente, haverá um quotramp upquot no início do seno, devido ao preenchimento da linha de atraso de filtros com amostras. Portanto, se você analisar o conteúdo espectral do seno, certifique-se de ignorar a parte da aceleração. Dependendo do fator de reescalonamento, o reescalonamento pode ser considerado como um caso geral de outros tipos de filtragem de multirate. Pode ser: Interpolação: O fator de interpolação, L, é maior do que um, e o fator de decimação, M, é um. Decimação: O fator de interpolação, L, é um, mas o fator de decimação, M, é maior que um. QuotOrdinaryquot Filtering: os fatores de interpolação e decimação, L e M, são ambos. Portanto, se você testá-lo com sucesso com todos esses casos usando os métodos apropriados para cada caso, provavelmente está correto. Fast Fourier Transform (FFT) FAQ A Fast Fourier Transform é um dos tópicos mais importantes no processamento de sinal digital, mas é um assunto confuso que freqüentemente levanta questões. Aqui, respondemos as Perguntas Frequentes (FAQs) sobre a FFT. 1. Princípios básicos da FFT 1.1 O que é o FFT A Transformada de Fourier Rápida (FFT) é simplesmente uma maneira rápida (computacionalmente eficiente) de calcular a Transformação de Fourier Discreta (DFT). 1.2 Como funciona o FFT Fazendo uso de periodicidades nos senos que são multiplicados para fazer as transformações, a FFT reduz muito a quantidade de cálculo necessária. Heres um pouco de visão geral. Funcionalmente, a FFT decompõe o conjunto de dados a serem transformados em uma série de conjuntos de dados menores a serem transformados. Em seguida, ele decompõe esses conjuntos menores em conjuntos ainda menores. Em cada estágio de processamento, os resultados da etapa anterior são combinados de forma especial. Finalmente, ele calcula o DFT de cada pequeno conjunto de dados. Por exemplo, uma FFT de tamanho 32 é dividida em 2 FFTs de tamanho 16, que são divididas em 4 FFTs de tamanho 8, que são divididas em 8 FFTs de tamanho 4, que são divididas em 16 FFTs de tamanho 2. Cálculo de DFT Do tamanho 2 é trivial. Esta é uma explicação um pouco mais rigorosa. Acontece que é possível levar o DFT dos primeiros pontos N2 e combiná-los de forma especial com o DFT dos segundos pontos N2 para produzir um único DFT N-ponto. Cada uma dessas DFT de ponto N2 pode ser calculada usando DFTs menores da mesma maneira. Um (radix-2) FFT começa, portanto, calculando N2 DFTs de 2 pontos. Estes são combinados para formar N4 de 4 pontos DFTs. O próximo estágio produz N8 de 8 pontos DFTs, e assim por diante, até que uma única DFT de N-ponto seja produzida. 1.3 Quão eficiente é a FFT A DFT realiza operações N2 para pontos N. Uma vez que, em qualquer fase, a computação necessária para combinar DFTs menores em DFTs maiores é proporcional a N, e existem estágios log2 (N) (para a base 2), a computação total é proporcional a N log2 (N). Portanto, a relação entre uma computação DFT e uma computação FFT para o mesmo N é proporcional a N log2 (n). Nos casos em que N é pequeno, essa relação não é muito significativa, mas quando N torna-se grande, essa proporção fica muito grande. (Toda vez que você dobra N, o numerador dobra, mas o denominador só aumenta em 1.) 1.6 Os FFTs são limitados aos tamanhos que são potências de 2 Não. Os FFTs mais comuns e familiares são quotradix 2quot. No entanto, outras radiações são às vezes usadas, que geralmente são pequenos números inferiores a 10. Por exemplo, o radix-4 é especialmente atraente, porque os fatores quottwiddle são todos 1, -1, j ou - j, que podem ser aplicados sem qualquer multiplicação em absoluto. Além disso, os FFT de radixquot quotmixed também podem ser feitos em tamanhos quotcompositequot. Neste caso, você quebra um tamanho não-primário para baixo em seus fatores primos, e faz uma FFT cujos estágios usam esses fatores. Por exemplo, uma FFT de tamanho 1000 pode ser feita em seis etapas usando radios de 2 e 5, desde 1000 2 2 2 5 5 5. Também pode ser feito em três estágios usando radix 10, desde 1000 10 10 10. 1.7 Can FFTs devem ser feitos em tamanhos iniciais Sim, embora estes sejam menos eficientes do que FFT de radix simples ou de radix misturado. É quase sempre possível evitar o uso de tamanhos iniciais. 2. FFT Terminology 2.1 O que é um FFT quotradixquot O quotradixquot é o tamanho de uma decomposição FFT. No exemplo acima, a radix era 2. Para FFT de radix simples, o tamanho da transformação deve ser uma potência da base. No exemplo acima, o tamanho era 32, que é 2 para a 5ª potência. 2.2 Quais são os fatores quotwiddle. Fatores importantes são os coeficientes usados para combinar resultados de um estágio anterior para formar entradas para o próximo estágio. 2.3 O que é uma quotin placequot FFT Uma quotin placequot FFT é simplesmente uma FFT que é calculada inteiramente dentro de sua memória de amostra original. Em outras palavras, o cálculo de uma quotin placequot FFT não requer memória tampão adicional (como fazem algumas FFTs). 2.4 O que é quotbit reversalquot quotBit reversalquot é exatamente o que parece: inverter os bits em uma palavra binária da esquerda para a direita. Portanto, os MSBs se tornam LSBs e os LSBs se tornam MSBs. Mas o que isso tem a ver com os FFTs, a ordenação de dados exigida por FFTs de radix-2 acaba por estar em ordem quotbit reversedquot, então os índices invertidos em bit são usados para combinar estágios FFT. É possível (mas lento) calcular esses índices inversos de bits no software no entanto, as reversões de bits são triviais quando implementadas em hardware. Portanto, quase todos os processadores DSP incluem uma capacidade de indexação de inversão de bits de hardware (que é uma das coisas que os distingue de outros microprocessadores). 2.5 O que é quotdecimation-in-timequot versus quotdecimation-in-frequencyquot FFTs podem ser decompostos usando DFTs de Pontos pares e estranhos, que é chamado de FIT de Decimation-In-Time (DIT), ou podem ser decompostos usando uma abordagem de meio-semestre, que é chamada de FFT de Decimação-In Frequência (DIF). Geralmente, o usuário não precisa se preocupar sobre qual tipo está sendo usado. 3. Implementação FFT 3.1 Como implemento uma FFT Exceto como um exercício de aprendizado, você geralmente nunca precisará. Muitas boas implementações de FFT estão disponíveis em C, Fortran e outras línguas, e os fabricantes de microprocessadores geralmente fornecem implementações de FFT otimizadas gratuitas em seu código de montagem de processadores, portanto, não é tão importante entender como a FFT realmente funciona, pois é para entender como para usá-lo. 3.2 Não estou convencido. Eu quero realmente aprender como o FFT funciona. (Gosh youre difficile) Bem, praticamente todos os livros DSP no planeta cobrem a FFT em detalhes. No entanto, se você quiser ler algo online agora, consulte o Guia de cientistas e engenheiros do DSP. 3.3 OK, eu li essas coisas. Vamos direto ao assunto. Onde faço para obter uma implementação FFT Se você quiser uma implementação de linguagem de montagem, confira o site do fabricante do seu microprocessador DSP escolhido. Eles geralmente fornecem implementações de montagem altamente otimizadas em seus guias de usuários e manuais de aplicativos, e também como parte da biblioteca de seus compiladores C. Aqui estão algumas das melhores implementações do C: MixFFT - Esta implementação da FFT de Mixed-radix de Jens Joergen Nielsen é rápida, flexível e fácil de usar. FFTW - A mais rápida transformação de Fourier no Westquot. Existem várias listas fantásticas da FFT na net. Uma das melhores é jjs útil e feia página FFT. E o FFTW também possui uma página de links FFT muito boa. Colaboradores As seguintes pessoas contribuíram com perguntas, respostas ou sugestões úteis: Dale Grover. Marius Vollmer CORDIC FAQ CORDIC é um algoritmo iterativo para o cálculo de funções trigonométricas, incluindo seno, cosseno, magnitude e fase. É particularmente adequado para implementações de hardware porque não exige nenhuma multiplicação. 1.1 O que quotCORDICquot significa coordenação de coordenação de coordenação diodal de radiocomunicações. (Não ajuda muito, não é isso) 1.2 O que ele faz Calcula as funções trigonométricas de seno, cosseno, magnitude e fase (arctangente) para qualquer precisão desejada. It can also calculate hyperbolic functions, but we dont cover that here. 1.3 How does it work CORDIC revolves around the idea of quotrotatingquot the phase of a complex number, by multiplying it by a succession of constant values. However, the multiplies can all be powers of 2, so in binary arithmetic they can be done using just shifts and adds no actual multiplier is needed. 1.4 How does it compare to other approaches Compared to other approaches, CORDIC is a clear winner when a hardware multiplier is unavailable, e. g. in a microcontroller, or when you want to save the gates required to implement one, e. g. in an FPGA. On the other hand, when a hardware multiplier is available, e. g. in a DSP microprocessor, table-lookup methods and good old-fashioned power series are generally faster than CORDIC. 2.0 Examples 2.1 Do you have an example in the form of an Excel spreadsheet Funny you should ask: I just happen to: cordic-xls. zip. I highly recommend you open this up and look it over a little before you ask any more questions. 2.2 Do you have an example as C code 3.0 Principles To rotate by phases of less than 90 degrees, we will be multiplying by numbers of the form quotR 1 - jKquot. K will be decreasing powers of two, starting with 20 1.0. Therefore, K 1.0, 0.5, 0.25, etc. (We use they symbol quotLquot to designate the power of two itself: 0, -1, -2, etc.)Since the phase of a complex number quotI jQquot is atan(QI), the phase of quot1 jKquot is atan(K). Likewise, the phase of quot1 - jKquot atan(-K) - atan(K). To add phases we use quotR 1 jKquot to subtract phases we use quotR 1 - jKquot. Since the real part of this, Ir, is equal to 1, we can simplify our table of equations to add and subtract phases for the special case of CORDIC multiplications to: To add a phase, multiply by R 1 jK: Ic Ic - KmiddotQc Ic - (2-L)middotQc Ic - (Qc gtgt L) Qc Qc KmiddotIc Qc (2-L)middotIc Qc (Ic gtgt L) To subtract a phase, multiply by R 1 - jK: Ic Ic KmiddotQc Ic (2-L)middotQc Ic (Qc gtgt L) Qc Qc - KmiddotIc Qc - (2-L)middotIc Qc - (Ic gtgt L) Lets look at the phases and magnitudes of each of these multiplier values to get more of a feel for it. The table below lists values of L, starting with 0, and shows the corresponding values of K, phase, magnitude, and CORDIC Gain (described below):A few observations: Since were using powers of two for the K values, we can just shift and add our binary numbers. Thats why the CORDIC algorithm doesnt need any multiplies You can see that starting with a phase of 45 degrees, the phase of each successive R multiplier is a little over half of the phase of the previous R. Thats the key to understanding CORDIC: we will be doing a quotbinary searchquot on phase by adding or subtracting successively smaller phases to reach some target phase. The sum of the phases in the table up to L 3 exceeds 92 degrees, so we can rotate a complex number by - 90 degrees as long as we do four or more quotR 1 - jKquot rotations. Put that together with the ability to rotate -90 degrees using quotR 0 - j1quot, and you can rotate a full -180 degrees. Each rotation has a magnitude greater than 1.0. That isnt desirable, but its the price we pay for using rotations of the form 1 jK. The quotCORDIC Gainquot column in the table is simply a cumulative magnitude calculated by multiplying the current magnitude by the previous magnitude. Notice that it converges to about 1.647 however, the actual CORDIC Gain depends on how many iterations we do. (It doesnt depend on whether we add or subtract phases, because the magnitudes multiply either way.) 4.0 Applications 4.1 How can I use CORDIC to calculate magnitude You can calculate the magnitude of a complex number C Ic jQc if you can rotate it to have a phase of zero then its new Qc value would be zero, so the magnitude would be given entirely by the new Ic value. quotSo how do I rotate it to zero, quot you ask Well, I thought you might ask: You can determine whether or not the complex number quotCquot has a positive phase just by looking at the sign of the Qc value: positive Qc means positive phase. As the very first step, if the phase is positive, rotate it by -90 degrees if its negative, rotate it by 90 degrees. To rotate by 90 degrees, just negate Qc, then swap Ic and Qc to rotate by -90 degrees, just negate Ic, then swap. The phase of C is now less than - 90 degrees, so the quot1 - jKquot rotations to follow can rotate it to zero. Next, do a series of iterations with successively smaller values of K, starting with K1 (45 degrees). For each iteration, simply look at the sign of Qc to decide whether to add or subtract phase if Qc is negative, add a phase (by multiplying by quot1 jKquot) if Qc is positive, subtract a phase (by multiplying by quot1 - jKquot). The accuracy of the result converges with each iteration: the more iterations you do, the more accurate it becomes. Editorial Aside: Since each phase is a little more than half the previous phase, this algorithm is slightly underdamped. It could be made slightly more accurate, on average, for a given number of iterations, by using quotidealquot K values which would addsubtract phases of 45.0, 22.5, 11.25 degrees, etc. However, then the K values wouldnt be of the form 2-L, theyd be 1.0, 0.414, 0.199, etc. and you couldnt multiply using just shiftadds (which would eliminate the major benefit of the algorithm). In practice, the difference in accuracy between the ideal Ks and these binary Ks is generally negligible therefore, for a multiplier-less CORDIC, go ahead and use the binary Ks, and if you need more accuracy, just do more iterations. Now, having rotated our complex number to have a phase of zero, we end up with quotC Ic j0quot. The magnitude of this complex value is just Ic, since Qc is zero. However, in the rotation process, C has been multiplied by a CORDIC Gain (cumulative magnitude) of about 1.647. Therefore, to get the true value of magnitude we must multiply by the reciprocal of 1.647, which is 0.607. (Remember, the exact CORDIC Gain is a function of the how many iterations you do.) Unfortunately, we cant do this gain-adjustment multiply using a simple shiftadd however, in many applications this factor can be compensated for in some other part of the system. Or, when relative magnitude is all that counts (e. g. AM demodulation), it can simply be neglected. 4.2 How can I use CORDIC to calculate phase To calculate phase, just rotate the complex number to have zero phase, as you did to calculate magnitude. Just a couple of details are different. For each phase-additionsubtraction step, accumulate the actual number of degrees (or radians) you have rotated. The actuals will come from a table of quotatan(K)quot values like the quotPhase of Rquot column in the table above. The phase of the complex input value is the negative of the accumulated rotation required to bring it to a phase of zero. Of course, you can skip compensating for the CORDIC Gain if you are interested only in phase. 4.3 Since magnitude and phase are both calculated by rotating to a phase of zero, can I calculate both simultaneously Yes--youre very astute. 4.4 How can I use CORDIC to calculate sine and cosine You basically do the inverse of calculating magnitudephase by addingsubtracting phases so as to quotaccumulatequot a rotation equal to the given phase. Specifically: Start with a unity-magnitude value of C Ic jQc. The exact value depends on the given phase. For angles greater than 90, start with C 0 j1 (that is, 90 degrees) for angles less than -90, start with C 0 - j1 (that is, -90 degrees) for other angles, start with C 1 j0 (that is, zero degrees). Initialize an quotaccumulated rotationquot variable to 90, -90, or 0 accordingly. (Of course, you also could do all this in terms of radians.) Do a series of iterations. If the desired phase minus the accumulated rotation is less than zero, add the next angle in the table otherwise, subtract the next angle. Do this using each value in the table. The quotcosinequot output is in quotIcquot the quotsinequot output is in quotQcquot. A couple of notes: Again, the accuracy improves by about a factor of two with each iteration use as many iterations as your applications accuracy requires. This algorithm gives you both cosine (Ic) and sine (Qc). Since CORDIC uses complex values to do its magic, its not possible to calculate sine and cosine separately. 5.0 References 5.1 Where can I learn more about CORDIC on-line 5.2 What are some article references for CORDIC Jack E. Volder, The CORDIC Trigonometric Computing Technique . IRE Transactions on Electronic Computers, September 1959. J. E. Meggitt, Pseudo Division and Pseudo Multiplication Processes . IBM Journal, April 1962. 5.3 What are some book references for CORDIC M. E. Frerking. Digital Signal Processing in Communication Systems Fre94 . Henry Briggs, Arithmetica Logarithmica . 1624. 6.0 Acknowledgments Thanks to Ray Andraka for helping me understand. Thanks to Rick Lyons for review. Thanks to Mark Brown and Bill Wiese for providing links. Raised Cosine FAQ Raised-Cosine filters are commonly used in digital data modems. Here, we answer some RC filter Frequently Asked Questions (FAQs). 1. Raised Cosine Filter Basics 1.1 What are Raised-Cosine (RC) Filters 2.0 Design 2.1 How do I implement RC and RRC filters RC and RRC filters are generally implemented as FIR (Finite Impulse Response) filters. The linear-phase property of FIR filters makes them. Also, FIR filters are easy-to-implement and efficient. See our FIR Filter FAQ for more FIR information. 2.2 What are the parameters for RC and RRC filters The frequency responses of RC and RRC filters are fully specified by a single paramter, the quotrolloff factorquot this is a number between 0.0 and 1.0. It often is symbolized as either alpha or beta . But to design a FIR filter that will actually implement an RC or RRC response, you also need two more parameters, the number of taps (quotNTapsquot), and the number of samples per symbol (quot 2.3 How do I design RC and RRC filters RC and RRC filters can be designed in either the time domain (FIR impulse reponse) or the frequency domain (FIR frequency response). To design in the time domain, calculate the FIR filter coefficients directly from a formula (see below). To design in the frequency domain, use the definition of the RC or RRC response to fill an array representing the RCRRC frequency response. Then, use the Inverse Discrete Fourier Transform (IDFT) to calculate the FIR filters impulse response (coefficients). 2.4 What are some formulas for a Raised-Cosine and Root-Raised-CosineFilters 2.4 What FIR filter design programs can design RC and RRC filters This FAQ is still Under Construction. Digital Signal Processing HowTos How to Interpolate in the Time-Domain by Zero-Padding in t he Frequency Domain How to Interpolate in the Time-Domain by Zero-Padding in the Frequency Domain Performing interpolation on a sequence of time-domain samples is an important (often used) process in DSP, and there are many descriptions of time-domain interpolation (a kind of curve fitting) in the literature and on the Internet. However, therersquos a lesser-known scheme used for interpolation that employs the inverse discrete Fourier transform (IDFT). This little tutorial attempts to describe that technique. One of the fundamental principles of discrete signals is that quotzero paddingquot in one domain results in an increased sampling rate in the other domain. For example, the most common form of zero padding is to append a string of zero-valued samples to the end of some time-domain sequence. Looking at a simple example of this notion, Figure 1(a) shows a Hanning window sequence w(n) defined by 32 time samples. If we take a 32-point DFT of w(n), and just look at the magnitudes, we get the W dB (m) spectral magnitude plot shown in Figure 1(b). If, on the other hand, we zero pad (append) 96 zero-valued samples to the end of w(n), wersquoll have the 128-sample wrsquo(n) sequence shown in Figure 1(c). The spectral magnitude plot of a 128-point DFT of wrsquo(n) is shown in Figure 1(d), where we can see the more detailed structure of the Fourier transform of a Hanning window. So, in this case, we can say quotzero padding in the time domain results in an increased sampling rate in the frequency domainquot. Here the zero padding increased our frequency-domain sampling (resolution) by a factor of four (12832). For each sample in Figure 1(b), we have four samples in Figure 1(d). Many folk call this process quotspectral interpolationquot. OK, thatrsquos time-domain zero padding. No big deal, yoursquove probably seen this before. Now letrsquos see what frequency-domain zero padding (FDZP) will do for us by way of an example. Think of an 8-sample real discrete sequence comprising the sum of a 1 kHz and a 2 kHz sinusoids defined as: x(n)sin(2middotpimiddot1000middotnt s ) 0.5sin(2middotpimiddot2000middotnt s 3middotpi4), where t s is the sample period (1f s ), and the f s sample rate is 8000 samplessecond. Our eight x(n) samples are shown as the black dots in Figure 2. Wersquoll call x(n)rsquos 8-point DFT the frequency-domain sequence X(m), the real and imaginary parts of which are shown in Figure 3(a) and 3(b). OK, herersquos where the zero padding comes in. If we insert 8 zero-valued complex samples in the middle of X(m), wersquoll have a new complex spectrum whose real and imaginary parts are shown in Figure 3(c) and 3(d). Realize, now, that a complex zero is merely 0 j0. That quotmiddle of X(m)quot phrase means just prior to half the sample rate, or 4 kHz in this example. Because of the way the X(m)rsquos sample index numbering is mapped to the frequency-domain axis, we can think of this f s 2 4 kHz point as the highest positive frequency in the spectrum. Thus we insert the zeros after the first N2 spectral samples, where N is the length of X(m), in order to maintain spectral symmetry. (Wersquore assuming that the 4 kHz, X(N2), spectral component is zero, or at least negligibly small, in magnitude.) OK, letrsquos call this new 16-sample discrete spectrum Xrsquo(m). Now, herersquos the slick part. If we take a 16-point inverse DFT of Xrsquo(m), wersquoll get the interpolated time sequence shown in Figure 4. Check it out In between each of the original x(n) samples (shaded dots), wersquove calculated the intermediate time samples (the black dots). All 16 dots in Figure 4 represent the new interpolated 16-sample xrsquo(n) sequence. In this case, we can say quotzero padding in the frequency domain results in an increased sampling rate in the time domainquot. A few things to keep in mind about this FDZP technique: 1.) Notice the agreeable property that the FDZPrsquos interpolated time samples match the original time samples. (The shaded dots in Figure 4.) 2.) We must not append zeros to the end of the X(m) sequence, as occurs in time-domain zero padding. The complex zero padding must take place exactly in the middle of the original X(m) sequence, with the middle frequency sample being f s 2. 3.) The new time sequence xrsquo(n), the inverse DFT of Xrsquo(m), is complex. However, if we stuffed the zeros properly Xrsquo(m) will symmetrical and xrsquo(n)rsquos imaginary parts should all be zero (other than very small computational errors). Thus Figure 4 is a plot of the real parts of xrsquo(n). 4.) Notice how the amplitudes of the new xrsquo(n) time sequence were reduced by a factor of two in our example. (This amplitude reduction can, of course, be avoided by doubling either the Xrsquo(m) or the xrsquo(n) amplitudes.) 5.) In Figure 4 we interpolated by a factor of two. Had we stuffed, say, 24 zeros into the X(m) sequence, we could perform interpolation by a factor of four using the inverse fast Fourier transform (IFFT). The point here is that the number of stuffed zeros must result in an Xrsquo(m) sequence whose length is an integer power of two if you want to use the efficient radix-2 inverse FFT algorithm. If your new Xrsquo(m) sequencersquos length is not an integer power of two, yoursquoll have to use the inverse discrete Fourier (IDFT) transform to calculate your interpolated time-domain samples. Although I havent gone through a mathematical analysis of this scheme, the fact that its called quotexact interpolationquot in the DSP literature is reasonable for periodic time-domain sequences. Think of the standard technique used to perform time-domain interpolation using a low-pass FIR filter. In that method, zero-valued samples are inserted between each of the original time samples, and then the new (lengthened) sequence is applied to an FIR filter to attenuate the spectral images caused by the inserted zeros. The accuracy of that FIR filter interpolation technique depends on the quality of the filter. The greater the low-pass FIR stopband attenuation, the greater the image rejection, and the more accurate the time-domain interpolation. In this FDZP technique, for periodic time signals, image rejection is ideal in the sense that the spectral images all have zero amplitudes. If our original time-domain sequence is not periodic, then the FDZP scheme exhibits the Gibbs phenomenon in that there will be errors at the beginning and end of the interpolated time samples. When we try to approximate discontinuities in the time-domain, with a finite number of values in the frequency-domain, ripples occur just before and after the approximated (interpolated) discontinuity in the time-domain. Of course, if your original time sequence is very large, perhaps you can discard some of the initial and final erroneous interpolated time samples. From a practical standpoint, its a good idea to model this FDZP technique to see if it meets the requirements of your application. One last thought here. For those readers with Law Degrees, dont try to cheat and use this FDZP technique to compensate for failing to meet the Nyquist sampling criterion when your x(n) time samples were originally obtained. This interpolation technique wont help because if you violated Nyquist to get x(n), your X(m) DFT samples will be invalid due to aliasing errors. This FDZP scheme only works if Nyquist was satisfied by the original x(n). About the Author: copy 1999 Richard G. Lyons Used with permission. How to Design Minimum-Phase FIR Filters How to Design Minimum-Phase FIR Filters by Matt Donadio Like most things in DSP, there are several methods to create minimum-phase Finite Impulse Response (FIR) filters. Zero Inversion If you want to transform a symetric (linear phase) FIR into a minimum-phase FIR of the same length, you can simply determine the zeros of h(n), and then invert zeros which are outside the unit-circle (i. e. compute the reciprical). Since the zeroes of real, symetric FIR filters are grouped as conjugate recipricals ( a jb . a - jb . 1 (a jb) . and 1 (a - jb) ), all of the zeros will be doubles. (However, if the FIR has even length, there will also be a zero at w pi .) The filter will be suboptimal with respect to its length, but if you are experienced with pole-zero manipulation, you can move some of the zeros around to get a better filter. Spectral Factorization A second method, described in Lim88. is called Spectral Factorization . This method builds on the first. In the first method, we end up with pair of double zeros and a suboptimal filter. We can then design a prototype filter that meets H(z)2 and then convert it into a filter H(z) that has minimum phase. We can outline this as: Create an equiripple filter, FIR1, that will meet H(z)2 Calculate the zeros of FIR1. Delete the zeros outside the unit circle. Delete half of the double zeros on the unit circle. Convert the zeros into coefficient form. Compensate the gain of the new filter. This approach has a few subtlies, though. First is creating the prototype filter. We have to insure that the magnitude response remains positive. This somewhat complicates an equiripple design, but can be dealt with. If dp and ds are the required passband and stopband ripple for a lowpass minimum phase FIR, then the passband ripple of the prototype filter needs to be 4.0 dp (2.0 2.0 dp dp - ds ds) and the stopband ripple ds ds (2.0 2.0 dp dp - ds ds) This leads us to the second problem. The requirements above can result in a farirly long filter because the prototype filter is designed proportional to the squares of the final ripples. This can make it difficult to accurately calculate the roots of the prototype filter. Homomorphic Filtering A third method for creating a minimum phase filter uses homomorphic filtering . It is described in the both Lim88 and Opp89. We take the coefficients of our prototype filter as a sequence, then extract the minimum-phase component using a frequency-invariant linear filter. The steps are: Create an equiripple filter, that will meet H(z)2. Zero-pad the FIR. Four times the filter length works well. Calculate the DFT (or FFT) of the above. Calculate 0.25 log(H(k)2). Calculate IDFT (with scaling factor) of the results. Multiply pointwise by the homomorphic filter lminn 2un - dn, where dn dirac delta function. Calculate DFT of results. Calculate complex exponential of results. Calculate IDFT (with scaling factor) of the results. Keep half (or half 1 if orig length was odd) of the results as the minimum phase filter. The only real problem with this method is making sure that the DFTs are long enough to minimize the aliasing error. (Thanks to Roland Froehlich for giving me some code to test my implementation against.) Optimal Real and Complex Design Method The above methods only work for creating real-valued minimum phase filters. In addition, the methods that delete zeros in the Z domain need to use polynomial inflation to turn the final zeros into the filter coeficients. Polynomial inflation, in addition to root finding, can suffer from catastrphic numerical errors. A new method has been developed that can create both real and complex-valued FIR filters for arbitrary magnitude responses. This method is non-iterative and relies on properties of the Discrete Hilbert Transform. It can also be extended into higher dimensions. The interested reader should visit the page Optimal Design of Real and Complex Minimum-Phase Digital FIR Filters for more info. References How to Create Oscillators in Software How to Create Oscillators in Software by Matt Donadio Oscillators can be created in software directly, using the quotsinequot function, or they can be calculated indirectly using several different iterative methods. We survey those methods here. First, lets assume that: Real Oscillator Now, creating a real oscillator in software is equivalent to sampling a sinusoid, so is sufficient. This isnt very efficient, though, because we calculate a sine for each output point (though using a sine approximation can speed things up a little.) Another way is to use the following recurrence relationship for sinusoids: In pseudocode, it would look like: This has a problem, though. The recurrence relationship is a 2nd-order all-pole system with: into the standard quadradic equation solver: This has a pair of conjugate poles on the unit circle, and as a result, is nearly unstable. Despite this, the above approach tends to work well in practice, depending on the application, numerical representation, and precision used. (Fre94 has an excellent discussion of this method.) Complex Oscillator For a complex (quadrature) oscillator, we can use the above method using cosine for the real arm and sine for the quadrature arm (you can actually generate both at the same time see the Frerking for details). Another method is to view the problem as a rotating vector. We can create an initial vector and rotate is using a complex multiply for each point. You can derive this method from the cos(A B) and sin(A B) trig relationships. This approach still suffers from stability problems, though. The new recurrence relationship is This system has a single pole on the unit circle and is unstable. In this case, we can deal with it. We know that the length of the vector is 1, so we can normalize each point as we create it. If we define the magnitude of yn as inside of the quotforquot loop to normalize the magnitude of yn. We loose efficiency, though, because we calculate a square root for each point. However, if x is close to 1, then Since the length of the rotating vector will always be close to 1 (it will only stray from 1 due to roundoff error), we can use this relationship. We can change the AGC inside the for loop to Another method for creating an oscillator is to use a lookup table. The key to understanding the lookup table approach is understanding the concept of the phase accumulator. Lets look at a sampled sinusoid we can write the sampled sinusoid as Since the variable quotiquot is monotnically increasing by 1 each iteration, we can rewrite this as Now, here is the key. A very easy way to do modulo addition is to use twos complement math. So, if we make dw a twos complement register, the mod 2pi is implicitly done, and we can also use it to index into a precalculated lookup table. If we have M bits, then the most negative number will represent - pi and the most positive number will represent pi (minus a smidge). In practical applications, if we need N bits of phase resolution in the lookup table, we only use a table with 2 N4 entries and use the symetrical properties of sine to choose the proper entry. We also usually use a phase accumulator, delta phase, and initial phase with M bits, and M gt N. When we index into the lookup table we take N top bits of the phase accululator (either round or truncate) as the index. Reference: How to Generate White Gaussian Noise How to Generate White Gaussian Noise by Matt Donadio White Gaussian Noise (WGN) is needed for DSP system testing or DSP system identification. Here are two methods for generating White Gaussian Noise. Both rely on having a good uniform random number generator. We will assume that the function quotuniform()quot returns a random variable in the range 0, 1 and has good statistical properties. (Be forewarned, though, that many standard random number generators have poor statistical properties.) Once we can generate noise signals with normal distribution, we can adjust the signals mean and variance to use it for any purpose. Central Limit Thorem Method The Central Limit Theorm states that the sum of N randoms will approach normal distribution as N approaches infinity. We can outline an algorithm that uses this approach as: When the algorithm finishes, X will be our unit normal random. X can be further modified to have a particular mean and variance, e. g.: The drawback to this method is that X will be in the range - N, N, instead of (-Infinity, Infinity) and if the calls to uniform are not truly independent, then the noise will no longer be white. Jeruchim, et. al. recommend N gt20 for good results. Box-Muller Method The Box-Muller method uses the technique of inverse transformation to turn two uniformly distributed randoms, U1 and U2, into two unit normal randoms, X and Y. We can use some trigonometry to simplify this a bit and get: The above is called the Polar Method and is fully described in the Ross book Ros88. X and Y will be unit normal random variables (mean 0 and variance 1), and can be easilly modified for different mean and variance. How to Interpolate the Peak Location of a DFT or FFT if the Frequency of Interest is Between Bins How to interpolate the peak location of a DFT or FFT if the frequency of interest is between bins If the actual frequency of a signal does not fall on the center frequency of a DFT (FFT) bin, several bins near the actual frequency will appear to have a signal component. In that case, we can use the magnitudes of the nearby bins to determine the actual signal frequency. This is a summary of some methods found at Some Frequency Estimation Algorithms. (Other methods of sinusoidal parameter estimation which do not rely on the DFT are found on that page those methods also work well, and are sometimes faster than these.) The following notation is used below: k index of the max (possibly local) magnitude of an DFT. Xi bin quotiquot of an DFT Xi magnitude of DFT at bin quotiquot. k the interpolated bin location. The first two methods appeared in comp. dsp posts. Quadradic Method ( see post ) : Barycentric method (see post ) : Quinns First Estimator: Quinns Second Estimator: tau(x) 14 log(3x2 6x 1) - sqrt(6)24 log((x 1 - sqrt(23)) (x 1 sqrt(23))) ap (Xk 1.r Xk. r Xk1.i Xk. i) (Xk. r Xk. r Xk. i Xk. i) dp - ap (1 - ap) am (Xk - 1.r Xk. r Xk - 1.i Xk. i) (Xk. r Xk. r Xk. i Xk. i) dm am (1 - am) d (dp dm) 2 tau(dp dp) - tau(dm dm) k k d Jains Method : Of the above methods, Quinns second estimator has the least RMS error. References Posted 19990419, Released 19990503, Revised 19990505 Digital Signal Processing Tricks One of the things that makes DSP so interesting is its wide variety of tricks, usually to reduce the processing required for a given operation. The right DSP trick can be a nugget of gold. Here, we provide a gold mine of well known - and not so well known - DSP tricks. Expanded Table of Contents Top-Level Table of Contents Filtering Tricks DSP Trick: Simple Filter Coefficient Interpolation Often it is necessary to design a FIR filter coefficient set that is longer than can be practically computed using common automated routines like Parks-McLellan or its Remez subroutine. In most cases this problem can be alleviated by using P-M or Remez to design a short coefficient set and then interpolating it up to the desired length. A simple interpolation method that avoids some of the distortions that may be associated with linear, spline, or polynomial interpolation utilizes the interpolating capabilities of the DFT. The procedure may be achieved as follows: Design a shortened FIR filter that can be computed using an appropriate design technique. Take a forward DFT of this shortened FIR coefficient set. Zero pad the result up to the desired length of the final filter. Take the inverse-DFT of the zero-padded vector. The real part of the inverse-DFT is the interpolated coefficient set of the desired length. It is always prudent to verify that the interpolated filter has the desired response. Eric Jacobsen Minister of Algorithms, EF Data Corp. DSP Trick: FIR Filtering in C Name: Filtering in C Category: Programming Trick Advantages: Simple and fast This is more like a trick in C but might also be applicable in DSP environments. It allows to compute FIR-filtering in a fast manner when the filter length contains a factor of, lets say 4 (other factors are also possible). Lets suppose you have an array for the FIR filter coefficients wLEN and an array for the delay line xLEN. A straightforward approach to do the filtering operation would be: However, many processors dont like the index calculations, so it is sometimes advantageous to do less index calculations. Heres how it goes (suppose LEN is divisible by four. As stated above, the trick basically also works for other factors): I had pretty good result with this on a SPARC. DSP Trick: Filtering in QAM transmitters and receivers Name: Filtering in QAM transmitters and receivers. When NOT to do what the textbooks tell you to do. Category: Hardware architecture, or implementation Application: QAM receivers (with hardware emphasis) Advantages: The textbook descriptions of QAM receivers sometimes miss practical details. quotOptimalquot solutions may not be the best ones. These tricks are simply a list of possible reasons for deviating from quotnormalquot QAM filter design. Introduction: (what the textbooks tell you to do) Any modem which modulates a linear channel (AM, ASK, FM, FSK, PM, PSK, BPSK, QAM, QPSK, or even baseband signalling) subject to noise will use filtering to improve the error rate in the receiver. In general, there will be filters on the output signals (tx) and the input signals (rx), and also the bit in the middle (the channel). There are two parts to this: Eliminate ISI (Inter Symbol Interference) due to limitations in the frequency or phase response of the channel. Use matched filtering to produce a maximum likelihood receiver. 1. ISI can be eliminated if the channel (including tx and rx filters) frequency response is (1) linear phase, and (2) has symmetry about a point at half the symbol rate (Fs2). a here is actually alpha - the rolloff factor. (Although I have seen (1alpha) used instead of alpha.) Alpha can be between 0 and 1, but commonly this will be 0.3 to 0.5 (or 1.3 to 1.5 using the other definition.) for 30 to 50 excess bandwidth For some reason (because the maths isnt too hard), most implemenations use a quotraised cosinequot response. The rolloff section between (1-a)middotFs2 and (1a)middotFs2 is actually a half cycle of a cosine wave. Note: it is also possible to use an adaptive equaliser in the receiver (either before or after the symbol decisions are made) which can reduce ISI. But this is quotsimplyquot a filter which adapts its response so the above requirement is met. Adaptive equalisers are used when the channel response is unknown or changing. They may either quotadaptquot to a training sequence and then remain fixed (like a fax machine), or they continuously adapt. 2. A matched filter will produce the lowest errors in the receiver output for a channel which adds white gaussian noise (an AWGN channel) if the rx filter impulse response is the time inverse of the tx pulse shape. (The tx pulse shape is determined by the tx filter.) In the frequency domain, this means that the magnitude responses of the rx and tx filters are the same, but the phase responses are opposite (and the combination has zero phase (linear phase in practice)). The matched filter output is only valid at the symbol sampling instant. (This was inherent in the maths. If you want to know more, look at a textbook .) For example, if we transmit square pulses, then the rx filter should have a square impulse response. This would be an integrate-and-dump filter. 3. Combining 1 and 2 results in the following: An optimal modem will use root-raised cosine filtering in the tx and rx filters. (A root-raised cosine filter puts quothalfquot the response in the tx and quothalfquot in the rx filter, so that the product in the frequency domain is a raised cosine.) The total channel reponse will have zero ISI, and the tx and rx filters are the same, so we have minimised the probability of errors. The Tricks The above description can be found in any communications textbook. Now for what the textbooks leave out: some examples of when not to use quotoptimalquot filters. Must meet transmit spectral mask because: Certain regulatory bodies place restrictions on the tx spectrum from a modem. For RF modems, the out-of-band emissions sometimes have to be lt -80dBc. Sometimes, the tx signal will interfere with the rx signal at the same end of the link in nearby channels. This is known as NEXT (Near End Cross Talk). In the case of an RF modem, the tx signal can be more than 100dB stronger than the rx signal, so NEXT can be a big problem. Both of these place limits on the tx filter. This will entail: Using a small alpha. Truncating the tails of the tx filter frequency response. This will result in degraded performance. Truncate the rx filter reponse as well. Using a non-root-raised cosine tx filter. Pick one that allows a sharper rolloff. Allocating more of the raised cosine filter to the tx, and less to the rx Interfering signal has non-white spectrum. (AWGN assumption was made in the matched filter derivation.) Known narrowband interferers can be handled by putting a notch in the rx filter. If the notch is very narrow, the tx filter neednt be changed. Adjacent channel interference can be handled by making the rx filter slightly narrower. (See Trick 1 above) Symbol timing recovery problems. A matched filter produces a maximum likelihood estimate of the input symbol at a particular instant only. This assumes that this instant is known. Some simpler symbol-timing recovery schemes may require sub-optimal filtering to work. For example, wideband rx and tx filters allow signal transition detection to be used for symbol timing recovery. (This is how a UART works.) Symbol timing recovery is usually easier with larger alpha. (Books could be written about symbol-timing recovery. Any takers) When one of the filters cannot be controlled. Perhaps the receiver uses analog filtering only, possibly in a SAW filter in the IF (passband) or RLC filter at baseband (BTW, 2nd and 3rd order butterworth have been used here). This filter will only be rough approximation for a root-raised-cosine, and will not have a linear phase response. This can be compensated for in the (FIR) tx filter. When there are significant non-linearities (in the tx output amplifier). Usually, the requirement will be to have the smallest amount of AM in the tx, which allows the average output power to be higher for a given amount of spectral spreading (due to the non-linearity). This may require wider tx filters and narrower rx filters. Useful where power efficiency is important (satellite links, handheld equipment, etc). There is also a case for using a larger alpha here. In extreme cases, it is possible to pick a modulation scheme that has a constant-amplitude constellation. (OQPSK, GMSK, etc.) When the rx filter is inside a feedback loop controlling carrier phase or frequency tracking. The group delay of the rx filter limits the tracking bandwidth of these loops (due to stability considerations). If a wider loop bandwidth is required (perhaps because of capture range or perhaps poor phase noise performance in the up - and downconverters), then the rx filter may need to be changed if it is not possible to move it outside the loop. In this case, allocate more of the raised cosine filter to the tx, and less to the rx (or try harder to move it outside the loop). DSP Trick: Using Parks-McClellan to Design a Non-Linear Phase FIR Filter It is possible to use the Parks-McClellan algorithm to design FIR filters with non-linear phase response. For example, a FIR filter with the equivalent response of a Butterworth filter can be designed using the P-M routine. First, take a common Butterworth description like that in Parks and Burrus where H(x) is a complex function. Create two PM input grids using the real and imaginary components of the Butterworth response. Use PM (or quotremezquot or whatever its called on your favorite system) to design two FIR filters using the respective input grids, but turn the Hilbert switch on for the one derived from the imaginary component. Sum the results, i. e. add together the nth coefficients of each filter to create a single N-tap filter. The resulting FIR filter (assuming youve done your job to make sure everything converges) will have the desired response from the original expression used to generate the PM input grids. Function Approximation Tricks In DSP, the exact value of a mathematical function usually isnt needed: a degree of inaccuracy usually can be tolerated, and computational speed usually is a primary concern. The right combination of accuracy and speed is very much application-specific. Approximation of mathematical functions, therefore, is an important subject in DSP. Highly accurate approximations are well known. However, here we present some less-well known approximation DSP tricks which provide an outstanding combination of speed and accuracy. DSP Trick: Magnitude Estimator Name: Magnitude Estimator Application: Signal strength measurement, AM demodulation, etc. Advantages: This estimation algorithm is very quick compared to calculating magnitude to full precision using a square-root operation. Given a complex number represented as quotI jQquot, the magnitude is: sqrt(I2 Q2). Unfortunately, the square-root operation in this formula is inherently slow and complicated to calculate, either in software or in hardware. For applications which do not require a full-precision magnitude value, the use of a magnitude estimation can save calculations. This well-known and widely used algorithm is a true gem of DSP because it provides considerable savings in calculation, at the cost of only a minimal loss of accuracy. Given a complex number whose real part is quotIquot and whose imaginary part is quotQquot, the algorithm estimates the magnitude as: Alpha max(I, Q) Beta min(I, Q) quotAlphaquot and quotBetaquot are two constants whose values can be chosen to trade among RMS error, peak error, and implementation complexity. The absolute value operations folds the complex number into the range of 0-90 degrees, and the min, max operations further fold the complex number into the range of 0-45 degrees. Within this limited range, a linear combination of I and Q are a good approximation of magnitude. Values for Alpha and Beta: A program to demonstrate and test this algorithm is given at bottom. It includes a table of the most useful values for Alpha and Beta. The program prints out the following: If you need a more accurate estimation than this algorithm provides, you can use some variation of it. For example, varying values of Alpha and Beta can be taken from a small lookup table, driven by the relative size of min and max values. Another possibility is to use this estimate as the quotseedquot of an iterative magnitude estimator. As an alternative, consider using the CORDIC algorithm, especially in hardware applications. This algorithm is described in Understanding Digital Signal Processing by Richard G. Lyons Lyo97. in Digital Signal Processing in Communication Systems by Marvin E. Frerking Fre94. and elsewhere. Thanks to Clay S. Turner for providing some of the coefficients. DSP Trick: Quick-and-Dirty Logarithms Name: Quick and dirty logarithms Application: Needs fairly precise logarithm of a value quickly. Advantages: Very fast, very little computation. Look up table is small for precision to well under a dB. Compact hardware implementation. Works for arbitary logarithm bases. Disadvantages: Precision limited by table size. Requires normalized floating point input. Introduction: Logarithms are usually computed by using a taylor series or another iterative algorithm. This takes up valuable clock cycles or hardware. Such algorithms are also usually limited to a specific logarithm base. This trick takes advantage of the normalization and the exponent in floating point representations. The Trick: Floating point representation of a number separates the number into an exponent (usually in excess notation), a sign and a significand, also known as a mantissa. The number represented is then NM2E. The log (in whatever base is convenient) of that number is LOG(N)LOG(M 2E)LOG(M) ELOG(2). If we assume M is normalized, 1ltMlt2, then 0 ltLOG(M) ltLOG(2). The LOG of the exponent gives us the coarse estimate of the LOG (to 6dB), which can be found by just multiplying the exponent by a constant (LOG(2) in the appropriate base). For IEEE floating point, a constant offset may need to be added to the exponent to correct for the excess 128 notation. If finer precision is required, and heres the real trick, then we can obtain an estimate of the logarithm of the mantissa and add that to the logarithm of the exponent to get a more accurate estimate. The logarithm of the mantissa can be found using a small look-up table addressed by the most significant bits of M (the most significant bit is always 1 if M is normalized, so that bit need not be used in the address). The more bits of M used, the larger the table, and the more accurate the logarithm. A single bit from M will get you close to 3dB, while a 5 bit address (32 entry table) will get close to 14 dB accuracy, which is usually all that is needed. This trick works well in hardware (FPGA) implementations, since the table size is kept small enough to be implemented in one logic cell. For hardware implementations, it may be convenient to use the exponent to address a table instead of using a multiplier. DSP Trick: Fixed-Point Atan2 With Self Normalization Name: Fast fixed-pt. atan2 calculation with self normalization Application: Used when one wants to compute the 4-quadrant arctangent of a complex number (or any number with x-y coordinates) with a self-normalizing function. Example Applications: digital FM demodulation, phase angle computations Computing a 4-quadrant arctangent on DSPs has been the subject of many discussions. Several techniques such as table lookup and polynomial expansion are well known. In fixed-point DSPs, some normalization of the complex number may be necessary, effectively implementing a hard limiter or amplitude invariance function. In fact, computing: includes the necessary normalization, but in a fixed-pt. DSP, the division can result in values outside the fixed-pt. range of -1,1). Also, for certain applications, such as digital FM demodulation, any amplitude fluctuations must be removed before computing the phase angle. I computed a self-normalizing ratio depending on the quadrant that the complex number resides in. For a complex number z, let xRe(z) and yIm(z). For a complex number in quadrant I, compute the ratio: To get the phase angle, compute: Likewise, if the complex number resides in quadrant II, compute the ratio: And to get the quadrant II phase angle, compute: If it turns out that the complex number was really in quad IV instead of quad I, just negate the answer resulting from (2). Likewise, do the same if the number was in quad III instead of quad II. By doing this, you have a 4-quadrant arctan function. The max error using equations (2) or (4) is a little less than 0.07 rads (only at a few angles though). The accuracy of the estimator is actually quite good considering using a 1st-order polynomial to estimate the phase angle. If you use a higher degree polynomial, it turns out that the even powers of the poly will disappear (due to the odd function), thus relaxing some of the computational load. QUICK NOTE FOR BETTER ACCURACY: To obtain better accuracy (a max error of .01 rads), one can replace equations (2) and (4) with: equations (2a) or (4a) can be computed using 2 MACs, which does not involve much more computation for a 7x increase in accuracy. Here is some C pseudocode (not optimized in any fashion) using equations (1)-(4): DSP Trick: Simultaneous Parabolic Approximation of Sin and Cos Name: Simultaneous parabolic approximation of sin and cos Application: When you need both sin and cos at once, and you need em fast, and using multiplications and parabolic approximation is OK, try this. Possible applications are audio panning, mixing fader, maybe even realtime filter coefficient calculations and 2D3D rotation transformations. Advantages: Cheap, only one or two multiplies per approximation pair. No discontinuities. A quarter of a sinusoid cycle is approximated with a parabola. The remaining quarters are horizontally and vertically flipped versions of the approximated quarter. Instead of creating two different approximations, the same polynomial is used for both sin and cos. The positive crossing point of sin(angle) and cos(angle), at anglepi4, is made to correspond to x0 in the polynomial. This shifts the center of a quarter at x0 and turns switching between quarters (and between sin and cos) into x and y sign flips. The range that is approximated is: Angle and x are related by: The approximation: (quot quot stands for quotapproximately equalsquot) As you see, the only difference is in the last sign, so you can calculate the part left from that first and then add or sub x to get sin or cos. For different angle ranges, you have to flip signs of the whole equation or the sign of the x term. See the example source code. c is a constant that can be fine-tuned for different applications. With c yet undefined, the polynomials hit 0 and 1 in the right places. Here are some differently optimized (and approximated) values for c: To compare the errors produced by different choices of c, we look at the maximums and minimums of the following error measures, for different c: The different c were optimized as follows: A) was optimized for minimum maximum absolute difference to sin. B) was optimized for minimum maximum absolute difference of sqrt(sinapprox(x)2cosapprox(x)2) to 1. This is important for example in a rotation transformation, where you want the dimensions to stretch as little as possible from the original. Note, though, that C) gives the lowest total magnitude quotwobblingquot range. C) was optimized similarly to B but never lets sqrt(sinapprox(x)2cosapprox(x)2) exceed 1. This is useful if you calculate filter coefficients and dont want unstable poles. Also, sinapprox(0) and cosapprox(0) give sqrt(2)2, which is the correct value. D) was optimized for continuous differential, which reduces high harmonics. This is good if you are creating sine and cosine signals rather than doing quotrandom accessquot to the function. Also, it eliminates the other multiplication, making the algo one-mul and low bit-depth: DSP Trick: Square Root Computation Name: Square root computation Category: Algorithmic Trick Application: e. g. Magnitude computation Advantages: Simple and fast Once in a while the square root of data has to be computed on a DSP. A method that comes to mind is polynomial approximation of the square root function. A much simpler method, however is the usage of Newtons method or, if division is a problem, successive approximation. 1) Newtons method: Newtons method states that if you want to find the zero of a function f(x) you may start at some guessing point x1 and compute the next guessing point for the zero x2 according to In the next step make x1 : x2 and repeat equation (1) etc. until the difference between x1 and x2 is sufficiently small. Newtons method does not alway converge, but if it does, it converges fast. In the special case of the square root computation Newtons method is guaranteed to converge. Lets say you want to compute x sqrt(z) then make If we compute f(x) 0 we immediately see, that x must be the square root of z. Now plug (2) into (1) to get which is the recursive equation to be used. The starting value for x1 is not critical but the closer it is to the real zero the better. I usually use x1 z. 2) Successive approximation: If division is a problem, then successive approximation might be the right choice to compute sqrt(x). Successive approximation basically does a binary search to find the square root. A little C-style pseudocode might best explain how it is done: Again, there might be better choices for the starting point but the one given is safe. DSP Trick: Polynomial Evaluation via Horner039s Rule Name: Polynomial Evaluation Category: Algorithmic Trick Application: e. g. Polynomial approximation of a transcendental function Advantages: Simple and fast Introduction: When evaluating a polynomial it is advantageous to use Horners rule as this nicely fits the MAC architectures of DSPs. Suppose you want to compute a polynomial: Horners rule to compute this polynomial is given by: or in a little C-snippet another, even better possibility is: Data Conversion Tricks DSP Trick: Fast Floating-Point to mu-Law Conversion Name: Fast floating point to mu-law conversion Application: When you need to convert audio data to mu-law and dont have a lot of time to mess around. Advantages: Very Fast (I implemented this in a seven cycle loop on a Sharc processor). Introduction: This trick is based upon the happy coincidence that mu-law compressed data is very much like a poor mans floating point format. Mu-law is a companding method fully descried in the ITU specification G.711. I believe this algorithm to be fully compliant. The Trick: The algorithm is performed in a few steps. The steps are described below. Although I have implemented and tested this approach in assembly on a Sharc, I am not at liberty to post the code (I do not own it). This approach will work when the data is already in floating-point format as per IEEE 754. Other floating point formats (i. e. Texas Instruments) may work as well, but will require adaptation. The input data is expected to range from -1.0 to 1.0. I present a C algorithm, which will not be fast, but should get the basic idea across. DSP Trick: Gray Code Conversion Name: Binary Gray Code Conversion Application: Some sensors send information in Gray code. These must be converted to binary in order to do arithmetic with it. Occasionally, it is necessary to convert back. Advantages: Higher speed or smaller code than other ways Ive seen. (A neat way to do this is elusive enough that Ive seen it done with a look-up table.) Introduction: The by-the-book conversion of Gray to binary is O(N-1), where N is the word length. One of my algorithms is O(log(N)-1), where N is the word length rounded up to a power of two. The other is O(N-1) (including N-1 subroutine calls), but the code is very compact, especially if binary-to-Gray is also needed. A Gray code is one in which adjacent numbers differ by one symbol. There are many Gray Codes, even in binary. They can be devised in any base. When Gray (or Gray code) is used without specifying which one, what is meant is reflected Binary Gray. To convert binary to Gray, it is only necessary to XOR the original unsigned binary with a copy of itself that has been right shifted one place. That is easy to do with common instructions. The cannonical way to convert Gray to binary is to XOR the bits one at a time, starting with the two highest bits, using the newly calculated bit in the next XOR. Ugh I show two easier ways here. Robert Sherry wrote the actual C code. The function declarations make these shorts and the code assumes 16 bits you can change that. Miscellaneous Tricks DSP Trick: Complex Downconverters for Signals at Fs4 or 3Fs4 PREDate: Thu, 22 Apr 1999 02:52:42 GMT From: Allan Herriman ltallan. herriman. hates. spamfujitsu. augt Newsgroups: comp. dsp Subject: Re: DSP Tricks THIS WORK IS PLACED IN THE PUBLIC DOMAIN Name: Complex downconverters for signals at Fs4 or 3Fs4 Category: Hardware architecture Application: Use for QAM modem receivers in FPGAs. Dont use if the local oscillator needs to be frequency agile. Advantages: This trick produces a trivially simple fixed frequency complex downconverter without needing an NCO or sine lookup tables quotClassicalquot modem receiver architecture using complex baseband processing: The X are multipliers. Typically, the FIR lowpass filters will be decimating types if the signal bandwidth is much less than the sample frequency, Fs. Polyphase filters may also be used here to resample the signals at the symbol rate (or 2x the symbol rate, etc) if this is not an integer submultiple of Fs. If the local oscillator isnt required to have a controllable frequency or phase, and it is possible to centre the input signal around Fs4 or 3Fs4, then the hardware can be dramatically simplified. Local oscillator outputs at Fs4: Cos: 1, 0, -1, 0, 1, 0, -1, etc. Sin: 0, 1, 0, -1, 0, 1, 0, Since we only need to multiply by 0, -1 or 1, the multiplier is trivial. Every second input to each filter is 0, so the filters only need to run at Fs2. (In this case, we only need to multiply by -1 or 1.) The multiplier can be removed altogether, and the - performed in the filter, either by twiddling the coefficients or by telling the accumulator to subtract. Since the Cos and Sin terms are never non-zero at the same time, it may be possible to to use just one FIR filter, designed to handle IQ interleaved data. This filter will have two accumulators which alternate between input samples. There are filter chips designed to do this, such as the HSP43168 from Harris. (Although there are better chips for new designs. ) This trick also potentially saves routing in FPGAs. Note: if this is a QAM receiver, then a separate carrier phase correction stage after the lowpass filters will be required. Also, any frequency errors in the input signal will be present during filtering. The solution is to: Tolerate this problem (after quantifying its effects). Use an AFC loop which controls the frequency error before downconversion. Dont use this trick - use an NCO as the LO. DSP Trick: Sinusoidal Tone Generator Name: Sinusoidal tone generator Application: If they need to generate a continuous tone of specific frequency and amplitude. Advantages: Fast and accurate. Ive seen this trick in a few different places, although never the (very simple) deriviation. It is based on the z-transform for sin(wn). Taking the inverse z-transform: Solving for the initial conditions (start at n1 since y0 and y-1 are so trivial to compute): where Ft is the tone frequency and Fs is the sampling frequency. For example, to generate a 1 kHz tone with a sampling frequency of 8 kHz: Note that all calculations were done with 64-bit floating point and rounded by hand. The z-transform of this shows two poles on the unit circle at - pi4 radians. Ive never encountered stability issues but care should be taken to evaluate quantization effects on the system. DSP Trick: Fast Floating Point to Mu-Law Conversion DSP Trick: Fast Floating-Point to mu-Law Conversion Name: Fast floating point to mu-law conversion Application: When you need to convert audio data to mu-law and dont have a lot of time to mess around. Advantages: Very Fast (I implemented this in a seven cycle loop on a Sharc processor). Introduction: This trick is based upon the happy coincidence that mu-law compressed data is very much like a poor mans floating point format. Mu-law is a companding method fully descried in the ITU specification G.711. I believe this algorithm to be fully compliant. The Trick: The algorithm is performed in a few steps. The steps are described below. Although I have implemented and tested this approach in assembly on a Sharc, I am not at liberty to post the code (I do not own it). This approach will work when the data is already in floating-point format as per IEEE 754. Other floating point formats (i. e. Texas Instruments) may work as well, but will require adaptation. The input data is expected to range from -1.0 to 1.0. I present a C algorithm, which will not be fast, but should get the basic idea across. DSP Trick: Fixed-Point DC Blocking Filter with Noise-Shaping Name: Fixed-Point DC Blocking Filter With Noise-Shaping Application: Used anytime DC offsets need to be removed (audio level metering or nearly any audio signal processing to avoid clicks). Since AD converters and their front end circuitry cannot be expected to be totally DC free, this is useful partly to insure that silence is equavalent to zero. Advantages: Utterly wipes out DC without introducing its own DC Introduction: The use of a digital differentiator along with a leaky integrator (essentially a one-pole LPF) to accomplish DC blocking is nothing new. It is essentially a 1st order HPF. Differentiator: ynxn - xn-1 Leaky Integrator: ynpoleyn-1 xn (0 lt 1-pole ltlt 1) if pole1, then it is a non-leaky integrator and completely undoes the differentiator. However, doing this with a fixed-point DSP (such as the 56K) introduces a couple of problems. First the order of operations has to be considered. Leaky Integrator first followed by differentiator: Since the differentiator truly wipes out DC no matter what the numerical issues are, this has the advantage that no DC gets into the output. The disadvantage is that if the pole is very close to 1 (which is necessary if you want your DC blocker to just block DC and other very low frequencies), the the gain of the leaky integrator blows up at low frequencies, enough that saturation is vitually assured and the post differentiation will not fix that horrible distortion. Differentiator first followed by leaky integrator: DC is killed in the first stage and the gains at low frequecies are reduced enough to guarantee that the integrator does not saturate. Also, there is no quantization error introduced by the differentiator so there isnt the problem of the integrator boosting quantization noise at low frequencies. The disadvantage is that the integrator creates its own DC problems due to quantization (rounding or truncating down) and limit cycling. This limit cycling happens when the amount that yn is reduced by multiplying by pole is equal to 12 LSB and rounding returns yn1 back to its previous non-zero value yn. it gets stuck on a non-zero value that gets measurably large as pole gets close to 1. We use the 2nd option above (differentiator first) and deal with the limit-cycling problem using error-shaping or noise-shaping with a zero on DC (Randy Yates called this quotfraction savingquot). By feeding back the quantization error that occurs in the one-pole LPF (the leaky integrator), one can design an error-to-output transfer function to have a desired frequency response (to literally shape the noise or error spectrum to steer noise away from where you dont want it to where you can tolerate it). With a zero of this noise transfer placed right on z1 (or at DC) we force the amplitude of the error in the output to be zero at the frequency of 0 (at the expense of increasing the error amplitude at Nyquist). We literally will have infinite SN ratio at DC. Therefore if no DC goes into the LPF (and the differentiator sees to that), then no DC comes out. Even if the quantization is not rounding to nearest but always rounding down (definitely a DC bias here) any DC introduced gets killed by the error shaping (this is what happens with fraction saving). I got this down to 3 instructions per sample in a 56K (using sample buffering, another trick, and pipelining) but here is what it might look like using C code: DSP Trick: Dealing With Propagating Truncation Errors Name: Dealing with propagating truncation errors. Category: Algorithmic tricks. Application: When values are truncated, and the truncated values are used later in the algorithm, ultimately corrupting the output. Advantages: You get an acceptable output without having to switch to a completely different algorithm, and generally without having to sacrifice too much execution time. Introduction: When you truncate or round the value of, say, a 32-bit product register to 16 bits, you may wind up getting pesky little rounding artifacts due to the reduced precision. Although it isnt a problem in most applications, sometimes the small rounding errors do propagate through subsequent stages of an algorithm and eventually corrupt the output. Here are a couple of suggestions that can help you get a cleaner output. Use extended-precision arithmetic, such as larger-width multiplies and add-with-carry operations, but thats computationally expensive. I think this is the most common way to kill those pesky errors that begin to accumulate. Processor support for extended-precision arithmetic includes: add with carry and subtract with borrow multiplication of signedsigned, signedunsigned, and unsignedunsigned operands Create quotleakage. quot This means that at strategic logactions in an algorithm you multiply with (1-epsilon) so that a value continously becomes slightly smaller than it was supposed to do. If you do that in a feedback loop, the errors that are feeding back will fade out. Dither the signal. You may find instability caused by a limit cycle appearing for zero (i. e. smaller magnitude than one LSB) or constant input. Or, an algorithm may quotstallquot because an input signal is too weak to excite the variables in an algorithm. Both problems may be eliminated by dithering the variables in the algorithm. You do that by adding white noise to the variables. In Handbook of Digital Signal Processing: Engineering Applications Ell87. Douglas F. Elliot discusses quoterror feedbackquot. As far as I remember, this is a technique where you essentially quotsavequot the truncation error of a previous iteration and add it in the next iteration, effectively introducing some redundancy. This redundancy effectively creates extended precision for you with less computational effort. If everything gets out of hand, have some error detection mechanism built into the algorithm (say, to check for magnitude of a certain variable) and re-initialize your algorithm by resetting coefficients or what else you can think of resetting. Digital Signal Processing Tutorials Digital Signal Processing is a difficult and complex subject. Here, we offer tutorials to clear up some of the mysteries of DSP. Quadrature Signals: Complex, But Not Complicated Understanding complex numbers and quadrature signals is essential for understanding DSP at both a theoretical and a practical level. Yet this strange, complex subject (based on the admittedly imaginary construct of the square root of negative one ) is among the hardest for DSP beginners to grasp - and is confusing at times even for advanced DSPers. But dont despair: help is on the way. In this tutorial, Rick Lyons. author of the best-selling DSP books Understanding Digital Signal Processing and Streamlining Digital Signal Processing: A Tricks of the Trade Guidebook . clears the fog around this difficult subject by providing the clearest, most intuitive explanation yet of quadrature signals and their importantance in Digital Signal Processing. QuadSignals (200K, pdf) Version 2, January 2008 Cascaded Integrator-Comb (CIC) Filter Introduction In the classic paper, quotAn Economical Class of Digital Filters for Decimation and Interpolationquot, Hogenauer introduced an important class of digital filters called quotCascaded Integrator-Combquot, or quotCICquot for short (also sometimes called quotHogenauer filtersquot). Here, Matthew Donadio provides a more gentle introduction to the subject of CIC filters, geared specifically to the needs of practicing DSP designers: A Little MLS (Maximum-Length Sequence) Tutorial A Little MLS Tutorial by Robert Bristow-Johnson A Maximum-Length Sequence (MLS) has two different (but related) definitions: One is the driving function applied to the input of a linear time invariant (LTI) system: The other definition is simply the binary sequence, an 0 or 1, used in the exponent. It is clear that xn or - X and that its RMS and peak values are both X, making its crest factor (peakRMS) equal to 1, the lowest it can get. This is why MLS is as noise-immune (for broadbanded noise) as you can get. In comparison, the other popular measurement method, Linearly Swept Frequency measurements, has a crest factor of sqrt(2) which is good but not quite as good as MLS. Also, the autocorrelation of xn is (N is defined later.) It is clear that The value of Rxn for n 0 is determined later. The sequence an is generated from a shift register exclusive-or (XOR) operation using the K bit word An which is akn are the bits of the word and an can be chosen to be any of the K bits but, for simplicity, well choose ana0n, the LSB. The shift and XOR operation is explicitly for 0 lt k lt K and it is understood that aKn is always zero. pk are the K most significant bits of the Kth order quotprimitive polynomialquot, P, (K1 bits) which is a specially chosen constant. Now it is clear that An is a function of its previous state, An-1 and the primitive polynomial, P. Since A has K bits, there are 2K possible bit permutations and conceivably An can have 2K possible states before the sequence repeats. But it is clear that the zero state must map only to the zero state, no matter what P is. So we define an to be an MLS and P to be a primitive polynomial if . starting with a nonzero state for An, all other nonzero states of An are taken before An gets back to the original state and the sequence of An states repeats. There are 2K - 1 nonzero states so the MLS would have length of 2K - 1 (if you exclude the zero state, thats as long as it gets) which we now define to be N-1 (or N2K). A few bit combinations for P will result in An being an MLS and other bit combinations will result in An returning to any given state before N-1 shift XOR operations. Clearly the MSB of P, pK, must be 1 or you immediately reduce the number of An states by 12. Okay, if you pick on any bit of An, particularly the LSB, a0n (or an), you will see that there are exactly N2 quot1quot bits and N2 - 1 quot0quot bits because the zero state is not part of the An sequence. So there is one more quot1quot bit to an than quot0quot bits and there is one more sample that xn is -1 than 1 for each cycle of the MLS. Now, heres the nontrivial part: if one takes an MLS, ai, which is a circular or repeating sequence, and XOR that with a shifted copy, ani, you will get either the zero sequence (if n0), or the very same MLS circularly shifted a completely different shift delay, ami. That is This is because which says the very same rule that generates the MLS, ai, is the rule that governs the sequence: ai XOR ain. That says the XOR sequence must either be the zero sequence (what happens when n 0) or the same MLS (possibly circularly shifted to some other delay amount). Now, what this says is that the autocorrelation defined above is because when n is not 0, the SUM has N2 quot-1quot terms and (N2 - 1) quot1quot terms resulting in one extra quot-1quot term. where dn is the periodic unit impulse function So, except for a little DC bias, xn has the same autocorrellation as white noise if N is large enough. Now, to make your MLS measurement, you squirt some MLS at your target and cross-correlate the result against all delayed versions of the same MLS yn is the output of your LTI: where hn is the impulse response. If the impulse response is much shorter than the MLS length N-1, than the only term in the left SUM we have to count is the m 0 term, resulting in This says that, except for a small and negative DC offset, the result of the cross-correlation is the impulse response of the system scaled up by the energy of the driving MLS function. From the impulse response, everything else about the LTI system can be computed (frequency response, etc.) A note about usage: MLS drives the input with a period function of length N-1. This causes quottime aliasingquot in the resulting measurement which is also periodic with the same period. To avoid problems choose N to be at least twice as long as the expected length of the impulse response (a problem of circular logic requiring you to know something about the impulse response before you measure it). The other necessary measurement issue is that you must drive your system with two concatenated cycles of the MLS, the first one to excite the system into a steady state and the second to make the complete impulse response measurement. Whats wrong with MLS MLS has truly weird behavior when there are small nonlinearities. now remember, linearity and time-invariancy is assumed when you are trying to measure frequency response using any method but some methods work better than others in the presence of nonlinearity. The MLS that is applied to the system under test can be represented as: where an0 or 1 and is the LSB (or any single bit) of the shift register sequence (with exclusive-OR in the feed back path) that the computer science guys like to call a maximum length sequence. for clarity, i will call xn an quotMLSquot and an an quotMLS bit sequencequot. Bboth are periodic, with period N-12K - 1, where K is the number of bits in the shift register word. Now, one thing that is shown in the tutorial is that if you take the MLS bit sequence, an, and exclusive-OR it against a circularly shifted version of itself, you get another copy of an but shifted by some other, seemingly random, amount. that is: Restated slightly differently although, strictly speaking, k does depend on j, its essentially a psuedo-random dependence. given an i and j (j not0), k could be any wild number between 1 and N-1. For now just push that fact onto your stack (well pop it off later). MLS measurement errors come about when there are nonlinearities (the tutorial explains how, for a perfectly linear, time-invarient system, MLS measures your system impulse response). in a 1995 letter to the AES, some guy named Matthew Wright, had the insight to explain why these spurious and randomly delayed spikes were getting added to the measured impulse response. If the system is modeled as a Volterra series (which is a pretty general way to model a nonlinear, non-memoryless system) you will get some cross-product terms that look like: Now, those nonlinear cross-products can be manipulated a little: That means the nonlinear cross-product term ( someCoefxn-ixn-i-j ) is gonna look just like the input sequence but delayed by some wild value, ki, and scaled by someCoef. So the measured impulse response will have an impulse delayed by ki and scaled by someCoef. That is where you can get problems in the impulse response and problems in the frequency response. Now, since this behavior is deterministic and repeatable (even though it looks like a random delay), you can repeat the measurement and average until the cows come home (or the cliche of your choice), and this problem will not go away. There are techniques for dealing with it (like try different MLSs based on different primitive polynomials and median filtering) but averaging the response using the same MLS wont help. References Douglas D. Rife and John Vanderkooy, quotTransfer-Function Measurement with Maximum-Length Sequencesquot, Journal of the Audio Engineering Society, Vol. 37, Number 6 pp. 419 (1989). This article presents a comprehensive analysis of transfer-function measurement based on maximum-length sequences (MLS). MLS methods employ efficient cross correlations between input and output to recover the periodic impulse response (PIR) of the system being measured. John Vanderkooy, quotAspects of MLS Measuring Systemsquot, Journal of the Audio Engineering Society, vol 42, no 4, (Apr 94). Matthew Wright, quotComments on Aspects of MLS Measuring Systemsquot, Journal of the Audio Engineering Society, vol 43, no 1, (JanFeb 95). Multipath Channel Model Using DSP Multipath distortion is a common problem in many DSP-based data transmission systems. Here, Neil Robertson shows how to model multipath channels using complex-coefficient FIR filters. Reducing FFT Scalloping Loss Errors Without Multiplication Sum of Two Sinusoidal FunctionsFinancial The module is dedicated to finance. There are three main areas that are covered: risk measure and management, asset allocation, pricing. For what concerns the risk measure, some functions are dedicated to the computation of Value at Risk (VaR) and Expected Shortfall (ES). Backtest is also implemented in order to check the goodness of such risk measures. Both VaR and ES are also computed in an Extreme Value Theory framework (EVT). Furthermore, it is possible to estimate the parameters of the EVT density function (through maximum likelihood). The Mean Excess Function for graphical study of an EVT distribution is also implemented. The interest rate risk is faced by functions aimed at computing duration, convexity, and yield to maturity. Furthermore, Merton, Vasicek and Cox, Ingersoll and Ross interest rate models are implemented together with the estimation of their parameters. Parametric interpolation of the interest rate curve is possible through both Svennsons and Nelson-Siegels models. Finally, some technical analysis indicators are implemented: Bollinger bands, moving averages, Hurst index. The asset allocation problem is faced by two functions which compute: the optimal portfolio minimizing the variance of its return and the optimal portfolio minimizing the expected shortfall of its return. In both cases, the portfolios with and without a riskless asset and with and without short selling are computed. Pricing problem is approached through functions aimed at: computing the spread on Interest Rate Swaps, computing the value of options in the Black and Scholes framework (with Greeks and implied volatility), simulating stochastic processes (through Euler discretization). backtest. Apply the backtest to Expected Shortfall, Value at Risk and a Linear Spectral risk measure. bollinger. Plots the historical prices, the Bollinger bands, and the b-percentage. bsgreeks. Compute the Greeks for Black and Scholes put and call options. bsimpvol. Compute the implied volatility in a Black and Scholes framework. bsoption. Compute the value of both a call and a put option in a Black and Scholes framework. cfr. Compare and merge two or more time series according to dates. duration. Compute both duration and convexity of cash flows by using the yield-to-maturity. esvarevt. Compute both Expected Shortfall and Value at Risk. esvarlin. Compute Expected Shortfall, Value at Risk and a Linear Spectral risk measure on a set of assets. esvaroptim. Compute the optimal portfolio minimizing the Expected Shortfall. euler. Simulate the solution of a system of stochastic differential equation. evt. Estimate the parameters of the Generalized Pareto Distribution. gbm. Estimate the parameters of a Geometric Brownian Motion. hedge. Compute the hedge ratio between an asset and a derivative on that asset. hurst. Compute the Hurst index on historical prices. interest. Estimate the parameters of three spot interest rate models (Merton - Vasicek - CIR). irs. Compute both the spread and the value of the legs of a fix-for-floating Interest Rate Swap. markowitz. Compute the optimal portfolio minimizing the variance. mef. Compute and draw the Mean Excess Function. movav. Compute and draw the moving average of a given time series. nelsonsiegel. Estimate the parameters for the Nelson Siegel model of spot interest rates. svennson. Estimate the parameters for the Svennson model of spot interest rates.
No comments:
Post a Comment