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

Name : Palepu Sai Sri Harsha (BL.EN.

U4EIE18029)
K.Gowtham (BL.EN.U4EIE18019)
Jagan M (BL.EN.U4EIE18018)
Course : Signal Processing Lab
Course code : 15EIE381
Date : 24 April 2021

--------------------------

Problem Statement: (in brief)


Three sinusoid signals with frequency 9KHz, 5KHz, 2KHz respectively
and amplitude of 4, 4, 3 respectively are given. All three signals undergo
sampling (with respect to Nyquist sampling theorem).
A FIR filter has to be designed such that it rejects frequency components above
7KHz using rectangular window function. The concatenated signal is given to
the FIR filter and input and output responses of the filter are being plotted.
As the last part of the design process Y(k) {which is the summation of the filter
output and the output of the delay element as depicted below}is plotted and has
to be observed

Block Diagram given:


Source code:

clc;

clear;

close all;

%signal 1
fs1 = 27000; %sampling frequency - taken as per Nyquist sampling theorm
n1 = (-1/900)*fs1:1:(1/900)*fs1;
t1 = (-1/10000):(1/180000):(1/10000);
ts1 = 1/fs1;
figure(1)
xt1 = 4*sin(2*pi*9000*t1);
subplot(2,1,1);
plot(t1,xt1); %continous plot
xlabel('time')
ylabel('amplitude')
title('input signal - x1(t)')
legend('continous time plot')
grid on;

xn1 = 4*sin(2*pi*9000*n1*ts1);
subplot(2,1,2);
stem(n1,xn1); %discrete plot
xlabel('n - discrete time')
ylabel('amplitude')
title('input signal - x1(t)')
legend('discrete time plot')
grid on;

%signal 2
fs2 = 15000; %sampling frequency
n2 = (-1/500)*fs2:1:(1/500)*fs2;
figure(2)
xt2 = 4*sin(2*pi*5000*t1);
subplot(2,1,1);
plot(t1,xt2); %continous plot
xlabel('time')
ylabel('amplitude')
title('input signal - x2(t)')
legend('continous time plot')
grid on;

xn2 = 4*sin(2*pi*5000*n2*ts1);
subplot(2,1,2);
stem(n2,xn2); %discrete plot
xlabel('n - discrete time')
ylabel('amplitude')
title('input signal - x2(t)')
legend('discrete time plot')
grid on;

%signal 3
fs3 = 12000; %sampling frequency
n3 = (-1/400)*fs3:1:(1/400)*fs3;
figure(3)
xt3 = 3*sin(2*pi*2000*t1);
subplot(2,1,1);
plot(t1,xt3); %continous plot
xlabel('time')
ylabel('amplitude')
title('input signal - x3(t)')
legend('continous time plot')
grid on;

xn3 = 3*sin(2*pi*2000*n3*ts1);
subplot(2,1,2);
stem(n3,xn3); %discrete plot
xlabel('n - discrete time')
ylabel('amplitude')
title('input signal - x3(t)')
legend('discrete time plot')
grid on;

%----------------------design of the fir filter----------------%


N=71;
wc=0.77*pi; %18,00,000Hz is the overall sampling frequency
w=0:0.01:pi;
n=0:1:N-1;
eps=0.001;
alpha=(N-1)/2;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
wr=boxcar(N);
h_filter=hd.*wr';
figure
freqz(h_filter, 1, w)

%designing the inputs


%x1(n) is given a gain of 6
gained_xn1 = xn1 * 6;
%this new input needs concatination with x2(n)
input_fir = gained_xn1 + xn2;

filter_output = filter(h_filter,1,input_fir)
%--------------------------------------------------------------------------
%--------------------------------------------------------------------------
%output of the fir filt`er designed above
%plotting the input and output responses of the filter
Y = fft(filter_output);
N1=length(xn1)-1;
k=0:length(Y)-1;
figure(5)
subplot(2,1,2) %output
stem(k*fs1/N1,abs(Y));
xlabel('Frequency(Hz)');
ylabel('Magnitude');
title('Filter Output Response');
grid;

subplot(2,1,1) %input
input_fft = fft(input_fir);
k1=0:length(input_fft)-1;
subplot(2,1,1)
stem(k1*fs1/N1,abs(input_fft));
xlabel('Frequency(Hz)');
ylabel('Magnitude');
title('Filter Input Response');
grid on;

%-------------------------design of the delay element----------------------


%x(n) -> x(n-2)
%delay in the impulse signal - h(n-no)
h = delta(n3-2); %function call--refer the function script
%---------delay input is x3(n) = 3*sin(2*pi*2000*n3*ts3)-------
disp('delay_input')
xn3 = 3*sin(2*pi*2000*n3*ts1)
delay_output = conv(xn3, h, 'same') % 'same' means convertion of same order
%------------------------concatinate the delay output and %y(n)------------
concat_signal = delay_output + filter_output;

%fft of the input - 'concat_signal' as stated in the block diagram


yk = fft(concat_signal);
figure(6)
stem(k1*fs1/N1,abs(yk));
xlabel('Frequency(Hz)');
ylabel('Magnitude');
title('y(k) - Magnitude response');
grid on;

Functions used in the above script:


o filter – it takes in the specifications of the filter and input of
the filter as attributes and provides output of the filter.
o delta – it is a user defined function which helps us to attain
the required delay.

Outputs:
Figure windows: Depicts input signal in time domain in continuous as well as
in discrete domain, Filter input and Filter output responses, Frequency response
of the FIR Filter Designed, Y(k) – Magnitude Response.

Command Window: Input and output of delay element that has been designed.
Input Signal:
Frequency response of the FIR Filter Design:
Input and Output of the FIR Filter:

y(k) – Magnitude response:


Response in Command window:
delay_input

xn3 =

Columns 1 through 7

-2.9544 -2.4064 -1.3464 0.0000 1.3464 2.4064 2.9544

Columns 8 through 14

2.8740 2.1821 1.0261 -0.3483 -1.6485 -2.5981 -2.9949

Columns 15 through 21

-2.7546 -1.9284 -0.6918 0.6918 1.9284 2.7546 2.9949

Columns 22 through 28

2.5981 1.6485 0.3483 -1.0261 -2.1821 -2.8740 -2.9544

Columns 29 through 35

-2.4064 -1.3464 0 1.3464 2.4064 2.9544 2.8740

Columns 36 through 42

2.1821 1.0261 -0.3483 -1.6485 -2.5981 -2.9949 -2.7546


Columns 43 through 49

-1.9284 -0.6918 0.6918 1.9284 2.7546 2.9949 2.5981

Columns 50 through 56

1.6485 0.3483 -1.0261 -2.1821 -2.8740 -2.9544 -2.4064

Columns 57 through 61

-1.3464 -0.0000 1.3464 2.4064 2.9544

delay_output =

Columns 1 through 7

0 0 -2.9544 -2.4064 -1.3464 0.0000 1.3464

Columns 8 through 14

2.4064 2.9544 2.8740 2.1821 1.0261 -0.3483 -1.6485

Columns 15 through 21

-2.5981 -2.9949 -2.7546 -1.9284 -0.6918 0.6918 1.9284


Columns 22 through 28

2.7546 2.9949 2.5981 1.6485 0.3483 -1.0261 -2.1821

Columns 29 through 35

-2.8740 -2.9544 -2.4064 -1.3464 0 1.3464 2.4064

Columns 36 through 42

2.9544 2.8740 2.1821 1.0261 -0.3483 -1.6485 -2.5981

Columns 43 through 49

-2.9949 -2.7546 -1.9284 -0.6918 0.6918 1.9284 2.7546

Columns 50 through 56

2.9949 2.5981 1.6485 0.3483 -1.0261 -2.1821 -2.8740

Columns 57 through 61

-2.9544 -2.4064 -1.3464 -0.0000 1.3464

Result: Therefore, implementation of the block diagram is studied and done


using the given conditions with the help of MATLAB.

You might also like