Home > Archive > Matlab > December 2006 > Filter frequency response
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Filter frequency response
|
|
| Udo Juerss 2006-12-27, 4:19 am |
| Hello,
how can I display the frequency response and phase shift of a
function? For a low pass filter, a running average like this:
"new_value = 0.95 * old_value + 0.05 * actual_value".
Thanks
Udo
| |
| Rune Allnor 2006-12-27, 8:17 am |
|
Udo Juerss skrev:
> Hello,
>
> how can I display the frequency response and phase shift of a
> function? For a low pass filter, a running average like this:
> "new_value = 0.95 * old_value + 0.05 * actual_value".
There is a very specific terminology for filters, which you have
not used. With the proviso that I misunderstand your meaning,
what you have is a FIR filter. The recipe for plotting magniude
spectrum and phase response is scetched below (I assume
you do not have access to the signal processing toolbox).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% First, collect the coefficients in a vector like this:
h = [0.95 0.05];
% Then compute the spectrum:
Nfft=1024;
H = fft(h,Nfft);
% Convert to polar representation:
[th,r]=cart2pol(real(H),imag(H));
% Construct a frequency vector:
fs = 1; % You did not specify the sampling frequency
fv = [0:Nfft-1]/Nfft*fs;
% Plot the spectrum:
fidx = find(fv<fs/2);
subplot(2,1,1)
plot(fv(fidx),r(fidx))
% Plot the phase response:
subplot(2,1,2)
plot(fv(fidx),th(fidx))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
And that's it.
Rune
| |
|
|
Rune Allnor wrote:
> Udo Juerss skrev:
>
> There is a very specific terminology for filters, which you have
> not used. With the proviso that I misunderstand your meaning,
> what you have is a FIR filter. The recipe for plotting magniude
> spectrum and phase response is scetched below (I assume
> you do not have access to the signal processing toolbox).
The running average is sometimes expressed as
Output(n) = (1-alpha) * Output(n-1) + alpha * Input(n)
This is an IIR filter. Try calculating a vector of outputs by this
formula for a unit impulse signal. That is, the first input is 1.0 and
the rest are 0's. For the first, nonexistant, previous output, use 0.0
and alpha = 0.05.
Then try Rune's plot with this output vector for H.
Dale B. Dalrymple
http://dbdimages.com
|
|
|
|
|