Sunteți pe pagina 1din 5

LOW PASS

%% Signal (Time Domain)


F = [ 300 400 1000 2000 ]; % frequencies
A = [1 1 3 1];
Fs = 6000;
fc=350; %Frequency cutoff
N = 0.05*Fs;
t = 0:1/Fs:(N-1)/Fs;
y=0;
for j=1:length(F)
y=y+A(j)*cos(2*pi*F(j)*t);
end
figure(1),subplot(3,2,1),plot(t,y)
title('Sinyal asli'), xlabel('time (s)'),ylabel('y(t)'),
ax2=axis(gca);
set(gcf,'Units','Normalized','OuterPosition',[0 0.04 0.5 .96])
% axis([min(t) max(t) min(y) max(y)])

%% Filter parameters:
L = N+1; % filter length
n_h = (-(L-1)/2:(L-1)/2);

hideal = (2*fc/Fs)*sinc(2*fc/Fs*n_h); % Ideal Lowpass Filter

% hideal = (-2*fc/Fs)*sinc(2*fc/Fs*n_h); % Ideal Highpass Filter


% hideal(ceil(L/2)) = (pi-2*pi*fc/Fs)/pi; % Untuk Highpass. Kalo tidak di off
kan saja

h = kaiser(L,10)' .* hideal; % h is our filter


% h = hideal; %This non-windowed filter will results Gibbs Phenomenon
n_h2=0:L-1;
figure(1),subplot(3,2,5:6),plot(n_h2,h), xlabel('Time (samples)'),
ylabel('Amplitude')
title(['Impulse Response of ' num2str(fc) 'Hz Lowpass filter (without Window)
L = ' num2str(L)])
%% Applying Filter (Way 1 : time domain; Convolution)
hy=conv(h,y);
HY=fft(hy,N2);
A_HY=2*abs(HY(1:floor(N2/2)))/N;
figure(2), subplot(2,2,4)
plot(f,A_HY), title('Filtered (Convolution)'), axis(ax)

y2_conv=ifft(HY,N2);
t2_conv = 0:1/Fs:(N2-1)*(1/Fs);
figure(1),subplot(3,2,2), plot(t,y), %axis(ax2)
hold on,plot(t2_conv,y2_conv)
legend('Origin','Filtered (conv)')

%% Applying Filter (Way 2 : Frequency domain)


YH = Y.*H;
A_YH = 2*abs(YH(1:floor(N2/2)))/N;
figure(2),subplot(2,2,2),plot(f,A_YH,'k')
title('Filtered (kali)')
axis(ax)

y2_kali=ifft(YH,N2);
t2_kali = 0:1/Fs:(N2-1)*(1/Fs);
figure(1),subplot(3,2,4),plot(t,y),
hold on, plot(t2_kali,y2_kali),%axis(ax2)
legend('Origin','Filtered (kali)')
%% Removing delay
delay = mean(grpdelay(Hd));
t_fdesignlow2=t(1:end-floor(delay));
y_fdesignlow2=y_fdesignlow(floor(delay)+1+length(nol):end-
length(nol)+floor(delay));
figure(101),subplot(2,1,2)
plot(y_fdesignlow),hold on, plot(y_fdesignlow2)
title('fdesign.lowpass : With Zero Padding'),legend('Moved delay','Still
delayed')
HIGH PASS FILTER

%% Filter parameters:
L = N+1; % filter length
n_h = (-(L-1)/2:(L-1)/2);

hideal = (-2*fc/Fs)*sinc(2*fc/Fs*n_h); % Ideal Highpass Filter

% hideal = (-2*fc/Fs)*sinc(2*fc/Fs*n_h); % Ideal Highpass Filter


% hideal(ceil(L/2)) = (pi-2*pi*fc/Fs)/pi; % Untuk Highpass. Kalo tidak di off
kan saja

h = kaiser(L,10)' .* hideal; % h is our filter


% h = hideal; %This non-windowed filter will results Gibbs Phenomenon
n_h2=0:L-1;
figure(1),subplot(3,2,5:6),plot(n_h2,h), xlabel('Time (samples)'),
ylabel('Amplitude')
title(['Impulse Response of ' num2str(fc) 'Hz HIGHpass filter (without
Window)
L = ' num2str(L)])

S-ar putea să vă placă și