Octave/Matlab problem with filters

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

Fedechiar
Posts: 44
Joined: Sat Jan 29, 2011 10:35 pm UTC

Octave/Matlab problem with filters

Postby Fedechiar » Sun May 20, 2012 5:54 pm UTC

Hello everyone, I'm trying to plot a filter's response for a signals class assignment and I find a weird error: the code in here
Spoiler:
close all
clear all
clc
t0=0.1;
Omega=0.1;
N=50;
omega=-N:Omega:N;
T=50;
t=-T:t0:T;
function y=ustep(t)
y= t>0;
end
%Sinc function provided by the teacher
function y=sinc(t)
N=length(t);
y=zeros(N,1);
for k=1:N
if t(k)==0
y(k)=1;
else
y(k)=sin(pi*t(k))/(pi*t(k));
end
end
D=size(t);
if D(1)==1
y=y';
end
end
x=cos(3*t).*exp(-2*t).*ustep(t);
X=zeros(1,length(omega));
for(k=1:length(t))
X=X+t0*x(k)*exp(-j*omega*t(k));
end
alfa1=4;
alfa2=10;
h1=alfa1/pi*sinc(alfa1*t/pi);
%h2=sin(alfa1*t)./(pi*t);
h2=alfa2/pi*sinc(alfa2*t/pi);
ha1=zeros(1,length(t));
ha2=zeros(1,length(t));
Tl=20;
H1=zeros(1,length(t));
H2=zeros(1,length(t));
for(k=1:length(t))
if(t(k)>0) & (t(k)<2*Tl)
ha1(k)=h1(k-(Tl/t0));
ha2(k)=h2(k-(Tl/t0));
end
end
for(k=1:length(t))
H1=H1+t0*ha1(k)*exp(-j*omega*t(k));
H2=H2+t0*ha2(k)*exp(-j*omega*t(k));
end
y=conv(h1,x);
y1=conv(x,ha1);
y2=conv(x,ha2);
y1=[y1(floor(length(t)/2)-1:3*floor(length(t)/2)-1)];
y2=[y2(floor(length(t)/2)-1:3*floor(length(t)/2)-1)];
Y1=zeros(1,length(omega));
Y2=zeros(1,length(omega));
for(k=1:length(t))
Y1=Y1+t0*y1(k)*exp(-j*omega*t(k));
Y2=Y2+t0*y2(k)*exp(-j*omega*t(k));
end
gives the correct output if I calculate y's Fourier transforms by multiplying H and X (convolution theorem), but if I get at the Fourier transform from the resulting signal y (as the assignment tells me to) the filtered Y is about 10 times bigger than the original X. I've tried just about everything short of brutally dividing Y by 10; the signal y seems to be also multiplied by 10, and I can't figure out why. Can you help me? Thanks in advance :)

Oh, if it may help, I'm using QtOctave 0.9.2 in a Debian (Gnome) system


Edit: got it, when I calculate y's FT I have to multiply by t0^2 and not simply by t0 (is this because of the convolution? If anyone can give me a theoretical explanation for this, I'd be really grateful

Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 2 guests