function [Hw,f]=fr_resp(h,K,fs) %% FR_RESP Computes the samples of the frequency response (i.e., DFT) %% for an input sequence. The user can specify number of %% points and a sample frequency. %% %% Usage: %% [Hw,f]=fr_resp(h,K,fs) %% %% Variables: %% h = sequence %% K = number of points desired [OPTIONAL - default = length(h)] %% fs = sampling frequency (Hz) [OPTIONAL - no default] %% %% Hw = samples of the frequency response of h %% f = frequency vector to plot against %% - if fs not specified, then f is [-pi,pi) %% - if fs specified, then f is in Hz %% %% File : fr_resp.m %% Author : Kathleen E. Wage %% Date : August 22, 1998 %-------------------------------------------------------------------- %%%% Set up defaults if nargin<2 K=length(h); fscale=1; elseif nargin<3 fscale=1; else % If fs specified, then set up scale factor fscale=fs/(2*pi); % to return analog frequencies (Hz) end %-------------------------------------------------------------------- %%%% Compute the frequency response Hw=fft(h,K); %-------------------------------------------------------------------- %%%% Compute the frequency vector and reorganize frequency components %%%% so they are from [-pi,pi) w=(2*pi/K)*[ 0:(K-1) ]'; mid=ceil(K/2)+1; w(mid:K)=w(mid:K)-2*pi; % move [pi,2pi) to [-pi,0) w=fftshift(w); Hw=fftshift(Hw); % move negative freq components f=fscale*w; % Scale frequency axis %-------------------------------------------------------------------- return;