Plotting a filter as a function of cyclic frequency using freqz()
Show older comments
Hello,
I'm trying to graph a moving average filter's magnitude response as a function of cyclic frequency. However, when I use freqz(), my plots do not look correct. Here's my code currently:
clear;close all;
fs = 200; %sampling frequency
Ts = 1/200; %sampling time
t = 0:Ts:1;
x = sin(2*pi*2*t) + sin(2*pi*10*t) + sin(2*pi*90*t); %signal
figure(1)
plot(t,x); %unfiltered signal
title('Signal with 2, 10, and 90 Hz');
xlabel('time (s)');
%Difference equation of Hanning Moving Average filter:
yn = zeros(size(t));
ind = 3:length(t);
yn(ind) = (0.25*x(ind)) + (0.5*x(ind-1)) + (0.25*x(ind-2));
%Attempt at creating the moving average equation.
figure(2)
plot(t,yn)
title("Hanning Moving Average")
%Me just plotting the filtered Hanning Moving Average plot with
%freqz():
figure(10)
freqz(yn)
Both the magnitude (dB) and the phase seem to show a lot of sound, but the plot of figure 2 does not. Any help will be appreciated.
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

