필터 지우기
필터 지우기

convolution of 2 discrete signal

조회 수: 92 (최근 30일)
HADIMARGO
HADIMARGO 2019년 7월 27일
답변: Pramil 2024년 8월 21일 11:31
hi. this is my code:
clc
clear all
n=-2:1:12;
nx = -2:8 ; nh = 0:12; % Set time vectors for x and h
x = usD(n-1) - usD(n-6); % Compute values of x
h = tri((nh-6)/4); % Compute values of h
y = conv(x,h); % Compute the convolution of x with h
ny=(nx(1) + nh(1)) + (0:(length(nx) + length(nh) - 2)) ;
subplot(3,1,1) ; stem(nx,x,'k','filled');
xlabel('n') ; ylabel('x'); axis([-2,20,0,4]);
subplot(3,1,2) ; stem(nh,h,'k','filled') ;
xlabel('n') ; ylabel('h'); axis([-2,20,0,4]);
subplot(3,1,3) ; stem(ny,y,'k','filled');
xlabel('n') ; ylabel('y'); axis([-2,20,0,4]);
function z = usD(n)
z = double(n >= 0); % Set output to one for non-
% negative arguments
I = find(round(n) ~= n); % Index non-integer values of n
z(I) = NaN ;
end
function d= tri(n)
....
....
....
end
in this code i want to stem conv(x,h). i need to define function tri in the last. can u help me.
the result:
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 7월 27일
편집: KALYAN ACHARJYA 2019년 7월 27일
Please do share tri function file. Is the x and h having same length?

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

답변 (1개)

Pramil
Pramil 2024년 8월 21일 11:31
Hi Hadimargo,
Based on your code, and result image, it looks like you want to create a triangular waveform. Here’s how you can define the "tri" function:
function d = tri(n)
% Create triangular waveform centered at zero
d = max(1 - abs(n), 0);
end
This function will generate a triangular waveform with a peak value of 1 and a base width of 2 units. You can adjust the function as needed to fit your specific requirements.
Here’s your complete code with the "tri" function defined:
clc
clear all
n = -2:1:12;
nx = -2:12; nh = 0:14; % Set time vectors for x and h
x = usD(n-1) - usD(n-6); % Compute values of x
h = tri((nh-6)/4); % Compute values of h
y = conv(x,h); % Compute the convolution of x with h
ny = (nx(1) + nh(1)) + (0:(length(nx) + length(nh) - 2));
subplot(3,1,1); stem(nx,x,'k','filled');
xlabel('n'); ylabel('x'); axis([-2,20,0,4]);
subplot(3,1,2); stem(nh,h,'k','filled');
xlabel('n'); ylabel('h'); axis([-2,20,0,4]);
subplot(3,1,3); stem(ny,y,'k','filled');
xlabel('n'); ylabel('y'); axis([-2,20,0,4]);
function z = usD(n)
z = double(n >= 0); % Set output to one for non-negative arguments
I = find(round(n) ~= n); % Index non-integer values of n
z(I) = NaN;
end
function d = tri(n)
% Create triangular waveform centered at zero
d = max(1 - abs(n), 0);
end
This should give you the desired convolution plot.

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by