Hi to all:
I have this program. My question is at the end of this program below.
clf;
h=[3 2 1 -2 1 0 -4 0 3];
x=[1 -2 3 -4 3 2 1];
y=conv(h,x);
n=0:14;
subplot(2,1,1);
stem(n,y);
xlabel('Time index n');ylabel('Amplitude');
title('Output Obtained by Convolution');grid;
x1=[x zeros(1,8)];
y1=filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel('Time index n');ylabel('Amplitude');
title('Output Generated by Filtering');grid;
Question 1: How do I determine the correct size of n?
Question 2: In x1=[x zeros(1,a)], what is the value of "a" in relation
to n,h and x? How do I compute "a"?
Thank you...I am new in DSP using Matlab.
Convolution and Filtering
Started by ●January 11, 2007
Reply by ●January 15, 20072007-01-15
when you use stem(n,y) or plot(n,y), the size of the two arguments n and y has
to be equal. In your program, y is a 1X15 array so n has to have the same size
(0-14). similarly, when you want to use stem(n,y1), y1 has to has a size of
1X15. But if you filter x which has a size of 1X7, the result (y1) would also
have a size of 1X7 thus when you want to plot the result with respect to n the
program will give you an error. That is why you add 8 zeros to x so the size of
x is now equal to 1X(7+8)=1X15 which is equal to size of n and then you can plot
it.
I hope I was clear
----- Original Message ----
From: icpower2000
To: m...
Sent: Wednesday, January 10, 2007 5:46:17 PM
Subject: [matlab] Convolution and Filtering
Hi to all:
I have this program. My question is at the end of this program below.
clf;
h=[3 2 1 -2 1 0 -4 0 3];
x=[1 -2 3 -4 3 2 1];
y=conv(h,x);
n=0:14;
subplot(2,1, 1);
stem(n,y);
xlabel('Time index n');ylabel(' Amplitude' );
title('Output Obtained by Convolution' );grid;
x1=[x zeros(1,8)];
y1=filter(h, 1,x1);
subplot(2,1, 2);
stem(n,y1);
xlabel('Time index n');ylabel(' Amplitude' );
title('Output Generated by Filtering'); grid;
Question 1: How do I determine the correct size of n?
Question 2: In x1=[x zeros(1,a)], what is the value of "a" in relation
to n,h and x? How do I compute "a"?
Thank you...I am new in DSP using Matlab.
I hope I was clear
----- Original Message ----
From: icpower2000
To: m...
Sent: Wednesday, January 10, 2007 5:46:17 PM
Subject: [matlab] Convolution and Filtering
Hi to all:
I have this program. My question is at the end of this program below.
clf;
h=[3 2 1 -2 1 0 -4 0 3];
x=[1 -2 3 -4 3 2 1];
y=conv(h,x);
n=0:14;
subplot(2,1, 1);
stem(n,y);
xlabel('Time index n');ylabel(' Amplitude' );
title('Output Obtained by Convolution' );grid;
x1=[x zeros(1,8)];
y1=filter(h, 1,x1);
subplot(2,1, 2);
stem(n,y1);
xlabel('Time index n');ylabel(' Amplitude' );
title('Output Generated by Filtering'); grid;
Question 1: How do I determine the correct size of n?
Question 2: In x1=[x zeros(1,a)], what is the value of "a" in relation
to n,h and x? How do I compute "a"?
Thank you...I am new in DSP using Matlab.
Reply by ●January 15, 20072007-01-15
to answer your first question:
convolution results in n = length(x)+length(y) - 1 where x and y are one dimensional vectors.
about the 2nd question
in matlab 'filter' results in an output with the same length as the input or filter whichever is greater. if the input is shorter than the filter length zeros are appended(provided input and filter start at 0 time index).
i think what you are doing is, making sure that when u compare the result of 'conv' and 'filter' ouputs, you get exactly same values as yor output. hope this helps
icpower2000 wrote:
Hi to all:
I have this program. My question is at the end of this program below.
clf;
h=[3 2 1 -2 1 0 -4 0 3];
x=[1 -2 3 -4 3 2 1];
y=conv(h,x);
n=0:14;
subplot(2,1,1);
stem(n,y);
xlabel('Time index n');ylabel('Amplitude');
title('Output Obtained by Convolution');grid;
x1=[x zeros(1,8)];
y1=filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel('Time index n');ylabel('Amplitude');
title('Output Generated by Filtering');grid;
Question 1: How do I determine the correct size of n?
Question 2: In x1=[x zeros(1,a)], what is the value of "a" in relation
to n,h and x? How do I compute "a"?
Thank you...I am new in DSP using Matlab.
Amit Pathania
convolution results in n = length(x)+length(y) - 1 where x and y are one dimensional vectors.
about the 2nd question
in matlab 'filter' results in an output with the same length as the input or filter whichever is greater. if the input is shorter than the filter length zeros are appended(provided input and filter start at 0 time index).
i think what you are doing is, making sure that when u compare the result of 'conv' and 'filter' ouputs, you get exactly same values as yor output. hope this helps
icpower2000 wrote:
Hi to all:
I have this program. My question is at the end of this program below.
clf;
h=[3 2 1 -2 1 0 -4 0 3];
x=[1 -2 3 -4 3 2 1];
y=conv(h,x);
n=0:14;
subplot(2,1,1);
stem(n,y);
xlabel('Time index n');ylabel('Amplitude');
title('Output Obtained by Convolution');grid;
x1=[x zeros(1,8)];
y1=filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel('Time index n');ylabel('Amplitude');
title('Output Generated by Filtering');grid;
Question 1: How do I determine the correct size of n?
Question 2: In x1=[x zeros(1,a)], what is the value of "a" in relation
to n,h and x? How do I compute "a"?
Thank you...I am new in DSP using Matlab.
Amit Pathania