Applying a lowpass filter to a square wave

18 次查看(过去 30 天)
Hello all,
I'm trying to apply a lowpass filter with the gain and phase responses given in the screenshots below to a square wave with frequency of 1khz however im not sure im going about it correctly (code is pasted below). Could someone clarify how filtering works in matlab and how it is possible to implement the conditions shown in the screenshots (especially with regards to the phase response)?
For reference ive been basing my current filter code off this article however im fairly sure i havent accounted for phase response and im not really sure how to.
T = 0.001; %sets f0 to 1000hz/1khz
w = 2*pi*(1/T);
%filter parameters
fs = 1/T ;
fpass = 10000;
t = linspace(0 , 3*T, 1000);
max_harmonics = 20; %sets maximum number of sine terms
synth_VT = zeros(size(t));
for n = 1:2:max_harmonics
synth_VT = synth_VT + (3/pi)*((1/n)*sin(n*w*t)) ;
end
filtered_synth_VT = zeros(size(t));
filtered_synth_VT = lowpass(synth_VT, fpass, fs);
plot(t, synth_VT, 'r-', t, filtered_synth_VT, 'b-');

回答(1 个)

Rohit Pappu
Rohit Pappu 2020-12-31
For implementing an ideal low pass filter, you can refer to this link

类别

Help CenterFile Exchange 中查找有关 Filter Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by