Frequency response function In matlab

13 views (last 30 days)
shabaz lee
shabaz lee on 20 Feb 2018
Answered: Walter Roberson on 20 Feb 2018
Can someone help me with this matlab frequency response problem.
This is what I have so far, but code doesnt work.
function [H] = freqresp(b, a, w)
a(1) = 1;
numer(0) = 0;
denom(1) = 0;
for k=1:length(b)
numer(k) = numer(k-1) + b(k) * exp(i*w*k);
end
for m=2:length(a)
denom(m) = denom(m-1) + a(m)*exp(i*w*k);
end
H = numer/denom;

Answers (1)

Walter Roberson
Walter Roberson on 20 Feb 2018
You have
numer(0) = 0;
In MATLAB, indexing can never start from 0. You need
numer(1) = 0;
for k=1:length(b)
numer(k+1) = numer(k) + b(k) * exp(i*w*k);
end
for m=1:length(a)
denom(m+1) = denom(m) + a(k)*exp(i*w*k);
end
But after that you have a problem. You could try
H = numer ./ denom
but if length(a) and length(b) are not the same, you have a problem.

Community Treasure Hunt

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

Start Hunting!