DSP算法作业源程序 下载本文

内容发布更新时间 : 2024/11/5 23:25:04星期一 下面是文章的全部内容请认真阅读。

DSP算法作业源程序

S06102112 谢宏 计算机科学与技术四班

一、 c语言程序myFirMain.c

/*将两个不同频率叠加的正弦余弦信号进行FIR滤波,得到频率较低的正弦信号*/ /*滤波器系数用matlab计算 */ #include \#include \

static void dataIO(); /*提供软件中断*/

void FIR(float input[],float output[],int SIZE);/*滤波核心函数*/ float coffi[21]={

0.000478595791017,0.000726931684122,-0.003065643310532, -0.005972516207952,0.009162581410507,0.024305842109567, -0.018305853075952,-0.076072756598977,0.026970528950393, 0.306965272918299,0.469427460783227,0.306965272918299, 0.026970528950393,-0.076072756598977,-0.018305853075952, 0.024305842109567,0.009162581410507,-0.005972516207952, -0.0030656643310532,0.000726931864122,0.000478595791017 };/*滤波器系数*/

float input[256];/*输入数据,使用库函数计算正余弦叠加信号*/ float output[256];/*经过fir滤波的输出数据*/ main() {

int i;

/*计算输入信号*/

/*正弦频率1000,余弦频率2500*/ for(i = 0;i <= 255;i ++) {

input[i]=(sin(2*3.14159235*i*1000/8000)+cos(2*3.14159265*i*2500/8000))/4; output[i]=0; }

FIR(input,output,256); /*滤波*/ while(1) {

dataIO(); /*此处加入软件中断,用以观察图形*/ } }

/*函数:FIR

作用:将输入滤波写入到输出信号中 输入:输入信号,输出信号,变量维数 返回:无*/

/*滤波公式:y(n)=coff[0]*x(n-0)+coff[1]*x(n-1)+.....+coff[N]*x(n-N)*/ /*此时N为20,n为255*/

void FIR(float input[],float output[],int SIZE)

{

int i,j;

for(i=0;i

output[i]+=coffi[j]*input[i-j];

puts(\}

static void dataIO() {

return ; }

二、 链接文件lnk.cmd

/*直接使用原有的lnk.cmd作为链接文件*/ /*未作改动*/

-stack 0x800 /* size of .stack section */ -heap 0x800 /* size of .sysmem section */ MEMORY {

PAGE 0: /* program memory */

PROG_RAM (RWX) : origin = 0x1400, length = 0x6C00 PROG_EXT (RWX) : origin = 0x8000, length = 0x4000 VECTORS (RWX): origin = 0xFF80, length = 0x80

PAGE 1: /* data memory, addresses 0-7Fh are reserved */ DATA_RAM (RW): origin = 0x1400, length = 0x6C00 DATA_EXT (RW): origin = 0x8000, length = 0x7FFF PAGE 2: /* I/O memory */ } /* MEMORY */ SECTIONS {

.text >> PROG_RAM | PROG_EXT PAGE 0

.vectors > VECTORS PAGE 0 /* interrupt vectors */ .cio > DATA_RAM PAGE 1 /* C I/O */

.data >> DATA_RAM | DATA_EXT PAGE 1 /* initialized data */ .bss >> DATA_RAM | DATA_EXT PAGE 1 /* global & static variables */ .const > DATA_RAM PAGE 1 /* constant data */ .sysmem >>DATA_RAM | DATA_EXT PAGE 1 /* heap */

.stack >> DATA_RAM | DATA_EXT PAGE 1 /* stack */ } /* SECTIONS */