フィルターのクリア

How do I plot this convolution correctly???

5 ビュー (過去 30 日間)
Poonam
Poonam 2012 年 11 月 2 日
I am trying to plot the following function sinc(x/.2) convolved with rect(x/10)
clc; close all; clear all;
x = linspace(-10,10,1001);
grid
hold;
plot(x,sinc(x/.2)),'r';
plot(x,rect(x/10)),'c';
y=conv(sinc(x/.2),rect(x/10),'full');
axis=(0:length(y)-1)*(x(2)-x(1));
plot(axis,y);
The resultant plot I am getting is shifted to 15. Shouldnt it be between -5 to 5? Thank you
  3 件のコメント
Poonam
Poonam 2012 年 11 月 2 日
Poonam
Poonam 2012 年 11 月 2 日
function out = pulse(in);
out = zeros(size(in)); out = step(in + 1/2) - step(in - 1/2);
This is my rect function

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

採用された回答

Image Analyst
Image Analyst 2012 年 11 月 2 日
No, because the convolved signal is the length of the original signal plus the length of the filter. And you had the values for the new x axis wrong. Try this:
clc;
clearvars;
close all;
imtool close all; % Close all imtool figures.
workspace;
format longg;
format compact;
fontSize = 16;
numberOfElements = 1001;
middleElement = ceil(numberOfElements/2);
x = linspace(-10,10, numberOfElements);
halfWindowWidth = 150;
% Make rectangular pulse.
rect = zeros(1, numberOfElements);
rect(middleElement-halfWindowWidth: middleElement+halfWindowWidth) = 1;
subplot(3, 1, 1);
plot(x, rect,'b-', 'LineWidth', 2);
ylim([0 2]);
grid 'on';
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Make sinc.
subplot(3, 1, 2);
s = sinc(x/2);
plot(x, s, 'b-', 'LineWidth', 2);
grid 'on';
% Convolve
y = conv(s, rect,'full');
predictedLength = length(s)+length(rect)-1
newXAxis = linspace((-10 - halfWindowWidth), (+10 + halfWindowWidth), length(y)) ;
subplot(3, 1, 3);
plot(newXAxis, y, 'b-', 'LineWidth', 2);
grid 'on';
  2 件のコメント
Poonam
Poonam 2012 年 11 月 2 日
clc; close all; clear all;
x = linspace(-10,10,1001);
grid
hold;
a = sinc(x/.2)
plot(x,a),'r';
b = rect(x/10)
plot(x,b),'c';
y=conv(a,b,'full');
axis = linspace((-10 - halfWindowWidth), (+10 + halfWindowWidth), length(y)) ;
%axis=(0:length(y)-1)*(x(2)-x(1));
plot(axis,y);
This is my rect function
function out = pulse(in);
out = zeros(size(in)); out = step(in + 1/2) - step(in - 1/2);
How do I change the axis to suit my code? Thank you so much for your help :)
Image Analyst
Image Analyst 2012 年 11 月 2 日
I'm not sure what you're asking. I already showed you. You need to look at my code. You can't just pull in one of my lines and then modify it like this:
axis = linspace((-10 - halfWindowWidth), (+10 + halfWindowWidth), length(y)) ;
First of all, I defined halfWindowWidth and you did not copy over that part, so of course it's undefined for you. Secondly I carefully chose my variable names, so I used newXAxis instead of axis. You used axis, which just blew away the built in axis() function - NOT a good idea.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by