Upload
lekiet
View
221
Download
2
Embed Size (px)
Citation preview
% Program 5_4% Linear Convolution Via the DFT% Read in the two sequences
>> Program_5_4Type in the first sequence = [1 2 0 1]Type in the second sequence = [2 2 1 1]% Read in the two sequences
x = input('Type in the first sequence = ');h = input('Type in the second sequence = ');% Determine the length of the result of
l ti 6Result of DFT-based linear convolution
Type in the second sequence = [2 2 1 1]
convolutionL = length(x)+length(h)-1;% Compute the DFTs by zero-paddingXE = fft(x,L); HE = fft(h,L); 2
4
6
Am
plitu
de
XE fft(x,L); HE fft(h,L);% Determine the IDFT of the producty1 = ifft(XE.*HE);% Plot the sequence generated by DFT b d l ti d
0 1 2 3 4 5 60
2
Time index n
A
15x 10-15 Error sequence
DFT-based convolution and% the error from direct linear convolutionn = 0:L-1;subplot(2,1,1) 0.5
1
1.5
Am
plitu
de Results from the finite precision arithmatic of fft
subp o ( , , )stem(n,y1)xlabel('Time index n');ylabel('Amplitude');title('Result of DFT-based linear convolution')2 ( h)
0 1 2 3 4 5 60
Time index n
y2 = conv(x,h);error = y1-y2;subplot(2,1,2)stem(n,error)( , )xlabel('Time index n');ylabel('Amplitude')title('Error sequence')