image thumbnail

EXPO 2011 Signal Processing Workflow Demo Files

by

 

MATLAB EXPO 2011 Signal Processing Workflow Demo Files

filter_fir_sig.m
%% e FIR fBW^tB^݌v
close all, clear all
%% 
Fs = 1000;				% TvOg [Hz]
Wp = 200/500;		% ʉߑшCiCLXggŐK
Ws = 250/500;		% ՒfшCiCLXggŐK
Rp = 1;				% ʉߑш̃bv [dB]
Rs = 30;				% Ւf [dB]
N = 4;              % 

%% FIR1 Window Based FIR Filter
% ʉߑшɃv
nf1 = fir1(34,0.4,kaiser(35));
hfv = fvtool(nf1,1), legend('Window')

%% FIR2 Frequecy Based FIR Filter
% gƐU^Đ݌v
f = [0 0.4 0.4 1]; m = [1 1 0 0];
nf2 = fir2(34,f,m);
addfilter(hfv,nf2,1),legend(hfv,'Window','Frequency')

%% Least Square Linear-Phase FIR Filter
% d݂ƃ^Cv̐ݒ^Đ݌v
f = [0 0.4 0.4 1]; m = [1 1 0 0]; w = [1 100];
nls = firls(34,f ,m, w);
hfv2 = fvtool(nls,1),legend(hfv2,'Least Square')

%% Constrained Least Square FIR Filter
% ȔA̐tĐ݌v
n = 34;
f = [0 0.38 0.4 0.8 1]; a = [1 1 0 0];
up=[1.02 1.02   0.002  0.002];	% Ȕ
lo =[0.98 0.98 -0.002 -0.002];	% Ủ
ncls = fircls(n,f,a,up,lo);
addfilter(hfv2,ncls,1),legend(hfv2,'Least Square','Constrained Least Square')

%% Constrained Least Square FIR Filter
% ʉ/Ւfш惊v̐tĐ݌v
n = 34;
wo = 0.4;	% JbgIt	
dp = 0.04;	% ʉߑш惊v
20*log10(dp)
ds = 0.002;	% Ւfш惊v 20*log10(ds)
20*log10(ds)
ncls1 = fircls1(n,wo,dp,ds); 
addfilter(hfv2,ncls1,1),legend(hfv2,'Least Square','Constrained Least Square', 'Constrained Least Square1')

%% Parks-McClellan Optimal FIR Filter 
% U̍ő勖e΍w肵Đ݌v
% firpmordŕ΍𖞂悤߂
rp = 1;           % Passband ripple
rs = 60;          % Stopband ripple
f = [200 240];    % Cutoff frequencies
a = [1 0];        % Desired amplitudes
% W΍̌vZ
dev = [(10^(rp/20)-1)/(10^(rp/20)+1)  10^(-rs/20)]; 
[n,fo,ao,w] = firpmord(f,a,dev,Fs);
npm = firpm(n,fo,ao,w);
hfv3 = fvtool(npm,1), legend(hfv3,'Parks-McClellan Optimal') 
%% Interpolation FIR Filter
% ш搧C^|[VtB^
alpha = 0.5;                 % "Bandlimitedness" factor
ni = intfilt(4,2,alpha);     % Bandlimited interpolation
hfv4 = fvtool(ni,1);legend(hfv4,'Interpolation') 

%% Complex and Nonlinear-Phase Equiripple FIR Filter
% fɂȂ”\̂tB^g^Đ݌v
f = [-1 -0.5 -0.4 0.1 0.8 1];
a = [0   0    1   1   1   0];
% nc = cfirpm(34,f,@lowpass);
nc = cfirpm(34,f,a);
fvtool(nc,1)

%% Kaiser window FIR1 filter
% KaiserEBhEg΍w肵݌v
% kaiserordŕ΍𖞂悤߂
f = [200 250];
a = [1 0];
devs = [0.05 0.01];
[n,Wn,beta,ftype] = kaiserord(f,a,devs,Fs);
nfk = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
fvtool(nfk,1)

Contact us