標(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窗帶通濾波器程序
- %hamming帶通
- %產(chǎn)生語音信號
- clc;
- Fs=48000;
- [x,FS]=audioread('C:\Users\SDHH\Documents\錄音\luyin.m4a');
- x=x(:,1);
- sound(x,FS);
- %頻譜分析
- n=length(x);
- n=2^nextpow2(n); %選取變換的點(diǎn)數(shù)
- t=(0:(n-1))/FS;%計算音頻信號的長度
- x=[x',zeros(1,n-length(x))]';
- figure(1);
- subplot(2,1,1); plot(t,x); axis tight; title('語音信號時域圖'); xlabel('t/s');ylabel('幅度')
- y=fft(x,n); %對n點(diǎn)進(jìn)行傅里葉變換到頻域
- f=FS*(0:n/2-1)/n; % 對應(yīng)點(diǎn)的頻率
- subplot(2,1,2);
- plot(f,abs(y(1:n/2)));axis tight;xlabel('f/Hz');ylabel('幅度');title('語音信號頻域圖');
- pause(2.5);
- %###########################################################################################################
- %產(chǎn)生噪聲信號
- noise=1*sin(2*pi*20000*t)+1*sin(2*pi*200*t);
- Noise=fft(noise,n);%對n點(diǎn)進(jìn)行傅里葉變換到頻域
- figure(2);
- subplot(2,1,1);plot(t,noise);axis tight;xlabel('t/s');ylabel('幅度');title('加噪聲信號時域圖');
- subplot(2,1,2)
- plot(f,abs(Noise(1:n/2))); %加噪語音信號的頻譜圖
- axis axis([1 40000 1 50000] );xlabel('f/Hz');ylabel('幅度');title('加噪語音信號頻譜圖');
- pause(1);
- %#############################################################################################################
- x1=x+noise'; %將兩個信號疊加成一個新的信號——加噪聲處理
- sound(x1,FS);
- %加噪后頻譜分析
- noise_1=fft(x1,n);%對n點(diǎn)進(jìn)行傅里葉變換到頻域
- figure(3);
- subplot(2,1,1)
- plot(t,x1);axis tight;xlabel('t/s');ylabel('幅度');title('加噪聲信號時域圖');
- subplot(2,1,2)
- plot(f,abs(noise_1(1:n/2))); %加噪語音信號的頻譜圖
- axis ([1 30000 1 4000] ;xlabel('f/Hz');ylabel('幅度');title('加噪語音信號頻譜圖');
- pause(2.5);
- %#################################################################################################################
- %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 tight;xlabel('n');ylabel('幅度');title('hamming窗帶通時域圖');
- subplot(2,1,2);plot(w1,abs(h1));title('hamming窗帶通頻譜圖');axis ([700 900 -0.5 1]);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);
復(fù)制代碼
完整的Word格式文檔51黑下載地址:
Hamming窗帶通濾波器.docx
(82.7 KB, 下載次數(shù): 20)
2020-1-2 00:46 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |