You are on page 1of 7

Digital Signal Processing

Task - 3
Slot: L5+L6

Team :

22BEC0962 - Pugalarasu M

22BEC0722 - G B Hitesh Vaibhav

22BEC731 - Sri Saradaa K

22BEC0389 - Varun M

1
Question 1 :

Code :

clc;
clear
all;
close
all; %
Given
fs=1000;% Sampling Frequency
dur=2; % Time duriation
t=0:(1/fs):dur-(1/fs);

% Plot 1
x=sin(2*pi*150*t);% sine wave
subplot(411); plot(t,x);
title('Sin Wave');ylabel('Amplitude');xlabel('Time');

% Plot 2 k=0:4095; dft=fft(x,4096);


% Dft of Sine wave f=k*1000/4096;
subplot(412); plot(f,abs(dft));
title('Magnitude');ylabel('Amplitude');xlabel('Frequency');

% Plot 3
xrt1=ifft(dft,4096);% inverse Dft
xrt=xrt1([1:length(x)]);
subplot(413);
plot(t,xrt);
title('Reconstucted sine wave');ylabel('Amplitude');xlabel('Time');

% Plot 4 subplot(414); plot(t,(x-xrt)); % Error between Original sine wave


and
Reconstructed wave title('Error');ylabel('Amplitude');xlabel('Time');

2
Question 2 :

Code :
clc; clear all; close all; % Given
fs=1000; % Sampling Frequencey dur=2;
% Time Duriation t=0:(1/fs):dur-
(1/fs); % Time

% Plot 1
x=sin(2*pi*150*t); % sine Wave
subplot(411); plot(t,x); title('Sin
Wave');ylabel('Amplitude');xlabel('Ti
me');

% Plot 2 k=0:4095; dft=fft(x,4096);% Dft of sine wave f=k*(1000/4096);


ndft=[abs(dft(1:2048)) zeros(1,2048)];% Only Frequency from 0 to Fs/2
subplot(412); plot(f,ndft);
title('Magnitude');ylabel('Amplitude');xlabel('Frequency');

% Plot 3
xrt1=ifft(dft,4096);% Inverse Dft , Reconstruction
xrt=xrt1([1:length(x)]); subplot(413); plot(t,xrt); title('Reconstucted
sine wave');ylabel('Amplitude');xlabel('Time');

3
% PLot 4 subplot(414); plot(t,(x-xrt));% Error Between original sine
and Reconstructed wave
title('Error');ylabel('Amplitude');xlabel('Time');

Question 3 :

Code :

4
clc; clear
all; close
all;

% Given frequencies=[100,200,400,600,800,1000,1200,1400];
%
Frequencies fs=5000; % Sampling frequency duration=0.1; %
Duration t=0:1/fs:duration; % Time sum_sine_wave =
zeros(size(t));

% Construct of sine wave with different frequencies and sum it up


for i=1:length(frequencies) xi=sin(2*pi*frequencies(i)*t);
sum_sine_wave = sum_sine_wave + xi; end

% Plot 1 subplot(411);
plot(t,sum_sine_wave);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time Domain Representation of Sum of Sine Waves');

% DFT of the signal


N=1024; % Number of points for DFT
X=fft(sum_sine_wave, N); % Compute DFT
frequencies_dft=(0:N-1)*fs/N; % Frequency axis for DFT

% Plot 2 subplot(412);
plot(frequencies_dft,abs(X));
xlabel('Frequency (Hz)'); ylabel('Magnitude');
title('Magnitude Response of Signal (DFT)');

% frequencies between 800 Hz and 1000 Hz f_cutoff_low=800; % Lower cutoff


frequency f_cutoff_high=1000; % Upper cutoff frequency
ideal_filter=(frequencies_dft>=f_cutoff_low&frequencies_dft<=f_cutoff_high);
% Ideal filter
filtered_signal=ifft(X .* ideal_filter');

% Plot 3 subplot(413);
plot(t,real(filtered_signal(1:length(t))));
xlabel('Time (s)'); ylabel('Amplitude');
title('Time Domain Filtered Signal (800 Hz to 1000 Hz)');

5
% DFT of the filtered signal
filtered_signal_dft = fft(filtered_signal, N);

% Plot 4 subplot(414); plot(frequencies_dft, abs(filtered_signal_dft));


xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('Magnitude Response
of Filtered Signal (DFT)');

Inference
Question 1:

• Learnt how to get the magnitude of the given wave using the function fft().
• Learnt how to get back the original signal from transformed signal using the function ifft().
• Learnt that there is always an error between the original signal and the reconstructed one.

Question 2:

• Learnt how to get the magnitude of given wave using the function fft().
• Learnt how to get back the original signal from transformed signal using the function ifft().
• Learnt how to get response for a particular range of frequency from the original response.

6
Question 3:

• Learnt how to generate a signal which is the sum of signals each with different frequencies.
• Learnt how to get the time domain signal for a particular range of frequency (filter).
• And to get magnitude response of that filtered signal.

You might also like