626 C H A P T E R 10: Fourier Analysis of Discrete-Time Signals and Systems
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example 10.22---Linear and circular convolution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; clf
N = 20; x = ones(1,N);
% linear convolution
z = conv(x,x);z = [z zeros(1,10)];
% circular convolution
y = circonv2(x,x,N);
y1 = circonv2(x,x,N + 10);
y2 = circonv2(x,x,2∗N + 9);
Mz = length(z); My = length(y); My1 = length(y1);My2 = length(y2);
y = [y zeros(1,Mz - My)]; y1 = [y1 zeros(1,Mz - My1)]; y2 = [y2 zeros(1,Mz-My2)];
The functioncirconv2has as inputs the signals to be convolved and the desired length of the circular
convolution. It computes and multiplies the FFTs of the signals and then finds the inverse FFT to
obtain the circular convolution. If the desired length of the circular convolution is larger than the
length of each of the signals, the signals are padded with zeros to make them the length of the
circular convolution. The following is the code for this function.
function xy = circonv2(x,y,N)
M = max(length(x),length(y))
if M>N
disp(‘Increase N’)
end
x = [x zeros(1,N - M)];
y = [y zeros(1,N - M)];
% circular convolution
X = fft(x,N); Y = fft(y,N); XY = X.∗Y;
xy = real(ifft(XY,N)); n
nExample 10.23
A significant advantage of using the FFT for computing the DFT is in filtering. Assume that
the signal to filter consists of the MATLAB file “laughter.mat,” multiplied by 5, to which a sig-
nal that continuously changes between−0.3 and 0.3 is added. We wish to recover the original
“laughter.mat” signal using a filter. Use the MATLAB functionfir1to design the required filter.
Solution
Noticing that since the disturbance 0.3(− 1 )nis a signal of frequencyπ, we need a low-pass filter
with a wide bandwidth so as to get rid of the disturbance while trying to keep the frequency
components of the desired signal. The following script is used to design the desired low-pass filter,
and to implement the filtering. To compare the results obtained with the FFT we use the function
convto find the output of the filter in the time domain. The results are shown in Figure 10.18.