Convolution of e and cosine using Matlab

17 vues (au cours des 30 derniers jours)
raykhu
raykhu le 13 Sep 2017
Commenté : Image Analyst le 9 Fév 2024
am trying to perform convolution in Matlab using the function conv() and then plot the result. Below is my code.
tstep = 0.1;
time = 10;
t = -time:t:time;
x = cos(2*pi*t);
h = exp(-t);
y = conv(x,h,'same');
plot(t,y);

Réponses (2)

Image Analyst
Image Analyst le 14 Sep 2017
I see no reason why you should get that kind of output given the h and x you have defined. In fact if you look at the plots, it makes perfect sense what you are seeing. Look at the plots and tell me if you don't now see why convolving those two gives the bottom output.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
Fs = 16000;
Ts = 1/Fs;
fc = 1000;
Tc = 1/fc;
t = 0:Ts:Tc;
% LTI impulse response h(t) = exp(-1000*t)
h = exp(-1000*t);
% angular frequency wc = 2*pi*fc
wc = 2*pi*fc;
% the signal x(t) = sin(wc*t)
x = sin(wc*t);
% convolution of x(t) and h(t)
y = conv(x,h,'same');
subplot(3, 1, 1);
plot(t, h, 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', fontSize);
ylabel('h', 'FontSize', fontSize);
subplot(3, 1, 2);
plot(t, x, 'LineWidth', 2)
grid on;
xlabel('t', 'FontSize', fontSize);
ylabel('x', 'FontSize', fontSize);
subplot(3, 1, 3);
plot(t, y, 'LineWidth', 2)
grid on;
hold on
stem(t,y)
xlabel('t', 'FontSize', fontSize);
ylabel('y = x**h', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
% set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')

Jaiprakash
Jaiprakash le 9 Fév 2024
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
Fs = 16000;
Ts = 1/Fs;
fc = 1000;
Tc = 1/fc;
t = 0:Ts:Tc;
% LTI impulse response h(t) = exp(-1000*t)
h = exp(-1000*t);
% angular frequency wc = 2*pi*fc
wc = 2*pi*fc;
% the signal x(t) = sin(wc*t)
x = sin(wc*t);
% convolution of x(t) and h(t)
y = conv(x,h,'same');
subplot(3, 1, 1);
plot(t, h, 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', fontSize);
ylabel('h', 'FontSize', fontSize);
subplot(3, 1, 2);
plot(t, x, 'LineWidth', 2)
grid on;
xlabel('t', 'FontSize', fontSize);
ylabel('x', 'FontSize', fontSize);
subplot(3, 1, 3);
plot(t, y, 'LineWidth', 2)
grid on;
hold on
stem(t,y)
xlabel('t', 'FontSize', fontSize);
ylabel('y = x**h', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
  1 commentaire
Image Analyst
Image Analyst le 9 Fév 2024
Yep, that was my code in my answer. But you do not need to post my code here as your answer to this 6 year old question.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by