Convolution of e and cosine using Matlab

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);

回答 (2 件)

Image Analyst
Image Analyst 2017 年 9 月 14 日

0 投票

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 2024 年 2 月 9 日

0 投票

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 件のコメント

Image Analyst
Image Analyst 2024 年 2 月 9 日
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.

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

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

質問済み:

2017 年 9 月 13 日

コメント済み:

2024 年 2 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by