標(biāo)題: MATLAB數(shù)字濾波器程序 Hamming窗帶通濾波器 [打印本頁]

作者: 小許家的豬    時間: 2020-1-2 00:48
標(biāo)題: MATLAB數(shù)字濾波器程序 Hamming窗帶通濾波器

Hamming窗帶通濾波器

%Hamming窗帶通濾波器的設(shè)計

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);

%對濾波后的信號進(jìn)行分析變換

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. %產(chǎn)生語音信號

  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); %選取變換的點(diǎn)數(shù)

  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點(diǎn)進(jìn)行傅里葉變換到頻域

  16. f=FS*(0:n/2-1)/n;             % 對應(yīng)點(diǎ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. %產(chǎn)生噪聲信號

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

  23. Noise=fft(noise,n);%對n點(diǎn)進(jì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點(diǎn)進(jì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窗帶通濾波器設(shè)計

  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. %對濾波后的信號進(jìn)行分析變換

  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);
復(fù)制代碼

完整的Word格式文檔51黑下載地址:
Hamming窗帶通濾波器.docx (82.7 KB, 下載次數(shù): 20)






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1