stem a convolve signal

조회 수: 17 (최근 30일)
Mohammed Alqahtany
Mohammed Alqahtany 2023년 11월 25일
댓글: Paul 2023년 11월 25일
% Define fs and time duration
fs = 10; % sample/second
duration = 1; % second
% Generate the time axis
t = 0:1/fs:duration-1/fs;
% the rectangular signal
x = ones(size(t));
% Plot the signal
subplot(2,1,1);
stem(t, x);
xlabel('Time (s)');
ylabel('Amplitude');
title('orignal Signal x[n]');
% Convolve the signal with itself
y = conv(x, x);
% Generate the time axis for the convolved signal
t_conv = 0:1/fs:2*duration-1/fs;
% Plot the convolved signal
subplot(2,1,2);
stem(t_conv, y);
Error using stem
X must be same length as Y.
xlabel('Time (s)');
ylabel('Amplitude');
title('Convolved Signal y[n]');
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2023년 11월 25일
The error is clear - The lengths of t_conv and y are not the same.
They should be the same.
Mohammed Alqahtany
Mohammed Alqahtany 2023년 11월 25일
thank you

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2023년 11월 25일
Because the first point in x corresponds to t = 0, so does the first point in y. t_conv has to have as many points as y. And the spacing in t_conv has to be fs. So the easiest way to construct the time vector that corresponds to y is
t_conv = (0:numel(y)-1)/fs
  댓글 수: 2
Mohammed Alqahtany
Mohammed Alqahtany 2023년 11월 25일
thank it work now
Paul
Paul 2023년 11월 25일
You're welcome.
Don't forget to divide y by fs if using conv, which computes the convolution sum, to approximate the convolution integral.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by