Applying a lowpass filter to a square wave
12 views (last 30 days)
Show older comments
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/470917/image.png)
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-');
0 Comments
Answers (1)
Rohit Pappu
on 31 Dec 2020
For implementing an ideal low pass filter, you can refer to this link
0 Comments
See Also
Categories
Find more on Pole and Zero Locations 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!