Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier...

10
1 2013 Slightly revised 2013 by Benny Lövström and Ronnie Lövström 20 Spectral analysis, MKSPA MKSPA is used to analyze the spectra in the sound files. Functions Window: Window functions. FFT length: FFT length. Overlap: Number of overlapping segments Fs(Hz): Sampling frequency. Zoom: Activate/deactivate Matlab zoom Analyze: Analyze Exit End the program.

Transcript of Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier...

Page 1: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

1

2013

Slig

htly

revi

sed

2013

by

Ben

ny L

övst

röm

and

Ron

nie

Lövs

tröm

20

Spec

tral

ana

lysi

s, M

KSP

A

MK

SPA

is u

sed

to a

naly

ze th

e sp

ectra

in th

e so

und

files

.

Func

tions

Win

dow

: W

indo

w fu

nctio

ns.

FFT

leng

th:

FFT

leng

th.

Ove

rlap:

N

umbe

r of o

verla

ppin

g se

gmen

ts

Fs(H

z):

Sam

plin

g fr

eque

ncy.

Zo

om:

Act

ivat

e/de

activ

ate

Mat

lab

zoom

A

naly

ze:

Ana

lyze

Ex

it

En

d th

e pr

ogra

m.

Page 2: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

19

Func

tion

Impo

rt W

orks

pace

: R

ead

filte

r spe

cific

atio

ns fr

om fi

le.

Expo

rt W

orks

pace

: S

ave

filte

r spe

cific

atio

ns o

n fil

e.

Set f

ilter

spec

s:

Inpu

t filt

er sp

ecifi

catio

ns.

Filte

r coe

ffs:

Inpu

t fil

ter c

oeff

icie

nts.

Hel

p:

Not

impl

emen

ted

yet.

Abo

ut:

P

rogr

am v

ersi

on.

Res

et:

Res

ets p

oles

and

zer

os b

ut n

ot fi

lter s

peci

ficat

ions

.

Exit:

E

xits

and

save

wor

kspa

ce to

the

file

curr

ent.m

at .

Add

pol

e:

P

lace

pol

e, p

ress

left

mou

se b

utto

n, e

nds w

ith

right

mou

se b

utto

n.

Del

ete

pole

:

Pla

ce c

urso

r ove

r pol

e, p

ress

left

mou

se

butto

n to

del

ete,

end

s with

righ

t mou

se b

utto

n.

Add

zer

o:

S

et A

dd p

ole

Del

ete

zero

:

See

del

ete

pole

M

ove:

See

add

pol

e Im

port

filte

r:

Impo

rt of

stan

dard

filte

rs fr

om M

atla

b Si

gnal

Pro

cess

ing

Tool

box.

M

agni

tude

:

Mag

nitu

de fu

nctio

n.

Phas

e:

Ph

ase

func

tion.

Im

puls

e:

Im

puls

e re

spon

se.

Rep

lace

last

:

Rep

lace

last

R

ecip

roc

Zero

s:

Hig

hPas

s:

H

igh

pass

filte

r |H

(f)|_

{| f=

0.5}

=1,

Low

pas

s filt

er

|H(f)

|_{|

f=0}

=1.

Zoom

:

Zoo

m.

Unw

rap;

Phas

e U

nwra

p Ph

ase.

Fo

cus:

R

adiu

s A

djus

t Gai

n:

A

djus

t Gai

n in

dB

.

2

Dig

ital S

igna

l Pro

cess

ing

ETI2

65 2

013

Intr

oduc

tion

In th

e co

urse

we

have

2 la

bora

tory

wor

ks fo

r 201

3. E

ach

labo

rato

ry w

ork

is a

3 h

ours

less

on.

We

will

use

MA

TLA

B fo

r illu

stra

te so

me

feat

ures

in d

igita

l sig

nal p

roce

ssin

g.

Equi

pmen

t:

PC

with

Mat

lab

and

inpu

t/out

put o

f sou

nd.

Mat

lab:

M

atla

b to

olbo

xes:

Si

gnal

Pro

cess

ing

tool

box

D

ata

acqu

isiti

on to

olbo

x

Lab

1:

Rea

l tim

e sp

ectr

al a

naly

sis u

sing

Fou

rier

tran

sfor

m a

nd

estim

atio

n of

impu

lse

resp

onse

s usi

ng c

orre

latio

n fu

nctio

n

Ta

sk 1

. R

eal t

ime

spec

tral a

naly

sis u

sing

Fou

rier t

rans

form

Ta

sk 2

. R

eal t

ime

spec

trogr

am

Task

3.

Estim

atio

