DSP Question: invfreqs.m

Technical Source
2 min readDec 24, 2021

--

I generate some coefficents for a filter and can inspect the frequency response as following:

%%Orginal Data
N = 5000;
data = cumsum(randn(N,1));
t = 252;
a = 2 / (t+1);
b = repmat(1-a,1 ,N).^(1:N); %b are your filter coeff
b = b ./ sum(b);
a = 1;
%%Plot the Filter on some example data
ma = filter(b, a, data);
figure;plot(data); hold all; plot(ma, 'r');
%%Plot the Response
figure;freqz(b,1);
[h,w] = freqz(b,1);

I now explain my problem. I am now in the situation where I have a frequency response (i.e. the vector “h”) and know nothing else.

I would like to estimate from this my original “b” (the filter coefficents) to allow me to estimate my variable “t”.

I thought I could use invfreqs.m (or invfreqz.m) to do this, but Im afraid I dont know how.

%%Find the impluse response
n = 10; % I choose a large number allowing a good approximation
m = 0; % I choose 0 here as I have 1 in my orignal filter ==> the output comes out as aNew = 1;
[bNew,aNew] = invfreqz(h,w,n,m);
%[bNew,aNew] = invfreqs(h,w,n,m);
sys = tf(bNew,aNew)
%%Plot the filter coeffcients
x1 = [0: 1/(size(b,2) -1) : 1];
x2 = [0: 1/(size(bNew,2) -1) : 1];
figure;plot(x1,b); hold all; plot(x2,bNew, 'r');

When I inspect the final plot, I would expect to see the red line (bNew) as a good approximation to b. It is not. not even close.

Clearly I am doing something very wrong. Please could someone with experince of how this function works, explain my mistake.

many thanks!

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

invfreqz.m has some odd rules re calling it.

%%Orginal Data
N = 5000;
data = cumsum(randn(N,1));
t = 252;
a = 2 / (t+1);
b = repmat(1-a,1 ,N).^(1:N);
b = b ./ sum(b);
a = 1;
%%Plot the Filter on some example data
ma = filter(b, a, data);
figure;plot(data); hold all; plot(ma, 'r');
%%Plot the Response
figure;freqz(b,1, N);
[h,w] = freqz(b,1,N);
%%Using dflit
% b = 1; a = -1; %Sanity Check. simple difference filter
% Hd = dfilt.df1([b a],1); % num/ denom == a/b
% fvtool(Hd);
%%Find the impluse response
% If n>(N-1) then you get a random answer!

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet