Upsampling Downsampling
Upsampling Downsampling
Upsampling Downsampling
dur = input ('Enter the signal duration'); dur = input ('Enter the signal duration');
L= input('Enter upsampling factor'); L= input('Enter downsampling factor');
fs= 6000; fs= 6000;
ts= 1/fs; ts= 1/fs;
t=(0:ts:dur-1); t=(0:ts:dur-1);
x= (5* cos(400*pi*t))+ (8* cos(600*pi*t)); x= (5* cos(400*pi*t))+ (8* cos(600*pi*t));
figure; figure;
subplot(4,1,1) subplot(4,1,1)
stem(x); stem(x);
axis([0 100 -30 30]) axis([0 100 -30 30])
title('Original signal')' title('Original signal')
xlabel('n') xlabel('n')
ylabel('Amplitude') ylabel('Amplitude')
z= zeros(1, L* length(x)); z= zeros(1, floor(length(x)/L));
z([1:L:length(z)]) = x; z= x([1:L:length(z)]);
subplot(4,1,2) subplot(4,1,2)
stem(z, 'r'); stem(z, 'r');
axis([0 100 -30 30]) axis([0 100 -30 30])
title('Up- Sampled') title('down- Sampled')
xlabel('n') xlabel('n')
ylabel('Amplitude') ylabel('Amplitude')
nfft=1024; nfft=1024;
b=fft(x,nfft); b=fft(x,nfft);
subplot(2,1,1) nval=0:nfft-1;
nval=0:nfft-1; subplot(2,1,1)
plot(nval,abs(b)); plot(nval,abs(b));
title('Original sequence') title('Original sequence')
xlabel('Frequency') xlabel('Frequency')
ylabel('Magnitude') ylabel('Magnitude')
subplot(2,1,2) subplot(2,1,2)
d=fft(z,nfft); d=fft(z,nfft);
plot(nval,abs(d)) plot(nval,abs(d))
title('Upsampled sequence') title('Down_sampled sequence')
xlabel('Frequency') xlabel('Frequency')
ylabel('Magnitude') ylabel('Magnitude')
MOVING AVERAGE FILTER