n of

impu

lses

resp

onse

s usi

ng c

orre

latio

n

Ta

sk 4

. M

odul

atio

n

Ta

sk 5

: SS

B-m

odul

ator

Lab

2:

Des

ign

of II

R-f

ilter

s

Ta

sk 1

: R

elat

ion

betw

een

pole

s and

filte

r spe

ctru

m

Task

2: D

esig

n of

IIR

-filt

er fr

om fi

lter s

peci

ficat

ion

Task

3 N

otch

filte

rs

Task

4: F

ilter

mus

ic si

gnal

s

Page 3: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

3

Lab

orat

ory

wor

k 1:

Rea

l tim

e sp

ectr

al a

naly

sis u

sing

the

Four

ier

tran

sfor

m

In th

is la

bora

tory

wor

k w

e w

ill u

se M

ATL

AB

for i

llust

rate

som

e fe

atur

es in

dig

ital s

igna

l pr

oces

sing

. St

art M

atla

b, a

nd u

pdat

e th

e M

atla

b pa

th if

nee

ded.

Con

nect

the

head

set t

o th

e PC

.

Tas

k 1.

R

eal t

ime

spec

tral

ana

lysi

s usi

ng F

ouri

er tr

ansf

orm

Star

t Mat

lab.

A

t the

Mat

lab

prom

pt, t

ype

sigf

ftio

_lin

(or s

igff

tio_l

og

or d

emoa

i_ff

t’)

Now

a sp

ectru

m a

naly

zing

win

dow

will

be

open

ed, s

ee b

elow

Item

1:

Say

the

wor

d ‘s

mile

’ slo

wly

and

look

esp

ecia

lly a

t the

spec

tra

of th

e vo

wel

s ‘i’

and

‘e’.

Try

also

oth

er so

unds

.

E

stim

ate

the

pitc

h, th

e fr

eque

ncy

of th

e do

min

ant p

eak.

My

pitc

h is

……

……

……

……

...(s

ome

mea

n va

lue)

.

Item

2:

Try

to g

ener

ate

a so

und

with

as f

lat s

pect

rum

as p

ossi

ble

(‘

oral

whi

te n

oise

’, or

oth

er so

unds

). T

ry b

oth

sigf

ftio

_lin

and

sigf

ftio

_log

.

Tas

k 2.

R

eal t

ime

spec

trog

ram

18

Tes

t the

filte

r in

Mat

lab

You

hav

e al

read

y a

smal

l par

t of t

he so

ng in

the

glob

al v

aria

ble

'song

'.

If n

ot,

relo

aded

usi

ng:

song

=wav

read

('ssi

lenc

e',[1

100

000]

); %

load

100

000

val

ue

List

en to

the

dist

urbe

d so

ng (n

o fil

terin

g)

soun

dsc(

song

, 800

0);

% li

sten

Fs=

8 kH

z

Filte

r the

song

with

you

r filt

ers,

both

the

FIR

and

the

IIR

filte

r and

list

en.

y0=f

ilter

(B,1

,song

);

soun

dsc(

y0, 8

000)

;

y1=f

ilter

(B,A

,song

); s

ound

sc(y

1, 8

000)

;

Did

you

r filt

ers f

ulfil

l the

requ

irem

ents

?

App

endi

x: P

rogr

am d

escr

iptio

ns

IIR

filte

r de

sign

, MK

IIR

M

KII

R c

an b

e us

ed fo

r int

erac

tive

filte

r des

ign

from

pol

es a

nd z

eros

.

Page 4: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

17

Tas

k 4:

Filt

er m

usic

sign

als

In th

is ta

sk, y

ou sh

all c

ance

l sin

usoi

ds a

dded

to m

usic

file

s. Sa

mpl

ing

rate

Fs=

8000

Hz,

ster

eo.

Cal

l gl

obal

S, j

ukeb

ox, s

ong=

S; a

nd c

hoos

e a

song

from

the

list.

You

mus

t cho

ose

one

of th

e fir

st 5

for t

estin

g in

the

DSP

. The

var

iabl

e S

will

con

tent

s 100

000

sam

ples

from

the

song

and

it

is st

ored

in th

e va

riabl

e 'so

ng' f

or fu

ture

use

. Li

sten

to th

e so

ng (s

mal

l par

t) so

unds

c(so

ng,8

000)

;

Use

Win

dow

s "So

und

reco

rder

" to

list

en to

the

who

le so

ng. A

void

long

file

s in

Mat

lab

due

to d

iffic

ultie

s to

stop

the

soun

d ou

tput

s in

Mat

lab.

Now

, use

mks

pa to

det

erm

ine

the

freq

uenc

ies o

f the

sinu

soid

s. Pr

ess

PEA

Kan

d us

e th

e m

ouse

to p

oint

at p

eaks

in th

e sp

ectru

m. T

he fr

eque

ncie

s are

mul

tiple

s of 1

0 H

z.

Writ

e do

wn

the

freq

uenc

ies f

or th

e pe

aks o

f you

r son

g.

Pres

sExi

t to

stop

mks

pa.

Now

, you

shal

l det

erm

ine

a no

tch

filte

r whi

ch c

ance

l the

sinu

soid

s. Tr

y bo

th F

IR a

nd II

R

filte

rs. T

ype

your

cho

ice

of p

oles

and

zer

os in

Mat

lab

and

put t

hem

into

vec

tors

. Th

en, d

eter

min

e th

e A

and

B p

olyn

omia

ls.

Exam

ple:

Fs

=800

0; F

1=

;

F2=

;

F3

=

;

z1

=exp

(-j*

2*pi

*F1/

Fs);

z2=

conj

(z1)

;

z3

=exp

(-j*

2*pi

*F2/

Fs);

z4=

conj

(z3)

;

z5=e

xp(-

j*2*

pi*F

3/Fs

); z

6=co

nj(z

5);

Z=[z

1,z2

,z3,

z4,z

5,z6

];

P=0.

9*Z

;

B

=pol

y(Z)

A

=pol

y(P)

zp

lane

(B,A

)

% c

heck

pol

e-ze

ro p

lot

plot

als

o th

e m

agni

tude

spec

trum

for y

our f

ilter

(see

hel

p fr

eqz)

f=

0:.0

1:1;

w=2

*pi*

f; H

=fre

qz(B

,1,w

); p

lot(

f,abs

(H))

; %

FIR

f=

0:.0

1:1;

w=2

*pi*

f; H

=fre

qz(B

,A,w

); p

lot(

f,abs

(H))

; %

IIR

Not

ice:

You

mus

t use

j fo

r the

imag

ine

part.

Tes

t the

filte

r usi

ng M

KII

R.

4

A sp

ectro

gram

is a

tim

e-fr

eque

ncy

plot

of t

he si

gnal

. A

slid

ing

win

dow

is a

pplie

d to

the

sign

al

and

the

shor

t tim

e Fo

urie

r tra

nsfo

rm a

re d

eter

min

ed fo

r eac

h tim

e-w

indo

w.

The

plot

has

tim

e on

the

x-ax

is a

nd fr

eque

ncy

on th

e y-

axis

, and

the

inte

nsity

is c

olor

cod

ed, w

ith re

d as

the

high

est i

nten

sity

. Se

ehe

lp sp

ectr

ogra

m fo

r mor

e in

form

atio

n

Type

N

=200

00; F

max

=400

0; r

ecor

d_sp

ectr

a_ch

ina

%

N=n

o of

sam

ples

(Fs=

10 k

Hz)

, %

Fmax

= m

ax fr

eq in

the

plot

(<50

00 H

z)

Now

2 se

cond

s of ‘

mic

in’ w

ill b

e re

cord

ed a

nd th

en th

e sp

ectro

gram

will

be

show

n.

(Inc

reas

e N

if y

ou w

ant t

o ha

ve lo

nger

sequ

ence

s)

Item

1:

Pron

ounc

e th

e C

hine

se w

ords

bel

ow a

nd se

e if

you

have

the

corr

ect

pitc

h (to

ne).

Let t

he C

hine

se st

uden

ts sh

ow th

e co

rrec

t pitc

h.

Use

als

o so

me

Swed

ish

wor

ds w

ith C

hine

se to

ne.

Page 5: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

5

Tas

k 3

. E

stim

atio

n of

impu

lses

res

pons

es u

sing

cor

rela

tion

Cor

rela

tion

func

tions

are

ofte

n us

ed in

est

imat

ion

of u

nkno

wn

syst

ems.

This

is d

escr

ibed

in th

e te

xtbo

ok p

ages

99-

101

and

in th

e sl

ides

from

the

seco

nd le

ctur

e..

Inpu

t – O

utpu

t Rel

atio

ns u

sing

cor

rela

tion

func

tions

(fro

m th

e sl

ides

)

Autocorrelationfunctio

nforthe

output

)(

)(

)(

)(

)(

)(

lh

lh

lr

ifl

rl

rl

rhh

xxhh

yy

Crossc

orrelatio

nfunctio

nforinp

utou

tput

signal

)(

)(

)(

lr

lh

lr

xxyx

If th

e au

toco

rrel

atio

n fo

r the

inpu

t is a

del

ta fu

nctio

n,

)(

)(

ll

r xx, w

e

dire

ct h

ave

the

impu

lse

resp

onse

)

()

(l

rl

hyx

.

If th

e au

toco

rrel

atio

n fo

r the

inpu

t is n

ot a

del

ta fu

nctio

n, w

e ha

ve to

est

imat

e th

e im

puls

e re

spon

se fr

om th

e ex

pres

sion

for t

he c

ross

cor

rela

tion.

Thi

s is n

ot in

clud

ed in

this

cou

rse.

B

ut st

ill, w

e ca

n fin

d a

lot o

f inf

orm

atio

n ev

en in

this

cas

e.

We

will

her

e us

e pr

e-ge

nera

ted

sign

als.

In fi

les o

n th

e co

mpu

ter t

here

are

pai

rs o

f inp

ut a

nd

outp

ut si

gnal

s fro

m v

ario

us u

nkno

wn

filte

rs. T

ry to

est

imat

e th

ese

impu

lse

resp

onse

s.

Mat

lab

scrip

t for

com

putin

g th

e co

rrel

atio

n fu

nctio

n us

ed b

elow

. Thi

s scr

ipt e

xist

in th

e M

atla

b pa

th.

% la

b_si

gcor

r.m

Com

pute

and

plo

t cor

rela

tion

-N0<

0<N

0%

[rxy

,n]=

lab_

sigc

orr(x

,y,N

0);

func

tion

[rxy,

n]=l

ab_s

igco

rr(x,

y,N

0)N

x=le

ngth

(x);

Ny=

leng

th(y

);if

Nx=

=Ny

N=N

x; e

lse

N=m

in(N

x,N

y); e

ndrx

y=xc

orr(x

(1:N

),y(1

:N))

;rx

y=rx

y(N

-N0:

N+N

0);

n=-N

0:N

0;

h(n)

y(n)

=h(

n) *

x(n

)x(

n)

16

Tas

k 2:

Des

ign

of II

R-f

ilter

from

filte

r sp

ecifi

catio

n

Cho

ose

pole

s and

zer

os fo

r ful

fillin

g th

e de

man

ds b

elow

bas

ed o

n yo

ur e

xper

ienc

e fr

om ta

sk 1

.

Pres

sIm

port

Wor

kspa

ce a

nd o

pen

the

file

irsp

ec1.

mat

to

load

the

spec

ifica

tions

into

MK

IIR

.

Now

, cho

ose

pole

s and

zer

os to

ful

fill t

he re

quire

men

ts.

You

can

ave

you

r filt

er w

ith E

xpor

t Wor

kspa

ce a

nd c

hoos

e a

file

nam

e (i

.e.fi

lter1

.mat

. The

n pr

ess I

mpo

rt fi

lter

to re

load

the

filte

r.

Opt

iona

l tas

k C

ompa

re w

ith st

anda

rd fi

lter s

olut

ions

. St

op th

e pr

ogra

m M

KII

R, p

ress

Exi

t.

Tas

k 3

Not

ch fi

lters

N

ow, y

ou w

ill e

xam

ine

notc

h fil

ters

. The

syst

em fu

nctio

n fo

r bot

h th

e FI

R fi

lter a

nd th

e II

R

filte

r are

giv

en b

elow

with

0 t

he fr

eque

ncy

whi

ch sh

all b

e ca

ncel

led.

Plo

t the

mag

nitu

de sp

ectra

for t

he fi

lters

w

ith v

aryi

ng p

ositi

on o

f the

pol

es a

nd z

eros

usi

ng th

e pr

ogra

m M

KII

R .

Alte

rnat

ivel

y, y

ou c

an u

se M

atla

b di

rect

and

typi

ng y

our s

yste

m fu

nctio

n ab

ove

(FIR

).

f0=0

.2; r

=0.9

5; w

0=2*

pi*0

.2;

f=0:

.01:

1; z

=exp

(j*2

*pi*

f);

Hfir

=1-2

*cos

(w0)

*z.^

(-1)

+z.^

(-2)

;sub

plot

(211

), pl

ot(f

,abs

(Hfir

));

Hiir

=Hfir

./(1-

2*r*

cos(

w0)

*z.^

(-1)

+r^2

*z.^

(-2)

); su

bplo

t(21

2),p

lot(

f,abs

(Hiir

));

Page 6: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

15

Lab

orat

ory

task

s

IIR

filte

r

The

pro

gram

MK

IIR

is u

sed

for i

nter

activ

e II

R fi

lter d

esig

n. Y

ou c

an p

lace

pol

es a

nd z

eros

in

the

pole

-zer

o pl

ane

and

then

show

the

impu

lse

resp

onse

, mag

nitu

de sp

ectra

and

pha

se fu

nctio

n fo

r the

dig

ital s

yste

m. T

he p

rogr

am c

an a

lso

desi

gn fi

lters

from

spec

ifica

tion

of re

quire

men

ts o

f m

agni

tude

spec

tra. A

set o

f sta

ndar

d fil

ters

are

als

o in

clud

ed in

the

prog

ram

.

Tas

k 1:

Rel

atio

n be

twee

n po

les a

nd fi

lter

spec

trum

Ty

pe M

KII

R to

star

t the

pro

gram

at t

he M

atla

b pr

ompt

.Pl

ace

a po

le o

r a p

air o

f com

plex

pol

es in

the

z pl

ane

and

chec

k th

e re

sult.

Pres

s firs

t Rep

lace

last

. Mov

e th

e po

le in

side

the

unit

circ

le a

nd c

heck

the

resu

lt.

Spec

ially

, loo

k at

the

rela

tion

of th

e m

agni

tude

and

ang

le o

f the

pol

es a

nd th

e m

agni

tude

spec

tra a

nd th

e im

puls

e re

spon

se.

Rel

ease

Rep

lace

last

.

6

Item

1:

Mus

ic th

roug

h an

ech

o fil

ter.

Firs

t we

liste

n to

mus

ic th

roug

h an

ech

o fil

ter (

reve

rber

atio

n). W

e ca

n he

ar th

e ef

fect

of t

he

echo

es b

ut it

will

be

diff

icul

t to

estim

ate

the

time

dela

ys.

The

inpu

t and

out

put s

igna

ls a

re st

ored

in fi

les w

ith in

put i

n th

e le

ft ch

anne

l and

out

put i

n th

e rig

ht c

hann

el. L

iste

n to

the

sign

als a

nd th

en tr

y to

est

imat

e th

e de

lay

usin

g co

rrel

atio

n fu

nctio

ns.

Type

the

com

man

ds b

elow

. Lo

ad th

e si

gnal

s and

plo

t and

list

en to

them

. lo

ad si

g_m

usic

; x=s

ig_m

usic

(:,1

); y

=sig

_mus

ic(:

,2);

% lo

ad in

put a

nd o

utpu

t sig

nals

soun

dsc(

x,10

000)

; pau

se(1

0), s

ound

sc(y

,100

00);

U

se a

lso

the

plot

com

man

d to

plo

t par

ts o

f the

sign

als.

subp

lot(2

11),

plot

(x),

subp

lot(2

12),

plot

(y)

%

Plo

t inp

ut a

nd o

utpu

t Th

e co

mm

and

subp

lot(m

np)c

reat

es m

row

s and

n c

olum

ns in

the

figur

e, a

nd se

lect

s pos

ition

nu

mbe

r p fo

r the

nex

t plo

t.

Now

, use

cor

rela

tion

func

tions

to e

stim

ate

the

dela

ys (t

he im

puls

e re

spon

se).

Writ

e ty

pe s

igco

rr to

show

the

Mat

lab

code

. su

bplo

t(21

1), N

0=20

00;[

rxx,

n]=s

igco

rr(x

,x,N

0);p

lot(

n,rx

x);g

rid

on %

inpu

t aut

o co

rrel

atio

n su

bplo

t(21

2), N

0=20

00;[

ryx,

n]=s

igco

rr(y

,x,N

0);p

lot(

n,ry

x);g

rid

on %

cro

ss c

orre

latio

n Es

timat

e th

e de

lay

in th

e im

puls

e re

spon

se. T

he d

elay

s ar

e …

…...

ms (

my

gues

s).

Item

2:

Use

whi

te n

oise

as t

he in

put t

o th

e ec

ho fi

lter.

W

e us

e w

hite

noi

se a

s the

inpu

t and

repe

at th

e in

stru

ctio

ns fr

om it

em 1

. Whi

te n

oise

has

the

corr

elat

ion

equa

l to

a de

lta sp

ike,

i.e.

the

auto

corr

elat

ion

func

tion

for w

hite

noi

se is

rxx(

l)=(l)

.

Load

inpu

t and

out

put d

ata

load

sig_

nois

e; x

=sig

_noi

se(:

,1);

y=si

g_no

ise(

:,2);

Not

e: D

ecre

ase

the

paus

e to

4 s.

so

unds

c(x,

1000

0);p

ause

(4),s

ound

sc(y

,100

00);

% L

iste

n to

inpu

t and

out

put

Use

als

o th

e pl

ot c

omm

and

to p

lot p

arts

of t

he si

gnal

s. su

bplo

t(21

1), p

lot(

x), s

ubpl

ot(2

12),

plot

(y)

% P

lot i

nput

and

out

put

Now

, use

cor

rela

tion

func

tions

to e

stim

ate

the

dela

ys (i

mpu

lse

resp

onse

). su

bplo

t(21

1), N

0=20

00;[

rxx,

n]=s

igco

rr(x

,x,N

0);p

lot(

n,rx

x);g

rid

on %

inpu

t aut

o co

rrel

atio

n su

bplo

t(21

2), N

0=20

00;[

ryx,

n]=s

igco

rr(y

,x,N

0);p

lot(

n,ry

x);g

rid

on %

in-o

ut c

ross

cor

rela

tion

With

whi

te n

oise

as i

nput

it w

ill b

e ea

sier

to e

stim

ate

the

impu

lse

resp

onse

. The

est

imat

ed d

elay

s in

the

impu

lse

resp

onse

are

…...

......

......

......

......

......

......

…...

ms.

Item

3:

Whi

te n

oise

thro

ugh

a ba

nd p

ass f

ilter

.

Page 7: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

7

We

have

now

est

imat

ed th

e im

puls

e re

spon

se o

f an

ech

o fil

ter.

Nex

t ste

p is

to e

stim

ate

a ba

nd

pass

filte

r im

puls

e re

spon

se. L

oad

the

inpu

t-out

put s

igna

ls a

nd li

sten

to th

em.

Then

est

imat

e th

e im

puls

e re

spon

se u

sing

cor

rela

tion

func

tions

.

Type

the

com

man

d be

low

lo

ad si

g_ba

ndpa

ss_n

oise

; x=s

ig_b

andp

ass_

nois

e(:,1

);y=

sig_

band

pass

_noi

se(:

,2);

so

unds

c(x,

1000

0);p

ause

(4),s

ound

sc(y

,100

00);

subp

lot(

211)

, N0=

2000

;[rx

x,n]

=sig

corr

(x,x

,N0)

;plo

t(n,

rxx)

;gri

d on

% in

put a

uto

corr

elat

ion

subp

lot(

212)

, N0=

2000

;[ry

x,n]

=sig

corr

(y,x

,N0)

;plo

t(n,

ryx)

;gri

d on

% c

ross

cor

rela

tion

You

can

hea

r tha

t the

out

put s

igna

l is a

nar

row

ban

d si

gnal

. Che

ck th

e sp

ectru

m b

y ta

king

the

Four

ier t

rans

form

of r

yx(n

) by

typi

ng

sigf

ftp(

ryx,

1000

0,10

000,

1000

);

% p

lot s

pect

ra u

p to

1 k

Hz,

Fs=

10 k

Hz

Tas

k 4:

Mod

ulat

ion

In m

ost c

omm

unic

atio

n sy

stem

s the

sign

als a

re tr

ansl

ated

from

a lo

wer

freq

uenc

y ba

nd u

p to

hi

gher

freq

uenc

ies.

This

is c

alle

d m

odul

atio

n. W

e kn

ow th

e fo

rmul

a

)co

s()

cos(

)co

s()

cos(

2di

ffer

enceb

ab

ab

asu

mTh

is m

eans

that

whe

n w

e m

ultip

ly tw

o si

gnal

s we

will

hav

e th

e su

m a

nd d

iffer

ence

of t

he

angl

es.

Whe

n w

e ha

ve si

gnal

s, th

is fo

rmul

a is

)))

(2

cos(

))(

2co

s((5.0

)2

cos(

)2

cos(

cm

cm

cm

ff

ff

ff

The

mul

tiplic

atio

n gi

ves

then

one

sig

nal

at t

he f

requ

ency

c

mlo

wer

ff

fan

d on

e at

the

fr

eque

ncy

cm

uppe

rf

ff

and

this

freq

uenc

ies i

s cal

led

the

low

er a

nd th

e up

per s

ide

band

.

cos(2

0.25

n)

x(n)

y(n)

14

Prep

arat

ion

exer

cise

2

Sket

ch th

e m

agni

tude

spec

tra |H

(f)| f

or th

e gi

ven

the

pole

-zer

o pl

ots.

Pole

-zer

o pl

ot

M

agni

tude

spec

tra |H

(f)|

Page 8: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

13

Lab

orat

ory

wor

k 2:

Des

ign

of II

R fi

lters

Intr

oduc

tion

In th

is la

bora

tory

wor

k w

e w

ill d

esig

n FI

R a

nd II

R fi

lters

. Firs

t, w

e w

ill sh

ow

the

rela

tion

betw

een

pole

-zer

o pl

ots a

nd th

e m

agni

tude

spec

tra a

nd im

puls

e re

spon

ses f

or

digi

tal f

ilter

s. Th

e w

e w

ill d

esig

n no

tch

filte

rs w

hich

will

be

test

ed in

bot

h M

atla

b

Prep

arat

ion

exer

cise

1

Com

bine

the

pole

-zer

o pl

ot a

nd th

e m

agni

tude

spec

tra |H

(f)| b

elow

. Sho

w th

e pa

ir of

pol

e-ze

ro

plot

and

mag

nitu

de sp

ectra

cor

resp

ondi

ng to

the

sam

e sy

stem

.

Pole

-zer

o pl

ot

M

agni

tude

spec

tra |H

(f)|

8

An

exam

ple

of th

e fr

eque

ncy

cont

ents

is sh

own

belo

w, w

ith

)05.0

2si

n()

(n

nx

bein

g m

odul

ated

by

)25.0

2co

s(n

.

Then

, the

inpu

t spe

ctru

m a

nd th

e ou

tput

spec

trum

are

show

n be

low

.

Item

1:

Che

ck th

is in

Mat

lab

by ty

ping

: N

=200

00;n

=1:N

;x=s

in(2

*pi*

0.05

*n);

spee

ch_m

odul

atio

n_la

b_a

Item

2:

N

ow, c

hang

e th

e in

put f

requ

ency

to f=

0.1,

i.e.

)1.0

2si

n()

(n

nx

and

fill i

n th

e di

agra

m b

elow

.

Page 9: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

9

Item

3:

Spee

ch sc

ram

bler

A

spec

ial c

ase

of th

e ab

ove

exam

ple

occu

rs th

en w

e ha

ve th

e fig

ure

belo

w. T

his i

s ofte

n ca

lled

spee

ch sc

ram

blin

g in

the

liter

atur

e. Y

ou sh

all t

est t

his s

yste

m in

Mat

lab.

Item

1: T

est t

he sy

stem

with

soun

d as

inpu

t. Fo

llow

the

inst

ruct

ions

bel

ow.

load

sig_

mus

ic;

% lo

ad so

und

sign

al

x=si

g_m

usic

(:,1

); N

=len

gth(

x); n

=[1:

N]';

spe

ech_

scra

mbl

er_l

ab_a

%

spee

ch sc

ram

bler

Try

to e

xpla

in th

e re

sults

from

Mat

lab.

Mat

lab

scrip

for s

peec

h sc

ram

bler

%

spee

ch_s

cram

bler

_lab

_a.m

d

emo

of s

peec

h sc

ram

bler

bm

201

1%

Use

: N

=200

00;n

=1:N

;x=s

in(2

*pi*0

.1*n

); s

peec

h_sc

ram

bler

_lab

_ay=

(-1).^

n.*x

;so

und(

0.5*

x,10

000)

;pau

se(1

0);s

ound

(0.5

*y,1

0000

)su

bplo

t(211

),sig

fftp(

x,1,

N,1

);su

bplo

t(212

),sig

fftp(

y,1,

N,1

);

Item

2:

To fu

rther

ana

lyze

the

syst

em w

e us

e si

nuso

ids a

s the

inpu

t, )

1.02

cos(

)(

nn

x.

Test

the

spee

ch sc

ram

bler

with

this

sign

al. B

ut b

efor

e ru

nnin

g th

e pr

ogra

m, c

alcu

late

th

eore

tical

ly th

e sp

ectru

m a

nd fi

ll in

the

figur

e be

low

.

Spec

trum

|X(f

)| an

d |Y

(f)|.

Che

ck y

our s

olut

ion

by ty

ping

N

=400

0; n

=[1:

N]';

x=s

in(2

*pi*

0.1*

n);

spee

ch_s

cram

bler

_lab

_a

cos(2

0.5n)=(

1)n

x(n)

y(n)

12

Then

che

ck th

e re

sult

in M

atla

b us

ing

N=2

0000

;n=[

1:N

]'; x

=sin

(2*p

i*0.

1*n)

; de

ltaf=

0;

ssb_

lab_

2012

Item

5.3

: Dem

odul

atio

n w

ith w

rong

freq

uenc

y Fi

nally

, we

chec

k th

e ca

se w

hen

delta

f=0.

02, i

.e. w

e us

e th

e w

rong

freq

uenc

y in

the

last

step

in

the

dem

odul

ator

. Typ

e

x=si

g_m

usic

(:,1

);N

=len

gth(

x);d

elta

f=0.

02;

ssb_

lab_

2012

, so

unds

c(xe

,100

00);

Expl

ain

wha

t hap

pens

in th

e SS

B sy

stem

for v

ario

us v

alue

s of d

elta

f. Th

e sp

ectra

is sh

own

belo

w fo

r del

taf=

0.02

.

Page 10: Spectral analysis, MKSPA · Laboratory work 1: Real time spectral analysis using the Fourier transform In this laboratory work we will use MATLAB for illustrate some features in digital

11

Item

5.1

: Mus

ic th

roug

h th

e SS

B sy

stem

F

irst,

test

the

SSB

mod

ulat

or/d

emod

ulat

or w

ith m

usic

(del

taf=

0). T

ype

load

sig_

mus

ic;

x=s

ig_m

usic

(:,1

);

soun

dsc(

x,10

000)

; x=

sig_

mus

ic(:

,1);

N=l

engt

h(x)

;del

taf=

0.0;

ssb

_lab

_201

2, s

ound

sc(x

e,10

000)

; Th

e fig

ure

belo

w sh

ows t

he sp

ectra

in th

e po

ints

A, B

, C, D

and

E.

Not

e th

at th

e x-

axis

is 0

<f<0

.5.

Item

5.2

. A si

nuso

id th

roug

h th

e th

e SS

B m

odul

ator

/dem

odul

ator

To

ana

lyze

the

SSB

syst

em, w

e no

w u

se a

sinu

soid

as i

nput

sign

al ( d

elta

f=0)

,)

1.02

sin(

)(

nn

x Fill

in th

e sp

ectra

in th

e po

ints

A, B

, C, D

and

E in

the

figur

e be

low

.

10

Tas

k 5:

SS

B-m

odul

ator

In

all

com

mun

icat

ion

syst

ems,

freq

uenc

y tra

nsla

tions

are

use

d. W

e m

ove

info

rmat

ion

sign

als

from

low

freq

uenc

ies u

p to

hig

her f

requ

enci

es b

efor

e tra

nsm

issi

on a

nd a

t the

rece

iver

side

we

rece

ived

the

sign

al a

nd th

en tr

ansl

ate

the

sign

als b

ack

to lo

w fr

eque

ncie

s. Th

is p

roce

dure

is

calle

d m

odul

atio

n-de

mod

ulat

ion

and

the

equi

pmen

t is c

alle

d m

odem

.

We

illus

trate

this

with

an

SSB

-mod

ulat

ion-

dem

odul

atio

n sy

stem

ofte

n us

ed in

com

mun

icat

ion

syst

ems.

A ti

me-

disc

rete

syst

em is

giv

en b

elow

(SSB

mod

ulat

or).

SSB

mea

ns S

ingl

e Si

deB

and.

Test

this

usi

ng th

e M

atla

b sc

ript b

elow

.

%ss

b_la

b_20

11.m

dem

o of

SSB

-mod

/dem

oula

tion

bm 2

011

% U

se:

N=2

0000

;x=s

in(2

*pi*0

.1*n

);del

taf=

0.02

5;,s

sb

% U

se:

N=2

0000

;n=[

1:N

]'; x

=sin

(2*p

i*0.1

*n);

delta

f=0;

, ssb

_lab

_201

1%

x

=sig

_mus

ic(:,

1);N

=len

gth(

x);d

elta

f=0.

025;

,ssb

_lab

_201

1, s

ound

sc(x

e,10

000)

;fc

=.25

; n=

[1:N

]';hl

p=fir

1(50

0,2*

.25)

;xa

=x;

xb=x

a.*s

in(2

*pi*f

c*n)

;xc

=filt

er(h

lp,1

,xb)

;xd

=xc.

*cos

(2*p

i*(fc

+del

taf)*

n);

xe=f

ilter

(hlp

,1,x

d);

subp

lot(5

11),s

igfft

p(xa

,1,N

);su

bplo

t(512

),sig

fftp(

xb,1

,N);

subp

lot(5

13),s

igfft

p(xc

,1,N

);su

bplo

t(514

),sig

fftp(

xd,1

,N);

subp

lot(5

15),s

igfft

p(xe

,1,N

);

10.75

f0.25

0.5

|Hlow

pass

(f)|

Hlow

pass(f)

Hlow

pass(f)

C

y(n)

x(n)

BD

EA

cos(2

0.25

n)cos(2

0.(25+d

eltaf)n)