Sovaa
Newbie level 2
I have a task i need to do but i'm not sure how to filter the signal without using Matlab filter function. Here is the code of the filter:
L =8;
x1 = [ones(1,L/2) -ones(1,L/2)];
%Input Signal
x = [x1 x1 x1 x1 x1 x1];
figure;
subplot(2,1,1);
stem(x, 'g');
title('Input signal in time domain');
X = fft(x,L);
SX = abs(X);
%length(SX)
%pols of linear system
P(1) = exp(j*2*pi*(3/L));
P(2) = conj(exp(j*2*pi*(3/L)));
subplot(2,1,2);
stem(0:L-1,SX , 'g');
title('Amplitude specter of input signal');
%zeros of linear system
Z = [];
for i = 1:L
if SX(i) > 0
Z = [Z exp(j*2*pi*(i-1)/L)];
end;
end;
if L == 8
a = [1 -2*cos(2*pi*(1/8 )) 1];
R = polyval(a,exp(2*pi*j*(3/8 )));
K = 1/abs(R)
[NUM,DEN] = zp2tf(Z.',P.',K)
else
[NUM,DEN] = zp2tf(Z.',P.',1);
y = filter(NUM,DEN,x);
[NUM,DEN] = zp2tf(Z.',P.',1/max);
pojacanje=1/max
end;
y = filter(NUM,DEN,x);
figure;
subplot(2,1,1);
%plot(y, '.');
plot;
title('Filtrated input signal(Time domain)');
I have to get the same result but without using function " filter(NUM,DEN,x)
If anyone can help i would appreciate it very much
L =8;
x1 = [ones(1,L/2) -ones(1,L/2)];
%Input Signal
x = [x1 x1 x1 x1 x1 x1];
figure;
subplot(2,1,1);
stem(x, 'g');
title('Input signal in time domain');
X = fft(x,L);
SX = abs(X);
%length(SX)
%pols of linear system
P(1) = exp(j*2*pi*(3/L));
P(2) = conj(exp(j*2*pi*(3/L)));
subplot(2,1,2);
stem(0:L-1,SX , 'g');
title('Amplitude specter of input signal');
%zeros of linear system
Z = [];
for i = 1:L
if SX(i) > 0
Z = [Z exp(j*2*pi*(i-1)/L)];
end;
end;
if L == 8
a = [1 -2*cos(2*pi*(1/8 )) 1];
R = polyval(a,exp(2*pi*j*(3/8 )));
K = 1/abs(R)
[NUM,DEN] = zp2tf(Z.',P.',K)
else
[NUM,DEN] = zp2tf(Z.',P.',1);
y = filter(NUM,DEN,x);
[NUM,DEN] = zp2tf(Z.',P.',1/max);
pojacanje=1/max
end;
y = filter(NUM,DEN,x);
figure;
subplot(2,1,1);
%plot(y, '.');
plot;
title('Filtrated input signal(Time domain)');
I have to get the same result but without using function " filter(NUM,DEN,x)
If anyone can help i would appreciate it very much