与dsp有关的算法整理.doc_第1页
与dsp有关的算法整理.doc_第2页
与dsp有关的算法整理.doc_第3页
与dsp有关的算法整理.doc_第4页
与dsp有关的算法整理.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1卷积:#include #include volume.h/* Global declarations */int inp1_bufferBUFSIZE;int inp2_bufferBUFSIZE; /* processing data buffers */int out1_bufferBUFSIZE;int out2_bufferBUFSIZE;int out3_bufferBUFSIZE;int out4_bufferBUFSIZE*2;int size = BUFSIZE;int ain = MINGAIN;int zhy=0;int sk=64; /*sk代表所开的bufsize的大小,需修改它.输入文件sine.dat为32点,sine11.dat, sin22.dat,sin33.dat,sin44.dat为64点的输入波形.*/ /* volume control variable */unsigned int processingload = 1; /* processing routine /load value */* Functions */extern void load(unsigned int loadValue);static int processing1(int *output1, int *output2);static int processing2(int *output2, int *output3); static int processing3(int *input1,int *output2,int *output4);static int processing4(int *input2, int *output1);static void dataIO1(void);static void dataIO2(void);/* * = main = */void main() int *input1 = &inp1_buffer0; int *input2 = &inp2_buffer0; int *output1 = &out1_buffer0; int *output2 = &out2_buffer0; int *output3 = &out3_buffer0; int *output4 = &out4_buffer0; puts(volume example startedn); /* loop forever */ 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(); dataIO2(); /* apply gain */ processing4(input2,output1); processing1(output1, output2); processing2(output2, output3); processing3(input1,output2,output4) ; /* * = processing = * * FUNCTION: apply signal processing transform to input signal. * * PARAMETERS: address of input and output buffers. * * RETURN VALUE: TRUE. */static int processing4(int *input2,int *output1) int m=sk; for(;m=0;m-) *output1+ = *input2+ * ain; for(;(size-m)0;m+) output1m=0; /load(processingload); return(TRUE); static int processing1(int *output1,int *output2) int m=sk-1; for(;m0;m-) *output2+ = *output1+ * ain; /* additional processing /load */ /load(processingload); return(TRUE);static int processing2(int *output2, int *output3) int n=zhy; size=BUFSIZE; for(;(size-n)0;n+) *output3+ = output2n; /* for (;n0;n-) *output3+ = 0; */ /load(processingload); return(TRUE); static int processing3(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=input1z*output2f; x=x+g; z+; f-; *output4+ = x; y+; m=sk; y=sk-1; w=m-zhy-1; for(;m0;m-) y-; i=y; z=sk-1; x=0; f=sk-y; for(;i0;i-,z-,f+) g=input1z*output2f; x=x+g; out4_bufferw=x; w+; /load(processingload); return(TRUE); /* * = dataIO = * * FUNCTION: read input signal and write processed output signal. * * PARAMETERS: none. * * RETURN VALUE: none. */static void dataIO1() /* do data I/O */ return;static void dataIO2() /* do data I/O */ return;2排序选择:程序如下,但是这个题目有些问题,随机产生10000个100之内的整数,根据概率来看至少有100个左右的100,所以输出前10个最大值基本上100%的可能都是100,你要是不放心,可以将我下面的程序里面的k改成10000看一下实际效果:#include #include #include #include #define N 10000void SelectSort ( int array, int n ) int nMinIndex; int nIndex_1, nIndex_2; for (nIndex_1 = 0;nIndex_1 n - 1 ;nIndex_1+) nMinIndex = nIndex_1; for (nIndex_2 = nIndex_1 + 1 ; nIndex_2 arraynIndex_2 ) nMinIndex = nIndex_2; if ( nMinIndex != nIndex_1 ) int temp = arraynIndex_1; arraynIndex_1 = arraynMinIndex; arraynMinIndex = temp ; void ShowArray(int array, int k) int i; for (i = 0; i k; i+) printf(%dt, arrayi); if (i+1)%10 = 0) printf(n); printf(n);int main() int arrayN = 0;int k=10,i; srand(unsigned) time(NULL); for(i=0;iN;i+)arrayi=rand()%100+1; SelectSort(array, N); printf(Sorted Array:n); ShowArray(array, k); system(pause);return 0;3冒泡:void sort(int p,int n) int i,j,temp; for(i=0;in-1;i+) for(j=i+1;jpj) temp=pi; pi=pj; pj=temp; 4差分方程法一:用C语言画差分方程 C(K2)1025C(K1)04733C(K)02385R(K1)02089R(K)图象k=0时 r(k)=1初试条件c(0)=,c(1)=0.238#include #include #define N 100main() int i; double cN+1; FILE *fp; fp=fopen(d:zhidao.txt,w); if (!fp) printf(File Open ERROR:nPress any to exit:); getch(); exit(1); c0=0; c1=0.238; fprintf(fp,0t%gn,c0); fprintf(fp,1t%gn,c1); for (i=2;i y1=sqh(20,0.0194); y2=sqh(20,-0.0324); y3=sqh(20,-0.0382); round(k,y1,y2,y3)利用plot 绘图观察数量变化趋势 可以用不同线型和颜色绘图 r g b c m y k w 分别表示 红绿兰兰绿洋红黄黑白色: + o * . X s d 表示不同的线型 plot(k,y1,k,y2,k,y3) 在同一坐标系下画图plot(k,y2,:) plot(k,y2,-) plot(k,y2,r) plot(k,y2,y) plot(k,y2,y,k,y1,:) plot(k,y2,k,y1,:) plot(k,y2,oy,k,y1,:)用gtext(r=0.0194),gtext(r=-0.0324),gtext(r=-0.0382)在图上做标记。 5功率谱的计算matlab1. Bartlett法Bartlett平均周期图的方法是将N点的有限长序列x(n)分段求周期图再平均。Matlab代码示例:clear;Fs=1000;n=0:1/Fs:1;xn=cos(2*pi*40*n)+3*cos(2*pi*100*n)+randn(size(n);nfft=1024;window=boxcar(length(n); %矩形窗noverlap=0; %数据无重叠p=0.9; %置信概率Pxx,Pxxc=psd(xn,nfft,Fs,window,noverlap,p);index=0:round(nfft/2-1);k=index*Fs/nfft;plot_Pxx=10*log10(Pxx(index+1);plot_Pxxc=10*log10(Pxxc(index+1);figure(1)plot(k,plot_Pxx);pause;figure(2)plot(k,plot_Pxx plot_Pxx-plot_Pxxc plot_Pxx+plot_Pxxc);2. Welch法Welch法对Bartlett法进行了两方面的修正,一是选择适当的窗函数w(n),并再周期图计算前直接加进去,加窗的优点是无论什么样的窗函数均可使谱估计非负。二是在分段时,可使各段之间有重叠,这样会使方差减小。Matlab代码示例:clear;Fs=1000;n=0:1/Fs:1;xn=cos(2*pi*40*n)+3*cos(2*pi*100*n)+randn(size(n);nfft=1024;window=boxcar(100); %矩形窗window1=hamming(100); %海明窗window2=blackman(100); %blackman窗noverlap=20; %数据无重叠range=half; %频率间隔为0 Fs/2,只计算一半的频率Pxx,f=pwelch(xn,window,noverlap,nfft,Fs,range);Pxx1,f=pwelch(xn,window1,noverlap,nfft,Fs,range);Pxx2,f=pwelch(xn,window2,noverlap,nfft,Fs,range);plot_Pxx=10*log10(Pxx);plot_Pxx1=10*log10(Pxx1);plot_Pxx2=10*log10(Pxx2);figure(1)plot(f,plot_Pxx);pause;figure(2)plot(f,plot_Pxx1);pause;figure(3)plot(f,plot_Pxx2);n=10;% 定义计算的点数c(1:n)=0;r(1:n)=1;k(1)=0;%定义输入输出和点数的初值for i=2:n c(i)=r(i)+0.5*c(i-1);k(i)=k(i-1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论