Calculate the convolution of signals both directly and using DFT.

28 ビュー (過去 30 日間)
Cordas Andrei Cristian
Cordas Andrei Cristian 2022 年 1 月 10 日
編集済み: Paul 2022 年 1 月 10 日
Hi,
I created a matlab code that calculates the convolution of two sequences (x1 and x2) both by the direct method and using the discrete Fourier transform. The problem I have is that when I run the code, the answers are different and I don't know where I went wrong.
I leave below the statement of the problem and the code.
I wrote disp (y) as a comment because I didn't understand what it was doing.
I wish a good day!
%% Convolutie directa
%The following sequences are considered:
%x1 (n) = [3 4.2 11 0 7 -1 0 2]
%x2 (n) = [1.2 3 0 -0.5 2]
%Create a MATLAB code that calculates the convolution of the two sequences
% both directly and using the discrete Fourier transform.
clear all
close all
x1 = [3 4.2 11 0 7 -1 0 2];
x2 = [1.2 3 0 -0.5 2];
y = conv(x1, x2)
y = 1×12
3.6000 14.0400 25.8000 31.5000 12.3000 22.7000 19.0000 -1.1000 20.5000 -2.0000 -1.0000 4.0000
%% DFT
clear all
close all
w = -pi:pi;
x1 = [3 4.2 11 0 7 -1 0 2];
x2 = [1.2 3 0 -0.5 2];
y = conv(x1,x2);
X1 = freqz(x1,1,w);
X2 = freqz(x2,1,w);
X = X1.*X2;
Y = freqz(y,1,w);
subplot(221)
plot(w/pi,abs(X)); grid
title('The product module in the DFT of the two sequences')
subplot(222)
plot(w/pi,angle(Y)); grid
title('The product phase between the DFTs of the two sequences')
%disp(y)
  3 件のコメント
Cordas Andrei Cristian
Cordas Andrei Cristian 2022 年 1 月 10 日
When I try to resolve the problem, in my notebook it was write an exemple with freqz() for Fourier transform.
Paul
Paul 2022 年 1 月 10 日
編集済み: Paul 2022 年 1 月 10 日
For finite duration sequences, as is the case here, freqz() can be used to compute the Discrete Time Fourier Transform (DTFT) of x1 and the DTFT of x2. Then multiply them together, and then take the inverse DTFT to get the convolution of x1 and x2. So there is some connection from freqz to the Fourier transform.
However, the problem statement says to use the DFT. But the DFT is just a set of particular samples of the DTFT, so the DFT can be computed from freqz(). Maybe the OP is trying to use this approach instead of using fft()?

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2022 年 1 月 10 日
The DFT only agrees with linear (not circulant) convolution when sufficient zero padding is done. It doesn't appear that you have done any.
  2 件のコメント
Cordas Andrei Cristian
Cordas Andrei Cristian 2022 年 1 月 10 日
And, what I need to do?
Matt J
Matt J 2022 年 1 月 10 日
Probably zero-pad.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by