找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3680|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

MATLAB數(shù)字濾波器程序 Hamming窗帶通濾波器

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:679278 發(fā)表于 2020-1-2 00:48 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式

Hamming窗帶通濾波器

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

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窗帶通時(shí)域圖');

subplot(2,1,2);plot(w1,abs(h1));title('hamming窗帶通頻譜圖');axis tight;xlabel('f/Hz');ylabel('耗損(dB)');

pause(1);

%對(duì)濾波后的信號(hào)進(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('濾波后的信號(hào)時(shí)域圖');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('濾波后的信號(hào)頻譜');

sound(X,FS);

圖1  語(yǔ)音信號(hào)

圖2  加噪信號(hào)

圖3  濾波信號(hào)

Hamming窗帶通濾波器程序


  1. %hamming帶通

  2. %產(chǎn)生語(yǔ)音信號(hào)

  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;%計(jì)算音頻信號(hào)的長(zhǎng)度

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

  13. figure(1);

  14. subplot(2,1,1); plot(t,x); axis tight; title('語(yǔ)音信號(hào)時(shí)域圖'); xlabel('t/s');ylabel('幅度')

  15. y=fft(x,n);          %對(duì)n點(diǎn)進(jìn)行傅里葉變換到頻域

  16. f=FS*(0:n/2-1)/n;             % 對(duì)應(yīng)點(diǎn)的頻率

  17. subplot(2,1,2);

  18. plot(f,abs(y(1:n/2)));axis tight;xlabel('f/Hz');ylabel('幅度');title('語(yǔ)音信號(hào)頻域圖');

  19. pause(2.5);

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

  21. %產(chǎn)生噪聲信號(hào)

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

  23. Noise=fft(noise,n);%對(duì)n點(diǎn)進(jìn)行傅里葉變換到頻域

  24. figure(2);

  25. subplot(2,1,1);plot(t,noise);axis tight;xlabel('t/s');ylabel('幅度');title('加噪聲信號(hào)時(shí)域圖');

  26. subplot(2,1,2)

  27. plot(f,abs(Noise(1:n/2)));     %加噪語(yǔ)音信號(hào)的頻譜圖

  28. axis axis([1 40000 1 50000] );xlabel('f/Hz');ylabel('幅度');title('加噪語(yǔ)音信號(hào)頻譜圖');

  29. pause(1);

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

  31. x1=x+noise';  %將兩個(gè)信號(hào)疊加成一個(gè)新的信號(hào)——加噪聲處理

  32. sound(x1,FS);

  33. %加噪后頻譜分析

  34. noise_1=fft(x1,n);%對(duì)n點(diǎn)進(jìn)行傅里葉變換到頻域

  35. figure(3);

  36. subplot(2,1,1)

  37. plot(t,x1);axis tight;xlabel('t/s');ylabel('幅度');title('加噪聲信號(hào)時(shí)域圖');

  38. subplot(2,1,2)

  39. plot(f,abs(noise_1(1:n/2)));     %加噪語(yǔ)音信號(hào)的頻譜圖

  40. axis ([1 30000 1 4000] ;xlabel('f/Hz');ylabel('幅度');title('加噪語(yǔ)音信號(hào)頻譜圖');

  41. pause(2.5);

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

  43. %hamming窗帶通濾波器設(shè)計(jì)

  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窗帶通時(shí)域圖');

  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. %對(duì)濾波后的信號(hào)進(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('濾波后的信號(hào)時(shí)域圖');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('濾波后的信號(hào)頻譜');

  66. sound(X,FS);
復(fù)制代碼

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

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表