Frequency Domain Analysis of Signals: Task Problem

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

Due Date: 23.09.

2021 DSP TASK -02 Max Marks: 10

Date of Submission: Lab Slot: L51+L52

Name: DINESH HANUMATH KUMAR Reg.No: 19BEC0355

FREQUENCY DOMAIN ANALYSIS OF SIGNALS


Objective:
To use MATLAB for Spectral analysis of Signals and Systems.

TASK PROBLEM

Practice FFT on MATLAB with the following source signals, and display the
amplitude spectrum:
1. 𝒙[𝒏] = 𝐬𝐢𝐧 [𝟒𝟎 𝝅𝒏/𝒇𝒔] + 𝐜𝐨𝐬 [𝟏𝟎𝟎 𝝅𝒏/𝒇𝒔+𝟐𝝅/𝟑] + 𝐬𝐢𝐧 [𝟏𝟎𝟎𝟎 𝝅𝒏/𝒇𝒔+𝟒𝝅/𝟓]
Where 𝒇𝒔 is the sampling rate, 𝒏 = 𝟏 ∶ 𝒇𝒔 and 𝒇𝒔 = 𝟐𝟎𝟎

Ans.) MATLAB CODE:


% DINESH HANUMATH KUMAR 19BEC0355
clear all
syms n;
fs = 200; n = 1:fs;
deltaf = fs/200;
x = sin((40*pi*n)/fs) + cos(((100*pi*n)/fs)+(2*pi/3)) +
sin(((1000*pi*n)/fs)+(4*pi/5));
f = [0:199]*deltaf;
Xf = fft(x);
figure
subplot(2,1,1)
stem(n,x)
title('Given signal x[n]');
xlabel('n'); ylabel('x[n]');
subplot(2,1,2)
stem(f,abs(Xf));
title('Amplitude Spectrum');
xlabel('f'); ylabel('X(f)');
OUTPUT GRAPH:
2.) Use MATLAB function ‘𝒂𝒖𝒅𝒊𝒐𝒓𝒆𝒂d’, to read a piece of music (wave
or mp3 format).Note: the music should be relatively harmonic, e.g.
some bird sound, pure music instrument play, etc. Or you can first use
‘𝒂𝒖𝒅𝒊𝒐𝒘𝒓𝒊𝒕𝒆’to generate a 1-second piece of music first.
Ans.) MATLAB CODE:
% DINESH HANUMATH KUMAR 19BEC0355
close all;
clear all;
birdFile ='BirdSound.wav';
[x,fs] = audioread(birdFile);
subplot(3,1,1);
plot(x);
xlabel('Sample Number');
ylabel('Amplitude');
title('Sample Signal');
chirping = x(2.45e4:3.10e4);
t = 10*(0:1/fs:(length(chirping)-1)/fs);
subplot(3,1,2);
plot(t, chirping);
xlabel('Time (Seconds)');
ylabel('Amplitude');
title('Single Chirp');
xlim([0 t(end)]);
m = length(chirping);
n = pow2(nextpow2(m));
y = fft(chirping,n);
f = (0:n-1)*(fs/n)/10;
power = abs(y).^2/n;
subplot(3,1,3);
plot(f(1:floor(n/2)),power(1:floor(n/2)));
xlabel('Frequency');
ylabel('Power');
title('Power Spectrum');
OUTPUT GRAPH:

You might also like