Remez exchange algorithm | Scigyan

Remez exchange algorithm

Matlab program for Remez exchange algorithm.
[n,fo,ao,w] = firpmord(f,a,dev,fs). Finds the approximate order, normalized frequency band edges, frequency band amplitudes, and weights.
b = firpm(n,f,a,w) returns row vector b containing the n+1 coefficients of the order n FIR filter whose frequency-amplitude characteristics match those given by vectors f and a.

Matlab code

clc; clear all; close all;
rp=input('Enter the Passband ripple (In db) = '); 
rs=input('Enter the Stopband attenuation (In db) = '); 
fpc=input('Enter the Passband corner frequency (In Hz) = '); 
fsc=input('Enter the Stopband corner frequency (In Hz) = '); 
fs=input('Enter the Sampling frequency (In Hz) = ');

f = [fpc fsc]; % f is a vector of frequency band edges
a = [1 0]; % Desired amplitudes on the bands defined by f.
dev = [(10^(rp/20)-1)/(10^(rp/20)+1) 10^(-rs/20)]; % Compute deviations by rp & rs

[n,fo,ao,w] = firpmord(f,a,dev,fs); b = firpm(n,fo,ao,w);
[h,fn] = freqz(b,1,1024,fs);% Denominator polynomials a = 1

subplot(3,1,1);
plot(fo,ao,'r');
hold on;
plot(fn/(fs/2),abs(h)); 
legend('Ideal','firpm Design')
title('Comparison b/w Ideal & firpm Design'); 
ylabel('Magnitude -->');
xlabel('Normalized Frequency ( x pi rad/sample)-->'
grid on;

subplot(3,1,2); 
plot(fn/(fs/2),20*log10(abs(h))); 
title('Magnitude Response of Lowpass Filter'); 
ylabel('Gain in dB -->');
xlabel('Normalized Frequency ( x pi rad/sample)-->'
grid on;

subplot(3,1,3);
plot(fn/(fs/2),angle(h));
title('Phase Response of Lowpass Filter'); 
xlabel('Normalized Frequency ( x pi rad/sample)-->'); 
ylabel('Phase in radians -->');
grid on;

Command window

Enter the Passband ripple (In db) = 1
Enter the Stopband attenuation (In db) = 30
Enter the Passband corner frequency (In Hz) = 400
Enter the Stopband corner frequency (In Hz) = 600
Enter the Sampling frequency (In Hz) = 2000

Figure window

Remez-exchange-algorithm
No comments:
Post a Comment

Related Posts Plugin for WordPress, Blogger...