MATLAB实现最优低通滤波器的函数

MATLAB实现最优低通滤波器的函数

% Fs     --Data rate

% Fpass  --pass band

% Fstop  --Cutoff frequencies

% Apass  --Passband ripple

% Astop  --Stopband ripple

% Q_Bit  --Quantization bits

function coef  = LowPassFir(Fs,Fpass,Fstop,Apass,Astop,Q_Bit)

 

 

 

dens  = 20;               % Density Factor

a = [1 0];        % Desired amplitudes

rp = Apass;

rs = Astop;

 

% Compute deviations

dev = [(10^(rp/20)-1)/(10^(rp/20)+1),10^(-rs/20)];

 

% Calculate the order from the parameters using FIRPMORD.

[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs/2), a, dev);

% Calculate the coefficients using the FIRPM function.

coef  = firpm(N, Fo, Ao, W, {dens});

coe = coef;

fft_coe = 20*log(abs(fft(coe,1024)))/log(10);

 

% x_f = [0:(Fs/length(fft_coe)):Fs/2];

% m = fft_coe(1:length(x_f));

% plot(x_f,m),grid

 

fft_shift_coe = fftshift(fft_coe);

x_f = [-Fs/2+(Fs/length(fft_shift_coe)):(Fs/length(fft_shift_coe)):Fs/2];

plot(x_f,fft_shift_coe);grid

 

HB

function Coef = LowPassHb(Fs,Fpass,Apass,n)

% -- Fs sample frequency

% -- Fpass

% -- Apass(dB)

% -- n stage of the half band fir

fp = Fpass*2/(Fs);

dev = [(10^(Apass/20)-1)/(10^(Apass/20)+1)];

% dev = Apass;

switch nargin

    case 3

        Coef = firhalfband('minorder',fp,dev);

    case 4

        Coef = firhalfband(n,fp);

    otherwise

        error('error');

end

        Coef = Coef';

   

 vpa(Coef,16);

fft_coe = 20*log(abs(fft(Coef,1024)))/log(10);

 

% x_f = [0:(Fs/length(fft_coe)):Fs/2];

% m = fft_coe(1:length(x_f));

% plot(x_f,m),grid

 

fft_shift_coe = fftshift(fft_coe);

x_f = [-Fs/2+(Fs/length(fft_shift_coe)):(Fs/length(fft_shift_coe)):Fs/2];

plot(x_f,fft_shift_coe);grid

原文地址:https://www.cnblogs.com/zhongguo135/p/5916821.html