How to Perform a Convolution in MATLAB | MATLAB Tutorial

preview_player
Показать описание
Convolutions in MATLAB! How to take the convolution conv() of two functions f(t)*x(t) to generate a system response. Discrete functions and smoothing curves discussed with examples.

OVERVIEW
conv(a,b) is used to take the convolution of two functions. Be sure to scale your output! 3:06
If you want the output to have the same number of terms as 'a', use conv(a,b,'same').

CHAPTERS
0:00 Introduction
0:36 Part 1: Convolution of Two Functions f(t)*g(t)
1:57 Using conv()
2:25 Analyzing System Response
3:06 Scaling System Response
7:24 Part 2: Smoothing Curves
9:13 Using conv(a,b,'same')

MATH CORRECTIONS/COMMENTS on the video -- PLEASE READ!!
1. f(t)*g(t) is said "f convolved with g".
2. at 4:15 we see the max value of the output = max f(t) times max g(t) -- know that this does not always happen.
3. Scaling the t-axis / x-axis is not always straightforward. My scale and shift works in this case but doesn't apply to the general case.
4. at 5:50 you don't need the .* for (1:length(yt))*dt because this is a vector times a scalar.
5. at 6:50 take note I have only included the t2(1) term. However, for the general case, you may use t2(1) + t1(1) to account for your signals starting at different times. In this video, t1(1) was simply zero and thus adding only t2(1) worked.

MORE MATLAB

LIKE AND SUBSCRIBE
If you received something of value from this video, please like and subscribe to support this channel :) as always comment below and I will answer your question!

Рекомендации по теме
Комментарии
Автор

your shift is wrong
the correct shift is : t1(1) + t2(1)
the resone is in Convolution we can swap => f(t)*x(t) = x(t)*f(t)
that's why we use : t1(1) + t2(1)
thank you for your great Tutorial

mahdinemati
Автор

At exactly 2:26, your output of conv shows two unusual features - the value at t = 0 is not in the plot, and the max value of the result is 63 instead of 60. After you scale both output and t values, those details are gone, and your final results don't show those. However when I duplicate your code, I get a final graph that has the same two incorrect features. Do you have any idea why the graph at 2:26 is off? Maybe that would help me. Has 'conv' changed since your video? Thanks!

ronlaspisa
Автор

I could not understand what you had done from line 23 up till line 36, could you please show me what is going on there?

burhanuddinsakarwala
Автор

Is there a specific formula you used for the Hamming curve?

jchopra
Автор

here is working code for the first part.

clc, clearvars, close all
dt = 0.0001;

t1 = 0:dt:2;
ft = 2-t1;

t2 = -2:dt:2;
gt = 3*ones(1, length(t2));

yt = dt*conv(ft, gt);
yt_x = (1:length(yt)).*dt + t2(1) + t1(2);

figure(1)
subplot(2, 2, 1), plot(t1, ft, 'r'), title('f(t) impulse response'),
grid on, xlim([-2 2]), xlabel('t'), ylabel('amplitude')

subplot(2, 2, 3), plot(t2, gt, 'b'), title('g(t) system input'),
grid on, xlabel('t'), ylabel('amplitude'), ylim([0 3.5])

subplot(2, 2, [2;4]), plot(yt_x, yt, 'k'), title('f(t)*g(t) system response'),
grid on, xlabel('t'), ylabel('amplitude')

knightning
visit shbcf.ru