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

UP-SAMPLING OF A SINUSOIDAL INPUT SEQUENCE USING MATLAB

MATLAB CODE:-

clear all;
clc;
N=3.5; %length of sinusoidal sequence
L=3; %length of upsampling factor
n=0:0.01:N-1;
x=sin(2*pi*n);
y=zeros(1,L*length(x));
y([1:L:length(y)])=x;
subplot(2,1,1);
stem(n,x);
xlabel('Time'); ylabel('Amplitude');
title('Input Signal');
subplot(2,1,2);
stem(n,y(1:length(x)));
xlabel('Time');
ylabel('Amplitude');
title('Upsampling');
DOWN-SAMPLING OF A SINUSOIDAL INPUT SEQUENCE USING MATLAB

MATLAB CODE:-
clear all;
clc;
N=4; %length of sinusoidal sequence
M=2; %downsampling factor
n=0:0.05:N-1;
x=sin(2*pi*n);
y=x([1:M:length(x)]);
subplot(2,1,1);
stem(n,x);
xlabel('Time'); ylabel('Amplitude');
title('Input Signal');
subplot(2,1,2);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('Down Sampling');
UP-SAMPLING IN THE FREQUENCY DOMAIN

MATLAB CODE:-

clc;
freq=[0 0.45 0.5 1];
mag=[0 1 0 0];
x=fir2(99, freq, mag);
[Xz,w]=freqz(x,1,512);
subplot(2,1,1)
plot(w/pi, abs(Xz)); grid on
xlabel('\omega/\pi');ylabel('Magnitude');
title('Input Spectrum');
L=5; % up-sampling factor
y=zeros(1,L*length(x));
y([1:L:length(y)])=x;
[Yz, w]=freqz(y,1,512);
subplot(2,1,2)
plot(w/pi,abs(Yz)); grid
xlabel('\omega/\pi');ylabel('Magnitude');
title('Output Spectrum');

Generated Input And Output Spectrum Of A Factor Of 5 Up-Sampler:-


DOWN-SAMPLING IN THE FREQUENCY DOMAIN

MATLAB CODE:-
clc;
freq=[0 0.42 0.48 1];
mag=[0 1 0 0];
x=fir2(101, freq, mag);
[Xz,w]=freqz(x,1,512);
subplot(2,1,1)
plot(w/pi, abs(Xz));grid
xlabel('\omega/\pi');ylabel('Magnitude');
title('Input Spectrum');
M=2; % down-sampling factor
y=x([1:M:length(x)]);
[Yz,w]=freqz(y,1,512);
subplot(2,1,2)
plot(w/pi,abs(Yz));grid
xlabel('\omega/\pi');ylabel('Magnitude');
title('Output Spectrum');

Generated Input And Output Spectrum Of A Factor Of 2 Down-Sampler:-


DESIGN A LINEAR PHASE LOWPASS FILTER USING THE WINDOWED
FOURIER SERIES WITH A HAMMING WINDOW. (N=23, L=2)

MATLAB CODE:-
N=23; % the filter order
L=2; % value of L
n=-N/2:N/2;
b=sinc(n/L)/L;
win=hamming (N+1);
c=b.*win';
[h,w]=freqz(c,1,512);
plot(w/pi,20*log10(abs(h))); grid
xlabel('\omega/\pi'); ylabel('Gain,dB');
title(['L-th band Nyquist Filter,L=',num2str(L),]);

Gain Response Of A Length-23 Linear-phase Half-band FIR Filter:-

You might also like