%  down sampling
% 
clear all, close all
%  S??n??rl?? bantl?? sinyal ??retme k??sm??
% ????arete ili??kin frekans band??
F = [0,0.1,0.46,1]; A=[0,1,0,0]; 
% i??aretin tekrar ??retilmesi
x =  fir2(256,F,A); 
% i??aretin frekans spekturumunun bulunmas??
X = fft(x,1024); 
f = 0:1/1024:(512-1)/1024; % frekanslar??n normalizasyonu
figure (1)
subplot(5,1,1), plot(f,abs(X(1:512))), legend('Orijinal')
ylabel('|X(e^j^\omega)|')

M = 2; % Down-sampling factor
y2 = x(1:M:256); % Down-sampling
Y2 = fft(y2,1024); % downsample edilmi?? i??arete ili??kin spec.
subplot(5,1,2), plot(f,abs(Y2(1:512))),legend('Decimation 2')
ylabel('|Y_2(e^j^\omega)|')

M = 3; % Down-sampling factor
y3 = x(1:M:256); % Down-sampling
Y3 = fft(y3,1024); % downsample edilmi?? i??arete ili??kin spec.
subplot(5,1,3), plot(f,abs(Y3(1:512))),legend('Decimation 3'); 
ylabel('|Y_3(e^j^\omega)|')

L = 2; % Up-sampling factor
y2_up = zeros(1,L*length(x));
y2_up([1:L:length(y2_up)]) = x; % Up-sampled signal, L=2 Basics of Multirate Systems
Y2_up = fft(y2_up,1024); % Computing the spectrum of the up-sampled signal 
subplot(5,1,4), plot(f,abs(Y2_up(1:512)))
ylabel('|Y_2(e^j^\omega)|'), legend('Interpolation 2')

L = 3; % Up-sampling factor
y3_up = zeros(1,L*length(x));
y3_up([1:L:length(y3_up)]) = x; % Up-sampled signal, L=3 Basics of Multirate Systems
Y3_up = fft(y3_up,1024); % Computing the spectrum of the up-sampled signal 
subplot(5,1,5), plot(f,abs(Y3_up(1:512)))
ylabel('|Y_2(e^j^\omega)|'), legend('Interpolation 3')