⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fir_example_sub.m

📁 很多matlab的源代码
💻 M
字号:
switch get (b1 ,'Value')
case 1
subplot(1,1,1);
wp = 0.2*pi;
ws = 0.3*pi;
tr_width = ws - wp;
M = ceil(6.6*pi/tr_width)+1
n = [0:1:M-1];
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);
w_ham = (hamming(M))';
h = hd.*w_ham;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
Rp = -(min(db(1:1:wp/delta_w+1)))
As = -round(max(db(ws/delta_w+1:1:501)))
subplot(3,2,3);
stem(n,hd);
title('Ideal Impulse Response');
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,4);
stem(n,w_ham);
title('Hamming Window');
axis([0 M-1 0 1.1]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,5);
stem(n,h);
title('Magnitude Response in dB');
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('h(n)');
subplot(3,2,6);
plot(w/pi,db);
title('Magnitude Response in dB');grid
axis([0 1 -100 10]);
xlabel('frequency in pi units');
ylabel('Decibels')
case 2
subplot(1,1,1);
wp = 0.2*pi;
ws = 0.3*pi;
As = 50;
tr_width = ws - wp;
M = ceil((As-7.95)/(14.36*tr_width/(2*pi))+1)+1
n = [0:1:M-1] ;
beta = 0.1102*(As-8.7)
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);
w_kai = (kaiser(M,beta))';
h = hd.*w_kai;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
As = -round(max(db(ws/delta_w+1:1:501)))
subplot(3,2,3);
stem(n,hd);
title('Ideal Response');
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,4);
stem(n,w_kai);
title('Kaiser Window');
axis([0 M-1 0 1.1]);
xlabel('n');
ylabel('w(n)');
subplot(3,2,5);
stem(n,h);
title('Actual Impulse Response');
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('h(n)');
subplot(3,2,6);
plot(w/pi,db);
title('Magnitude Response');
axis([0 1 -100 10]);
xlabel('frequency in pi units');
ylabel('Decibels');
case 3
subplot(1,1,1);
ws1 = 0.2*pi;
wp1 = 0.35*pi;
wp2 = 0.65*pi;
ws2 = 0.8*pi;
As = 60;
tr_width = min((wp1-ws1),(ws2-wp2))
M = ceil(11*pi/tr_width)+1
n = [0:1:M-1] ;
wc1 = (ws1+wp1)/2;
wc2 = (ws2+wp2)/2
hd = ideal_lp(wc2,M)-ideal_lp(wc1,M);
w_bla = (blackman(M))';
h = hd.*w_bla;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w))
As = -round(max(db(ws2/delta_w+1:1:501)))
subplot(3,2,3);
stem(n,hd);
title('Ideal Response');
axis([0 M-1 -0.4 0.5]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,4);
stem(n,w_bla);
title('Blackman Window');
axis([0 M-1 0 1.1]);
xlabel('n');
ylabel('w(n)');
subplot(3,2,5);
stem(n,h);
title('Actual Impulse Response');
axis([0 M-1 -0.4 0.5]);
xlabel('n');
ylabel('h(n)');
subplot(3,2,6);
plot(w/pi,db);grid
title('Magnitude Response in dB');
axis([0 1 -150 10]);
xlabel('frequency in pi units');
ylabel('Decibels');
case 4
subplot(1,1,1);
M = 45;
As = 60;
n = [0:1:M-1];
beta = 0.1102*(As-8.7)
w_kai = (kaiser(M,beta))';
wc1 = pi/3;
wc2 = 2*pi/3;
hd = ideal_lp(wc1,M)+ideal_lp(pi,M)-ideal_lp(wc2,M);
h = hd.*w_kai;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
subplot(3,2,3);
stem(n,hd);
title('Ideal Response');
axis([0 M-1 -0.2 0.8]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,4);
stem(n,w_kai);
title('Kaiser Window');
axis([-1 M 0 1.1]);
xlabel('n');
ylabel('w(n)');
subplot(3,2,5);
stem(n,h);
title('Actual Impulse Response');
axis([-1 M -0.2 0.8]);
xlabel('n');
ylabel('h(n)');
subplot(3,2,6);
plot(w/pi,db);
title('Magnitude Response');
axis([0 1 -80 10]);
xlabel('frequency in pi units');
ylabel('Decibels');
case 5
subplot(1,1,1);
M = 21;
alpha = (M-1)/2;
n = 0:M-1;
hd = (cos(pi*(n-alpha)))./(n-alpha);
hd(alpha+1) = 0
w_ham = (hamming(M))';
h = hd.*w_ham
[Hr,w,P,L] = Hr_Type3(h);
subplot(3,2,3);
stem(n,hd);
title('Ideal Response');
axis([-1 M -1.2 1.2]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,4);
stem(n,w_ham);
title('Hamming Window');
axis([-1 M 0 1.2]);
xlabel('n');
ylabel('w(n)');
subplot(3,2,5);
stem(n,h);
title('Actual Impulse Response');
axis([-1 M -1.2 1.2]);
xlabel('n');
ylabel('h(n)');
subplot(3,2,6);
plot(w/pi,Hr/pi);
title('AMplitude Response');grid
axis([0 1 0 1]);
xlabel('frequency in pi units');
ylabel('slope in pi units');
case 6
subplot(1,1,1);
M = 25;
alpha = (M-1)/2;
n = 0:M-1;
hd = (2/pi)*((sin((pi/2)*(n-alpha)).^2)./(n-alpha));
hd(alpha+1) = 0;
w_han = (hanning(M))';
h = hd.*w_han;
[Hr,w,P,L] = Hr_Type3(h);
subplot(3,2,3);
stem(n,hd);
title('Ideal Impulse Response')
axis([-1 M -1.2 1.2]);
xlabel('n');
ylabel('hd(n)');
subplot(3,2,4);
stem(n,w_han);
title('Hanning Window');
axis([-1 M 0 1.2]);
xlabel('n');
ylabel('w(n)');
subplot(3,2,5);
stem(n,h);
title('Actual Impulse Response');
axis([-1 M -1.2 1.2]);
xlabel('n');
ylabel('h(n)');
w = w';
Hr = Hr';
w = [-fliplr(w),w(2:501)];
Hr = [-fliplr(Hr),Hr(2:501)];
subplot(3,2,6);
plot(w/pi,Hr);
title('Amplitude Response');grid;
xlabel('frequency in pi units');
ylabel('Hr');
axis([-1 1 -1.1 1.1]);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -