• 数字信号处理(MATLAB入门例子)


    (代码主要来源于这本书)

    1.用MATLAB产生32个正弦波样本,A=2,f=1000Hz,以及fs=8000Hz

    1. %
    2. % Example 2.1 Sinewave generator
    3. % This example generate 32 sine sample,
    4. % plot it and save in sine.dat file
    5. % For the book "Real Time Digital Signal Processing:
    6. % Fundamentals, Implementation and Application, 3rd Ed"
    7. % By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
    8. % Publisher: John Wiley and Sons, Ltd
    9. n = [0:31]; % Time index n
    10. omega = 0.25*pi; % Digital frequency
    11. xn = 2*sin(omega*n); % Sinewave generation
    12. plot(n, xn, '-o'); % Samples are marked by 'o'
    13. xlabel('Time index, n');
    14. ylabel('Amplitude');
    15. axis([0 31 -2 2]); % Define ranges of plot
    16. save sine.dat xn -ascii;% Save in ASCII data file

    例2:绘制传递函数的零极点图:

    1. % Example 2.11a Mgnitude and phase response of an IIR filter
    2. % This example plots magnitude and phase response of an IIR filter
    3. % For the book "Real Time Digital Signal Processing:
    4. % Fundamentals, Implementation and Application, 3rd Ed"
    5. % By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
    6. % Publisher: John Wiley and Sons, Ltd
    7. b=[1]; % Define numerator
    8. a=[1, -1, 0.9]; % Denominator
    9. zplane(b,a); % Pole-zero plot

    例3:正弦波A=1,f=1000Hz,采样率为 10 000Hz,可以产生100个正弦波采样样本。信号的幅度谱可以采用以下MATLAB程序绘制:

    1. % example2_16.m - Compute and plot amplitude spectrum of sinewave
    2. %
    3. % For the book "Real Time Digital Signal Processing:
    4. % Fundamentals, Implementation and Application, 3rd Ed"
    5. % By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
    6. % Publisher: John Wiley and Sons, Ltd
    7. N=100; f = 1000; fs = 10000; % Define parameter values
    8. n=[0:N-1]; k=[0:N-1]; % Define time and frequency indices
    9. omega=2*pi*f/fs; % Frequency of sinewave
    10. xn=sin(omega*n); % Generate sinewave
    11. Xk=fft(xn,N); % Perform DFT
    12. magXk=20*log10(abs(Xk)); % Compute magnitude spectrum
    13. plot(k, magXk); axis([0, N/2, -inf, inf]); % plot from 0 to pi
    14. xlabel('Frequency index, k');
    15. ylabel('Magnitude (dB)');

    例4:绘制下面这个传递函数的幅度响应和相位响应

    1. % For the book "Real Time Digital Signal Processing:
    2. % Fundamentals,Implementation and Application, 3rd Ed"
    3. % By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
    4. % Publisher: John Wiley and Sons, Ltd
    5. b=[1, 0, 0, 0, 0, 0, 0, 0, -1]; % Numerator
    6. a=[1, -1]; % Denominator
    7. freqz(b,a); % Plot frequency response

    例5:本例产生中的一个包含噪声的正弦波信号,其中噪声是零均值、单位方差白噪声所示。

    1. N=256; A=sqrt(2); w0=0.2*pi; % Define parameters
    2. n = [0:N-1]; % Time index
    3. sn = A*sin(w0*n); % Sine sequence
    4. sd = 12357; % Define seed value
    5. rng(sd); % Use defined seed
    6. vn = (rand(1,N)-0.5)*sqrt(12); % Zero-mean, unit-variance white noise
    7. xn = sn+vn; % Sinewave embedded in white noise
    8. plot(n,xn);
    9. save xn.dat xn -ascii ;

  • 相关阅读:
    umi4 React项目使用icon集合
    论文阅读:Explainability for Large Language Models: A Survey
    计算机毕业设计Java酒店预约及管理系统(源码+系统+mysql数据库+lw文档)
    华为od 面试题及流程 (前后端)
    计算机网络---第四章网络层
    三维模型相机视角投影详细介绍及python程序解析
    bug:Junit5报错,@SpringBootTest没有运行
    【SQL】SQLAlchemy:如何使用Python ORM框架来操作MySQL?
    【鸟哥杂谈】十分钟使用命令行在云服务器Centos环境下搭建NodeJS环境
    SpringMVC异常处理器
  • 原文地址:https://blog.csdn.net/z754721/article/details/138199062