⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 experiment-1.cpp

📁 dsp 信号处理中的 生成离散信号并计算其振幅谱
💻 CPP
字号:
#include"math.h"
#include"stdio.h"
#include"stdlib.h"
void signal(float *h, float f, float dt, float m, int N);
extern void Spectrum(float *x, float *Amp, int N);
extern void DFT(float *x, float *Xr, float *Xi, int N, float s);
extern void output_h(float *x, float T, int N);
extern void output_S(float *Xamp, float T, int N);
extern void output_h_calculation(float *x, float T, int N);


/////////////////////////////////////////////////////////////
//                          试验-1                         //
//---------------------------------------------------------//
//        任务-1:  生成离散信号并计算其振幅谱             //
//                                                         //
//  1.  在函数void signal()中, 编写生成离散信号的程序片断;//
//                                                         //
//  2.  运行程序,输出结果(数据文件data-?ms.dat),        //
//      分别计算0.004s,  0.009s,  0.011s采样的结果;       //
//                                                         //
//  3.  用Excel软件绘图显示计算结果。                      //
//                                                         //
//  4.  分析不同采样间隔对的离散信号振幅谱的影响           //
//                                                         //
//---------------------------------------------------------//
//                                                  //
//             任务-2:  序列的运算                 //
//                                                  //
//  1.  计算序列h(-n)。                             //
//                                                  //
//  2.  计算序列h(n)+h(-n)和h(n)+h(-n)。            // 
//                                                  //
//////////////////////////////////////////////////////


void main()
{
    float h[128], Xamp[128],
		  deltat, M, f;
	int   N, i;

    deltat=float(0.011);  // 时域采样间隔(sec)
	                      // 分别计算0.004s,  0.009s,  0.011s采样的结果

    N=32;           // 数据长度(点数)
	f=35;           // 信号的频率
	M=float(1.5);   // 波形参数
	for(i=0; i<N; i++)	{  h[i]=0; }

//----------------------------------------//
//             生成离散信号 h(n)          //
//----------------------------------------//
    signal(h, f, deltat, M, N);    //  调用函数signal形成离散信号h(n)

    output_h(h, deltat, N);        //  输出离散信号h(n)
//----------------------------------------//
//      计算信号 h(n) 的振幅谱 |X(k)|     //
//----------------------------------------//
    Spectrum(h, Xamp,N);

//----------------------------------------//
//           输出振幅谱 |X(k)|            //
//----------------------------------------//
    output_S(Xamp, deltat, N);     //  输出振幅谱 Xamp(k)


//####################################################//
//----------------------------------------------------//
//       在此处编写计算程序语句,完成任务-2 !!!       //
//----------------------------------------------------//
//####################################################//
float h1[64],h2[64],h3[64],h4[64];
 
 int j=0;
 int k=0;
  for(j=0;j<N;j++)
	 { h1[j]=0;
       h2[j]=0;
	   h3[j]=0;
  h1[31+j]=h[j];
  h2[31-j]=h1[31+j];}
  for(k=0;k<64;k++)
  {h3[k]=h1[k]+h2[k];
  h4[k]=h1[k]-h2[k];}

   

   output_h_calculation(h3, 1, 2*N);  // 
   output_h_calculation(h4, 1, 2*N);  // 





   output_h_calculation(h2, 1, 2*N);  // 输出计算结果1
  // output_h_calculation(h1, 2, 2*N);  // 输出计算结果2

    printf("  End of caculating !!\n\n");
}

//------------------------------------------//
//             生成离散信号 x(n)            //
//------------------------------------------//
void signal(float *h, float f, float dt, float m, int N)
{
  int i=0;
  double pi=3.1415926;
  float a;
     a=2*f*f*log( m);
	  for(i=0;i<N;i++)
	  {h[i]= exp( (-1)*a*(i*dt)*(i*dt))*sin( 2*pi*f*i*dt);}

//####################################################//
//----------------------------------------------------//
//  离散抽样:  在此处编写计算离散信号h(n)的语句 !!!   //
//----------------------------------------------------//
//####################################################//




}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -