[go: up one dir, main page]

0% found this document useful (0 votes)
50 views6 pages

M Lab Report 2

The document is a lab report submitted by two students containing code and output for 4 tasks involving digital signal processing functions in MATLAB. The tasks include: 1) Writing a function to generate a sinusoidal sequence; 2) Writing a function to calculate the energy and average power of a sequence; 3) Writing a function to generate unit step and unit impulse sequences; 4) Writing a function to read a sound file, plot samples of it, and play it back.

Uploaded by

marryam nawaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views6 pages

M Lab Report 2

The document is a lab report submitted by two students containing code and output for 4 tasks involving digital signal processing functions in MATLAB. The tasks include: 1) Writing a function to generate a sinusoidal sequence; 2) Writing a function to calculate the energy and average power of a sequence; 3) Writing a function to generate unit step and unit impulse sequences; 4) Writing a function to read a sound file, plot samples of it, and play it back.

Uploaded by

marryam nawaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DSP

LAB REPORT # 2
Submitted By:
Marryam Nawaz
SP-12-BET-043
Hifza Sajid
SP-12-BET-029
Submitted To:
Sir Mobeen Sabir
Class Instructor:
Sumayya Haroon
Class:
BET-5A
Dated:
07/03/2014
TASK NO 1:
WRITE A FUNCTION WHICH TAKES FREQUENCY ‘FM’, SAMPLING FREQUENCY ‘FS’ AND THE NO. OF
SAMPLES ‘N’ AS THE INPUT ARGUMENTS AND GENERATES A SINUSOIDAL SEQUENCE.

Code:
fm= 5e3;
fs=10*fm;
N=200;
y=sine(fm,fs,N);
plot(y)
legend('sinusoid with fs=10*fm')

Function code:

* function y=sine(fm,fs,N)
* n=0:N-1;
* y=sin(2*pi*(fm/fs)*n);8
*

1
sinusois with fs=10*fm
0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 20 40 60 80 100 120 140 160 180 200

TASK NO 2:
WRITE A FUNCTION WHICH TAKES A SEQUENCE X[N] AS INPUT AND CALCULATES THE ENERGY AND
AVERAGE POWER OF THE SEQUENCE. USE THE FUNCTION IN PREVIOUS TASK TO PASS A SINUSOID AS
INPUT.
Code:
fm= 5e3;
fs=10*fm;
N=200;
y=sine(fm,fs,N);
[E,P]= pn(y)

Function code:
* function y=sine(fm,fs,N)
* n=0:N-1;
* y=sin(2*pi*(fm/fs)*n);
* end

* function [E,P]=pn(x)
* L=length(x);
* E=0;
* for i=1:L
* E=E+abs(x(i)).^2;
* end
* P=E/L;
* end

Output:

E = 100.0000
P = 0.5000

TASK NO 3:
Write a function which takes the limits of n-axis as the input arguments
and generates
1. A unit-step sequence
2. A unit-impulse sequence
Plot the resultant sequences. Properly label and format the plots.

Code:
n1=-5;
n2=5;
[u,i]=unit(n1,n2)
subplot(2,1,1)
stem(n1:n2,u); legend('Unit Step')
xlabel('n-axis')
subplot(2,1,2)
stem(n1:n2,i); legend('Unit Impulse')
xlabel('n-axis')

Function Code:
* function [u,i]=unit(n1,n2)
* n=n1:n2;
* i(n==0)=1;
* i(n~=0)=0;
* u(n<=0)=0;
* u(n>0)=1;
* end

Output:
TASK NO 4:
WRITE A FUNCTION WHICH PERFORMS FOLLOW
1. READS A SOUND FILE AND STORES IT IN A MATR
2. PLOTS 500 SAMPLES OF THAT FILE
3. PLAYBACKS THE SOUND ONCE DONE PLOTTING

Code:
function []=aud()

y=wavread('snd');
y=y';
fs=500;
plot(y(1:500))
sound(y,fs)
legend('500 sample of audio file')
end

Output:

You might also like