DSP卷積算法

卷積和(簡稱卷積)是信號處理中常用的算法之一。數字卷積運算通常採用兩種方法:線性卷積和圓卷積。爲了能使卷積運算在C54x系列DSP上的實現方法,首先要對數字卷積的基本概念作深入瞭解。使大家從根本上掌握卷積的實現方法,我們以模擬信號的卷積和數字信號的卷積爲主,以及他們在C54x系列DSP上的實現方法。
1.卷積的基本原理和公式
卷積和:Y(n)= ∑X(m)H(n−m)=X(n)*H(n) m=−∞
對離散系統“卷積和”也是求線性時不變系統輸出響應(零狀態響應)的主要方法。
2.卷積和的運算在圖形的表示
可分爲四步:
A) 翻褶 現在亞變量座標M上作出X(m)和H(m),將m=0的垂直軸爲軸翻褶成H(-m)。
B) 移位 將H(-m)移位n,即得H(n-m)。當n爲正整數時,右移n位。當n爲負整數時,左移n位。
C) 相乘 再將H(n-m)和X(m)的相同m值的對應點值相乘。
D) 相加 把以上所有點的對應點的乘積疊加起來,即得Y(n)值。
依上法,取n=……,-2,-1,0,1,2,3,……各值,即可得全部Y(n)值。

設計總框圖
這裏寫圖片描述

當程序成功運行通過後,通過仿真器(XDS510或者XDS560)與目標板連接,安裝仿真器驅動,然後load program到目標板,運行,利用仿真器提供的RTDX可實時查看存儲器和寄存器變化。

程序流程圖
這裏寫圖片描述

程序中函數
processing1(int *input2, int *output2)
調用形式:processing1(int *input2, int *output2)
參數解釋:intput2、output2爲兩個整型指針數組。
返回值解釋:返回了一個“TREN”,讓主函數的while循環保持連續。
功能說明:對輸入的input2 buffer波形進行截取m點,再以零點的Y軸爲對稱軸進行翻褶,把生成的波形上的各點的值存入以OUTPUT2指針開始的一段地址空間中。
processing2(int *output2, int *output3)
調用形式:processing2(int *output2, int *output3)
參數解釋:output2、output3爲兩個整型指針數組。
返回值解釋:返回了一個“TREN”,讓主函數的while循環保持連續。
功能說明:對輸出的output2 buffer波形進行作n點移位,然後把生成的波形上的各點的值存入以OUTPUT3指針開始的一段地址空間中。
processing3(int *input1,int *output2,int *output4)
調用形式:processing3(int *input1,int *output2,int *output4)
參數解釋:output2、output4、input1爲三個整型指針數組。
返回值解釋:返回了一個“TREN”,讓主函數的while循環保持連續。
功能說明:對輸入的input2 buffer波形和輸入的input1 buffer作卷積和運算,然後把生成的波形上的各點的值存入以OUTPUT4指針開始的一段地址空間中。
processing4(int *input2,int *output1)
調用形式:processing4(int *input2,int *output1)
參數解釋:output1、input2爲兩個整型指針數組。
返回值解釋:返回了一個“TREN”,讓主函數的while循環保持連續。
功能說明:對輸入的input2 buffer波形截取m點,然後把生成的波形上的各點的值存入以OUTPUT1指針開始的一段地址空間中。

程序代碼

#include <stdio.h>
#include "volume.h"
int in1_buffer[BUFSIZE];
int in2_buffer[BUFSIZE];       
int out1_buffer[BUFSIZE];
int out2_buffer[BUFSIZE];
int out3_buffer[BUFSIZE];
int out4_buffer[BUFSIZE*2];
int size = BUFSIZE;
int ain = MINGAIN;
int zhy=0;
int sk=64;        
/* Functions */
static int step1(int *output1, int *output2);
static int step2(int *output2, int *output3); 
static int step3(int *input1,int *output2,int *output4);
static int step4(int *input2, int *output1);
static void dataIO1(void);
static void dataIO2(void);
void main()
{
    int *input1 = &in1_buffer[0];
    int *input2 = &in2_buffer[0];
    int *output1 = &out1_buffer[0];
    int *output2 = &out2_buffer[0];
    int *output3 = &out3_buffer[0];
    int *output4 = &out4_buffer[0];
    puts("volume example started\n");
    while(TRUE)
    {       
        /* 
         *  Read input data using a probe-point connected to a host file. 
         *  Write output data to a graph connected through a probe-point.
         */

        dataIO1();  // break point
        dataIO2();  // break point
        step4(input2,output1);
        step1(output1, output2); 
        step2(output2, output3);
        step3(input1,output2,output4) ;
    }
}

static int step4(int *input2,int *output1)
{
    int m=sk;
    for(;m>=0;m--)
    {
        *output1++ = *input2++ * ain;
    }
    for(;(size-m)>0;m++)
    {
        output1[m]=0;
    }
    return(TRUE);
}

static int step1(int *output1,int *output2)
{  
    int m=sk-1;  
    for(;m>0;m--)
    {
        *output2++ = *output1++ * ain;
    }
    return(TRUE);
}

static int step2(int *output2, int *output3)
{   
    int n=zhy;   
    size=BUFSIZE; 
    for(;(size-n)>0;n++)
    { 
        *output3++ = output2[n];
    }
    return(TRUE);
}

static int step3(int *input1,int *output2,int *output4)
{   
    int m=sk;
    int y=zhy;
    int z,x,w,i,f,g;
    for(;(m-y)>0;)
    {
        i=y;
        x=0;
        z=0;
        f=y;
        for(;i>=0;i--)
        {
            g=input1[z]*output2[f];
            x=x+g;
            z++;
            f--;
        }
        *output4++ = x;
        y++;
    }
    m=sk;
    y=sk-1;
    w=m-zhy-1;
    for(;m>0;m--)
    {
        y--;
        i=y;
        z=sk-1;
        x=0;
        f=sk-y;
        for(;i>0;i--,z--,f++)
        {
           g=input1[z]*output2[f];
           x=x+g;    
        }
        out4_buffer[w]=x;
        w++;
    }
    return(TRUE);
}  

static void dataIO1()
{
    /* do data I/O */
    return;
}
static void dataIO2()
{
    /* do data I/O */
    return;
}
發佈了67 篇原創文章 · 獲贊 11 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章