How to design a low pass filter with rectangular window?
46 views (last 30 days)
Show older comments
Hello all, Here, I have a lowpass filter with butter 15Hz cutoff freqeuncy. But I am looking for a low pass filter using rectangular window implimentation.
clear all;
% close all; clc;
%-------------------------------------------------------------
% System definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%-------------------------------------------------------------
fs=8192; % sampling frequency
dt = 1/fs; % sample time
T=3; % duration of the signal
Nt = T*fs; % total number of samples
t = 0:dt:T-dt; % time vector
% Source definition
f0 = 900; % initial angular speed in Hz
fT = 2700; % final angular speed in Hz
finst = linspace(f0,fT,Nt);
phi = 2*pi*cumsum(finst)*dt;
a1 = 45;
b1 = 5000;
c1 = 2;
c2 = 1.5;
d1 = 2+3*1j;
% Definition of envelop
int_phi0 = 3*pi/4;
A = d1+(a1 * exp(-b1 * (t - T/c1).^2 + 1j * int_phi0));
% Definition of source signal
q = A.'.*exp(1j*phi).';
filtorder =6; fc =15;%----------------------------------% fc-cutoff
[bcoeff,acoeff] = butter(filtorder,fc/fs*2);
Afilt = filtfilt(bcoeff,acoeff,q.*exp(-1j*phi).');
figure()
plot(t,q,'k')
hold on
plot(t,abs(Afilt),'r','LineWidth',2)
grid on; box on;
legend('q(t)','A(t)')
xlabel('s')
ylabel('Amp')
title('q(t) and A(t) - filtered')
set(gca,'FontSize',15)
xlim([1.2 1.8])
0 Comments
Answers (1)
N A POORNA CHANDRA
on 7 Jul 2023
hi kalasagarreddi, here is the code for low pass filter with rectangular window
clear all;
clc;
fs = 8192; % Sampling frequency
dt = 1/fs; % Sample time
T = 3; % Duration of the signal
Nt = T*fs; % Total number of samples
t = 0:dt:T-dt; % Time vector
f0 = 900; % Initial angular speed in Hz
fT = 2700; % Final angular speed in Hz
finst = linspace(f0,fT,Nt);
phi = 2*pi*cumsum(finst)*dt;
a1 = 45;
b1 = 5000;
c1 = 2;
c2 = 1.5;
d1 = 2+3*1j;
%envelop
int_phi0 = 3*pi/4;
A = d1 + (a1 * exp(-b1 * (t - T/c1).^2 + 1j * int_phi0));
% source signal
q = A.'.*exp(1j*phi).';
% Low-pass filter using Kaiser window
fc = 15; % Cutoff frequency in Hz
normalized_fc = fc / (fs/2); % Normalized cutoff frequency
filter_order = 50; % Filter order
beta = kaiser(filter_order+1, 8); % Kaiser window with beta = 8
h = fir1(filter_order, normalized_fc, 'low', beta); % Filter coefficients
Afilt = filtfilt(h, 1, q.*exp(-1j*phi).');
figure();
plot(t, q, 'k');
hold on;
plot(t, abs(Afilt), 'r', 'LineWidth', 2);
grid on;
box on;
legend('q(t)', 'A(t)');
xlabel('s');
ylabel('Amp');
title('q(t) and A(t) - filtered');
set(gca,'FontSize',15);
xlim([1.2 1.8]);
See Also
Categories
Find more on Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!