Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

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

dur = input ('Enter the signal duration');


L= input('Enter L factor');
fs= 6000;
ts= 1/fs;
t=(0:ts:dur-1);
x= (5* cos(400*pi*t))+ (8* cos(600*pi*t));
figure;
subplot(3,1,1)
stem(x);
axis([0 100 -30 30])
z= zeros(1, L*length(x));
z([1:L:length(z)]) =x;
subplot(3,1,2)
stem(z, 'r');
axis([0 100 -30 30])
title('Up- Sampled')
xlabel('n')
ylabel('Amplitude')
M=3;
for(i=4:length(z))
if i>M
zz(i)= (1/M) *( (z(i-3)) +
(z(i-2)) (z(i-1)) );
else
zz(i) = z(i);
end
end
subplot(3,1,3)
stem(zz);
axis([0 100 -30 30])
title('Moving Average filter signal')
xlabel('n')
ylabel('Amplitude')
nfft=1024;
b=fft(x,nfft);
subplot(2,1,1)
nval=0:nfft-1;
plot(nval,abs(b));
title('Up-sampled sequence')
xlabel('Frequency')
ylabel('Magnitude')
subplot(2,1,2)
d=fft(z,nfft);
plot(nval,abs(d))
title(' 'Moving Average filter signal ')
xlabel('Frequency')
ylabel('Magnitude')

You might also like