标题: MATLAB数字滤波器程序 Hamming窗带通滤波器 [打印本页]

作者: 小许家的猪    时间: 2020-1-2 00:48
标题: MATLAB数字滤波器程序 Hamming窗带通滤波器

Hamming窗带通滤波器

%Hamming窗带通滤波器的设计

fp1=200;fc1=100;

fpu=8000;fcu=10000;

wlp=2*pi*fp1/FS;wls=2*pi*fc1/FS;

wup=2*pi*fpu/FS;wus=2*pi*fcu/FS;

Bt=wlp-wls;            

N0=ceil(6.6*pi/Bt);

N=N0+mod(N0+1,2);

wc=[(wls+wlp)/2/pi,(wus+wup)/2/pi];   

hn=fir1(N-1,wc,hamming(N));

[h1,w1] = freqz(hn,1,512,FS);

figure(4);

subplot(2,1,1);plot(hn);axis ([700 900 -0.5 1]);xlabel('n');ylabel('幅度');title('hamming窗带通时域图');

subplot(2,1,2);plot(w1,abs(h1));title('hamming窗带通频谱图');axis tight;xlabel('f/Hz');ylabel('耗损(dB)');

pause(1);

%对滤波后的信号进行分析变换

X=conv(hn,x);

n2=length(X);      

n2=2^nextpow2(n2);

f=FS*(0:n2/2-1)/n2;  

figure(5);subplot(2,1,1);plot(X);title('滤波后的信号时域图');axis tight;xlabel('f/Hz');ylabel('幅度');

X1=fft(X,n2);subplot(2,1,2);plot(f,abs(X1(1:n2/2))); axis tight;xlabel('f/Hz');ylabel('幅度');title('滤波后的信号频谱');

sound(X,FS);

图1  语音信号

图2  加噪信号

图3  滤波信号

Hamming窗带通滤波器程序


  1. %hamming带通

  2. %产生语音信号

  3. clc;

  4. Fs=48000;

  5. [x,FS]=audioread('C:\Users\SDHH\Documents\录音\luyin.m4a');

  6. x=x(:,1);

  7. sound(x,FS);

  8. %频谱分析

  9. n=length(x);      

  10. n=2^nextpow2(n); %选取变换的点数

  11. t=(0:(n-1))/FS;%计算音频信号的长度

  12. x=[x',zeros(1,n-length(x))]';

  13. figure(1);

  14. subplot(2,1,1); plot(t,x); axis tight; title('语音信号时域图'); xlabel('t/s');ylabel('幅度')

  15. y=fft(x,n);          %对n点进行傅里叶变换到频域

  16. f=FS*(0:n/2-1)/n;             % 对应点的频率

  17. subplot(2,1,2);

  18. plot(f,abs(y(1:n/2)));axis tight;xlabel('f/Hz');ylabel('幅度');title('语音信号频域图');

  19. pause(2.5);

  20. %###########################################################################################################

  21. %产生噪声信号

  22. noise=1*sin(2*pi*20000*t)+1*sin(2*pi*200*t);

  23. Noise=fft(noise,n);%对n点进行傅里叶变换到频域

  24. figure(2);

  25. subplot(2,1,1);plot(t,noise);axis tight;xlabel('t/s');ylabel('幅度');title('加噪声信号时域图');

  26. subplot(2,1,2)

  27. plot(f,abs(Noise(1:n/2)));     %加噪语音信号的频谱图

  28. axis axis([1 40000 1 50000] );xlabel('f/Hz');ylabel('幅度');title('加噪语音信号频谱图');

  29. pause(1);

  30. %#############################################################################################################

  31. x1=x+noise';  %将两个信号叠加成一个新的信号——加噪声处理

  32. sound(x1,FS);

  33. %加噪后频谱分析

  34. noise_1=fft(x1,n);%对n点进行傅里叶变换到频域

  35. figure(3);

  36. subplot(2,1,1)

  37. plot(t,x1);axis tight;xlabel('t/s');ylabel('幅度');title('加噪声信号时域图');

  38. subplot(2,1,2)

  39. plot(f,abs(noise_1(1:n/2)));     %加噪语音信号的频谱图

  40. axis ([1 30000 1 4000] ;xlabel('f/Hz');ylabel('幅度');title('加噪语音信号频谱图');

  41. pause(2.5);

  42. %#################################################################################################################

  43. %hamming窗带通滤波器设计

  44. fp1=200;fc1=100;

  45. fpu=8000;fcu=10000;

  46. wlp=2*pi*fp1/FS;wls=2*pi*fc1/FS;

  47. wup=2*pi*fpu/FS;wus=2*pi*fcu/FS;

  48. Bt=wlp-wls;            

  49. N0=ceil(6.6*pi/Bt);

  50. N=N0+mod(N0+1,2);

  51. wc=[(wls+wlp)/2/pi,(wus+wup)/2/pi];   

  52. hn=fir1(N-1,wc,hamming(N));

  53. [h1,w1] = freqz(hn,1,512,FS);

  54. figure(4);

  55. subplot(2,1,1);plot(hn);axis tight;xlabel('n');ylabel('幅度');title('hamming窗带通时域图');

  56. subplot(2,1,2);plot(w1,abs(h1));title('hamming窗带通频谱图');axis ([700 900 -0.5 1]);xlabel('f/Hz');ylabel('耗损(dB)');

  57. pause(1);

  58. %#################################################################################################################

  59. %对滤波后的信号进行分析变换

  60. X=conv(hn,x);

  61. n2=length(X);      

  62. n2=2^nextpow2(n2);

  63. f=FS*(0:n2/2-1)/n2;  

  64. figure(5);subplot(2,1,1);plot(X);title('滤波后的信号时域图');axis tight;xlabel('f/Hz');ylabel('幅度');

  65. X1=fft(X,n2);subplot(2,1,2);plot(f,abs(X1(1:n2/2))); axis tight;xlabel('f/Hz');ylabel('幅度');title('滤波后的信号频谱');

  66. sound(X,FS);
复制代码

完整的Word格式文档51黑下载地址:
Hamming窗带通滤波器.docx (82.7 KB, 下载次数: 20)






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1