Gabrian A07

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

3.

Apply a different window to eliminate the Gibbs phenomenon (other than Kaiser)
a. Blackman window

Result of windowing with Blackman


b. Kaiser Window

Result of windowing with Kaiser

c. Comparison of Filter Response

Fig(a). Filter Response with Blackman Window


Fig(b). Filter Response with Kaiser Window
Thus, it is clear that using Kaiser Window will result in Gibbson Phenomenon as there is still
ringing seen on the figure, while using Blackman Window on the signal result in no Gibbson
Phenomenon to be found as the line in the figure shows non straight line and no ringing.

Attachment
Matlab code:
clc, clear all, close all

%% Signal(Time Domain)
F=[300 400 1000 2000]; %frequencies
A=[1 1 3 1];
Fs=6000;
fcll=350;
fclh=800; %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);
M=(N-1)/2;

hideall=(2*fcll/Fs)*sinc(2*fcll/Fs*n_h); %Ideal Lowpass Filter


hidealh=(-2*fclh/Fs)*sinc(2*fclh/Fs*n_h); %Ideal Highpass Filter
hideal=hideall+hidealh;
h=blackman(L)'.*hideal; %h is our filter
n_h2=0:L-1;
figure(1),subplot(3,2,5:6),plot(n_h2,h),xlabel('Time(sampels)'),ylab
el('Amplitude')
title(['Impulse Response of' num2str(fcll) 'Hz Highpass
filter(without Window)L=' num2str(L)])

%% Spectrum of Our Signal and The Filter


N2=L+N-1;
Y = fft(y,N2);
H = fft(h,N2);
A_Y = 2*abs(Y(1:floor(N2/2)))/N;
A_H = 2*abs(H(1:floor(N2/2)))/N;
f = linspace(0,Fs/2,N2/2);

figure(2),title('Amplitude Spectrum')
set(gcf,'Units','Normalized','OuterPosition',[0.5 0.04 0.5 0.96])
subplot(2,2,1),plot(f,A_Y,'r'),title('Original')
ax = axis(gca);
subplot(2,2,3),plot(f,A_H),title('Filter Response')
xlabel('f(Hz)'),ylabel('Amplitude')

%Y_dB = 10*log10((abs(Y(1:floor(N2/2)))));
%H_dB = 10*log10((abs(H(1:floor(N2/2)))));
%figure(10),plot(f,H_dB)
%xlabel('Frequency(Hz)'),ylabel('Amplitude(dB)')
%suptitle([num2str(fcl)'Hz Low-pass Filter (Hann
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)')
%% Applying Filter (Freq domain; Length N)
Y2=fft(y,N);
H2=fft(h,N);
YH2=Y2.*H2;
y2=ifft(YH2);
figure(1),subplot(3,2,3),plot(t,y),%axis(ax2)
hold on,plot(t,y2)
legend('Origin','Filtered (kali, length N)')

You might also like