楼主: Lisrelchen
5447 53

Real-Time Digital Signal Processing, 2nd Edition [推广有奖]

51
Lisrelchen(未真实交易用户) 发表于 2016-3-13 08:04:35
  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
复制代码

52
Lisrelchen(未真实交易用户) 发表于 2016-3-13 08:07:04
  1. %
  2. % example3_7.m - MATLAB file for designing FIR filter using
  3. %                the Fourier series method
  4. %

  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. omegac = 0.4*pi; % Cutoff frequency
  10. L = 61;                     % Filter order L = 61
  11. M = (L-1)/2;     % M
  12. l = 0:2*M;       % Coefficient index l
  13. h = omegac/pi*sinc(omegac*(l-M)/pi);  % Compute coefficients
  14. omega = -pi:2*pi/200:pi;     % Frequency range
  15. Hd = freqz(h,1,omega);       % Frequency response
  16. plot((omega/pi),abs(Hd)),... % Use normalized frequency
  17.     xlabel('Normalized frequency'), ylabel('Magnitude'), grid;
  18. axis([-1 1 0 1.2]);
复制代码

53
Lisrelchen(未真实交易用户) 发表于 2016-3-13 08:07:43
  1. %
  2. % example3_8.m - Ploting magnitude responses of rectangular
  3. %                windows
  4. %

  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. M = 8;                     % M = 8 (First window)
  10. L = 2*M+1;                 % Window length
  11. wn = [ones(1,L)];          % Fectangular window
  12. omega = -pi:2*pi/200:pi;   % Frequency range
  13. Hd = freqz(wn,1,omega);    % Frequency response
  14. mag = 20*log10(abs(Hd));   % Log scale

  15. M1 = 20;                   % M = 20 (Second window)
  16. L1 = 2*M1+1;               % Window length
  17. wn1 = [ones(1,L1)];        % Rectangular window
  18. omega = -pi:2*pi/200:pi;   % Frequency range
  19. Hd1 = freqz(wn1,1,omega);  % Frequency response
  20. mag1 = 20*log10(abs(Hd1)); % Log scale

  21. subplot(2,1,1), plot((omega/pi),mag), ...
  22.     xlabel('Normalized frequency'), ylabel('Magnitude(dB)'), grid;
  23. axis([-1 1 -40 40]);
  24. subplot(2,1,2), plot((omega/pi),mag1), ...
  25.     xlabel('Normalized frequency'), ylabel('Magnitude(dB)'), grid;
  26. axis([-1 1 -40 40]);
复制代码

54
Lisrelchen(未真实交易用户) 发表于 2016-3-13 08:08:26
  1. %
  2. % example3_9.m - Designing FIR filter using Hamming window
  3. %

  4. % For the book "Real Time Digital Signal Processing:
  5. %               Fundamentals, Implementation and Application, 3rd Ed"
  6. %               By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
  7. %               Publisher: John Wiley and Sons, Ltd

  8. omegac = 0.4*pi; % Cutoff frequency
  9. L = 61;          % Filter order L = 61
  10. M = (L-1)/2;     % M
  11. l = 0:2*M;       % Coefficient index l
  12. h = omegac/pi*sinc(omegac*(l-M)/pi);  % Compute coefficients
  13. wn = 0.54 -0.46*cos(2*pi*l/(L-1));    % Hamming window
  14. hwn = h.*wn;     % Windowing
  15. omega = -pi:2*pi/200:pi;   % Frequency range
  16. Hr = freqz(h,1,omega);     % Frequency response-Rectangular
  17. Hd = freqz(hwn,1,omega);   % Frequency response-Hamming  
  18. plot((omega/pi),abs(Hr),':r',(omega/pi),abs(Hd),'-b');
  19. xlabel('Normalized frequency'), ylabel('Magnitude'), grid;
  20. legend('Rectangular window','Hamming window')
  21. axis([-1 1 0 1.2]);
复制代码

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-25 06:22