Highpass FIR Filter using Kaiser

4 Ansichten (letzte 30 Tage)
Leon
Leon am 5 Nov. 2013
Hi all. I am new to MatLab and am interested in designing a Highpass FIR filter using the Kaiser window method. The parameters for the filter is: Cutoff f = 1500Hs, Transition width = 1200Hz, Sampling f = 32000Hz, minimum passband ripple = 0.000275dB and stopband attenuation = 90dB.
My code does not seem to reflect the results and responses that would be expected from a highpass filter, any help will be greatly appreciated. Please forgive the awkwardness and messiness of my code.
%%HIGH PASS FILTER
format long;
% Filter parameters
fc = 1500; % Cutoff frequency
Df = 1200; % Transition bandwidth
fs = 32000; % Sampling frequency
fp = fc-fs; % Stopband frequency
B = 8.96; % From kaiser window
% Normalised values
fcn = fc/fs;
fpn = fp/fs;
Dfn = Df/fs;
N = ceil(5.71/Dfn); % Rounds up the value to next integer
Nh = (N-1)/2; % Calculating mid-point of order
Wcn = 2*pi*fcn; % Angular frequency in radians
y = Nh*Wcn; % Defines a variable for use with sinc
beta = 8.96; % From the given parameters of min. ripple
x = beta; % and stopband attenuation >60dB
Io = 1;
% Kaiser window
% Bessel function for Io
for k = 1:12;
Io = Io + (((x/2)^k)/factorial(k))^2; % Bessel function for the denom.
end
denominator = Io;
i =1;
for n = -Nh:Nh;
x = beta*(1-(2*n/(N-1))^2)^0.5; % Calculate the num. of the window
Io = 1;
for k =1:12;
Io = Io + (((x/2)^k)/factorial(k))^2;
end
Io_of_n(i) = Io;
i = i + 1;
end
% Ideal filter impulse response
kaiser = Io_of_n/denominator; % Creates the Kaiser window
hD = -2*fcn*sin(Nh*Wcn/Nh*Wcn);
filt = hD*kaiser;
% Plots
figure(1)
subplot(3,1,1)
stem(kaiser)
ylabel('Kaiser Window Function')
grid on
subplot(3,1,2)
stem(abs(fft(hD))) % impulse_resp=filter(Hd,[1 zeros(1,31)]);
ylabel('Ideal Impulse Response')
grid on
subplot(3,1,3)
stem(filt)
ylabel('Filter Frequency Response')
grid on
figure(2)
freqz(filt,1)
% Save information to disc
fid = fopen('filter.asm','w');
fprintf(fid,';Sampling frequency =%d\n',fs);
fprintf(fid,';Cutoff frequency =%d\n',fc);
fprintf(fid,';Transition bandwidth =%d\n',Df);
fprintf(fid,';Window type used = kaiser\n\n');
fprintf(fid,'ntaps EQU\t%d\n\n',N);
i=0;
for t=1:1:N
i=i+1;
fprintf(fid,'h_%d\tdc\t%1.8f\n',i,filt(i));
end
fclose(fid)
end

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by