Use MATLAB built-in function conv() to compute and plot y[n]

3 visualizaciones (últimos 30 días)
CHENG-YI LI
CHENG-YI LI el 28 de Oct. de 2018
Respondida: asad ali el 1 de Mayo de 2021
my code is: clear all; close all; clc;
%first sequence x=[0, 1, 1, 1, 0, 0, 0]; %second sequence h=[1, 2, 4, 8, 16, 32, 64];
%built-in function
y= conv(x,h); disp('The convolution output is'); disp(y); and the command window is: >> k=[0, 1, 1, 1, 0, 0, 0]; >> >> y=[1, 2, 4, 8, 16, 32, 64]; >> >> z= conv(k,y); >> >> disp(z) 0 1 3 7 14 28 56 112 96 64 0 0 0
>> subplot(6,1,1);plot(k);subplot(6,1,2);plot(y);subplot(6,1,3);plot(z); >> subplot(6,1,1);stem(k);subplot(6,1,2);stem(y);subplot(6,1,3);stem(z); My problem is that the figure "欲2" where I make the code doesn't match the figure "欲" which the question gives. I have no idea if my code and the final figure"欲2" is right.
  5 comentarios
CHENG-YI LI
CHENG-YI LI el 28 de Oct. de 2018
May you help me solve the problem?

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 28 de Oct. de 2018
Editada: Bruno Luong el 28 de Oct. de 2018
I don't see what is the difficulty for you.
MATLAB array is 1-indexing, and CONV just do the work on array indices.
If you know the correspondence between indices and the [n] value, which obviously 0-base, therefore equal to (matlab indices-1), just shift the indices and plot with 2 arguments.
x = ...
h = ...
y = conv(x,h);
subplot(3,1,1);
stem(0:length(x)-1,x);
subplot(3,1,2);
stem(0:length(h)-1,h)
subplot(3,1,3);
stem(0:length(y)-1,y)

Más respuestas (1)

asad ali
asad ali el 1 de Mayo de 2021
x = ...
h = ...
y = conv(x,h);
subplot(3,1,1);
stem(0:length(x)-1,x);
subplot(3,1,2);
stem(0:length(h)-1,h)
subplot(3,1,3);
stem(0:length(y)-1,y)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by