How do I calculate filter from transfer function?
5 views (last 30 days)
Show older comments
Suppose I have a filter h = [1/4; 1/2; 1/4]. It is known that its Fourier transform (transfer function) is somewhat like H(w) = cos(w/2).^2. Now, suppose I have a transfer function, e.g. G(w) = sin(w/2).^2. How do I obtain g = [-1/4; 1/2; -1/4]?
Here is a part of my code for the forward problem:
Fs = 1000;
dt = 1/Fs;
L = 1000;
t = ((0:L-1)*dt)';
% signal
x = 0.7*sin(2*pi*6*t)+0.5*sin(2*pi*360*t);
figure;
subplot(2,2,1);
plot(t,x);
% Fourier transform
[Z,phi,f,NFFT] = FourierF(x,Fs,L);
subplot(2,2,2);
plot(f(1:NFFT/2+1),Z(1:NFFT/2+1));
% filter
h = [1/4; 1/2; 1/4];
% H = cos(pi*f/(NFFT+1)).^2; % the corresponding transfer function
subplot(2,2,3);
[H,~,f0,NFFT0] = FourierF(h,Fs,L); % передаточная функция
plot(f0(1:NFFT0/2+1),H(1:NFFT0/2+1));
function [Z,phi,f,NFFT] = FourierF(x,Fs,L)
NFFT = 2^nextpow2(L);
X = fft(x,NFFT);
Z = abs(X);
phi = angle(X);
fsc = linspace(0,1,NFFT)';
f = Fs*fsc;
end
0 Comments
Answers (1)
Christiaan
on 11 Mar 2015
Edited: Christiaan
on 11 Mar 2015
Dear Ivaschenko,
The value of those filter coefficients depend on the type of filter you want to use.
If your filter is a FIR filter, then the filter coefficients are the values of the laplace transformed impulse response. If your filter is an IIR filter, then the filter coefficients are not the same as the impulse response. (In case of the IIR, the impulse response of the filter is infinite)
What you could do, is use the DSP toolbox to plot the impulse response of the transfer function and use the fdatool in matlap (type 'fdatool' in prompt) and modify the filter with hand. Then you can export the filter coefficients in the fdatool.
Good Luck! Christiaan
0 Comments
See Also
Categories
Find more on Filter Analysis 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!