You are on page 1of 16

# COMMUNICATION SYSTEMS-I (LAB) ASSIGNMENT (Frequency modulation and demodulation in MATLAB)

Submitted to: Sir Zeeshan Submitted by: NS Sana Mazahir (093) NS Anika Sadiq (084) NS Mahin Akhtar (088) DE -31 EE B

Objective:
Implementing frequency modulation and demodulation of sinusoidal message signal in MATLAB.

## Frequency demodulation using the Hilbert Transform:

MATLAB CODE:
clc; %carrier signal Ac=1; t1=0:0.25:500; fs=80; f = fs*(0:length(t1)-1)/ length(t1); c=Ac*cos(2*pi*t1); c_f=fft(c); %message signal t2=0:0.0025:5; m=cos(2*pi*t2); m_f=fft(m); %modulation beta=2; sfm=Ac*cos(2*pi*t1+beta*sin(2*pi*t2)); sfm_f=fft(sfm); %demodulation using hilbert transform

y1=hilbert(sfm); %same results are obtained if following %signal is used instead of using %hilbert function %y1=Ac*cos(2*pi*t1+beta*sin(2*pi*t2)) %+i*Ac*sin(2*pi*t1+beta*sin(2*pi*t2)); y2=conj(y1); %delaying the signal y3=1:1:length(y2); y3(1)=1 + 0.51i; for j=2:length(y2) y3(j)=y2(j-1); end y=angle(y1.*y3); y_f=fft(y); %plots subplot(4,2,1),plot(c,'color','black','linewidth',2); title('Carrier signal c(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,2,2),plot(f,abs(c_f),'color','black','linewidth',2); title('Carrier signal C(f)'); xlabel('frequency'); ylabel('amplitude'); subplot(4,2,3),plot(m,'color','black','linewidth',2); title('Message signal m(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,2,4),plot(f,abs(m_f),'color','black','linewidth',2); title('Carrier signal M(f)'); xlabel('frequency'); ylabel('amplitude'); subplot(4,2,5),plot(sfm,'color','black','linewidth',2); title('Modulated signal s(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,2,6),plot(f,abs(sfm_f),'color','black','linewidth',2); title('Modulated signal S(f)'); xlabel('frequency (kHz)'); ylabel('amplitude'); subplot(4,2,7),plot(y,'color','black','linewidth',2); title('Demodulated signal y(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,2,8),plot(f,abs(y_f),'color','black','linewidth',2); title('Demodulated signal Y(f)'); xlabel('frequency (kHz)'); ylabel('amplitude'); %DC shift in the demodulated wave y_dc=mean(y); %amplitude of demodulated signal y_amp=max(y(500:1500))-mean(y); %maximum value in steady state is used display(y_dc);display(y_amp); %comparing message signal and demodulated signal figure(2) plot(m,'color','black','linewidth',2);

hold on plot(y,'color','black','linewidth',2); title('Comparison of message signal and demodulated signal'); xlabel('samples'); ylabel('amplitude');

RESULTS:
For =2:

amplitude

amplitude

0 -1

500 0

500

1000

1500

2000

2500

10

20

30

amplitude

60

70

80

2000
amplitude

0 -1

1000 0

500

1000

1500

2000

2500

10

20

30

amplitude

60

70

80

1000
amplitude

0 -1

500 0

500

1000

1500

2000

2500

10

20

amplitude

## 40 50 frequency (kHz) Demodulated signal Y(f)

30

60

70

80

4000
amplitude

1 0

2000 0

500

1000 samples

1500

2000

2500

10

20

30

40 50 frequency (kHz)

60

70

80

## Comparison of message signal and demodulated signal 2

1.5

amplitude

0.5

-0.5

-1

500

1000 samples

1500

2000

2500

For =5:
Comparison of message signal and demodulated signal 2

1.5

amplitude

0.5

-0.5

-1

500

1000 samples

1500

2000

2500

For =10:
Comparison of message signal and demodulated signal 2

1.5

amplitude

0.5

-0.5

-1

500

1000 samples

1500

2000

2500

Mathematical justification for the small amplitude and DC shift in demodulated signal:
The modulated signal is represented as follows: (referring Simon haykin, Communication Systems, 4th edition, pg 114, 115) ( ) ( ) ( ) ( ( ( )[ ( ( ) ( ) ( ( ( )) )]) )) ( ( ) )

Let H(f) be the Fourier transform of the Hilbert transform h(t) of s(t), then ( ) ( ) ( ( )[ ( ) ( ( ) ( ( ) ( ( ) ( ) ( ) ( )) ( )) )]) ( ) ( )

Thus the Hilbert transform shifts all positive frequencies by /2. Using the hilbert() function in matlab returns a complex sequence whose real part contains s(t) and imaginary part contains the Hilbert transform h(t)of s(t). Let this signal be denoted by y1: ( ) ( ) Or ( ) Taking the conjugate of y1, ( ) Or ( ) ( ( ( ))) ( ( )) ( ( )) (( ( ))) ( ( ( ) )) () ( ( ))

Delaying the signal by 1 sample means is equivalent to delaying it by 1/fs = Ts, where Ts is time interval between two samples and fs is sampling frequency. Let the delayed signal be denoted by y3,

## ( ) ( ) ( ( Or ( ) Multiplying y1(t) by y3(t): ( ) ( ) ( ) ( ( ( ( ( ( ( ) ( ( ( ( ( ( ( ( )

( )

) ( ( ( ( ))) )))

))))

( ( (

)))) )) ))

(( ( ( )))

( )))

)))

The angle() function computes the phase of the above signal: ( ) Using the identity, ( ) ( ) ( ) (( ( ) ) (( ) ( ) ) ) ( ( )) ( )

Since fmTs is very small (referring to MATLAB results), ( So the amplitude of the demodulated wave is: )

For =2,

For =5,

For =10,

## Frequency demodulation using local carrier and mixer:

MATLAB CODE:
clc; %carrier signal Ac=1; t1=0:0.25:2000; fs=80; f = fs*(0:length(t1)-1)/ length(t1); c=Ac*cos(2*pi*t1); c_f=fft(c); %message signal t2=0:0.0025:20; m=cos(2*pi*t2); m_f=fft(m); %modulation beta=2; sfm=Ac*cos(2*pi*t1+beta*sin(2*pi*t2)); sfm_f=fft(sfm); %demodulation %multiplying by local carrier y1=sfm.*c; y1_f=fft(y1); %frequency translation y2=2*y1.*cos(2*pi*t2); y2_f=fft(y2); %filtering %low pass filter with fp=290, fs=310 load lp_freqmod; y=filter(lp_freqmod,y2); y_f=fft(y); %plots subplot(4,3,1),plot(c,'color','black'); title('Carrier signal c(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,3,2),plot(f,abs(c_f),'color','black'); title('Carrier signal C(f)'); xlabel('frequency'); ylabel('amplitude'); subplot(4,3,3),plot(m,'color','black'); title('Message signal m(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,3,4),plot(f,abs(m_f),'color','black'); title('Carrier signal M(f)'); xlabel('frequency'); ylabel('amplitude'); subplot(4,3,5),plot(sfm,'color','black'); title('Modulated signal s(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,3,6),plot(f,abs(sfm_f),'color','black'); title('Modulated signal S(f)');

xlabel('frequency (kHz)'); ylabel('amplitude'); subplot(4,3,7),plot(y1,'color','black'); title('signal after multiplication with local carrier y1(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,3,8),plot(f,abs(y1_f),'color','black'); title('signal after multiplication with local carrier Y1(f)'); xlabel('frequency (kHz)'); ylabel('amplitude'); subplot(4,3,9),plot(y2,'color','black'); title('Frequency translated signal y2(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,3,10),plot(f,abs(y2_f),'color','black'); title('Frequency translated signal Y2(f)'); xlabel('frequency (kHz)'); ylabel('amplitude'); subplot(4,3,11),plot(y,'color','black'); title('Demodulated signal (after filtering) y(t)'); xlabel('samples'); ylabel('amplitude'); subplot(4,3,12),plot(f,abs(y_f),'color','black'); title('Demodulated signal (after filtering) Y(f)'); xlabel('frequency (kHz)'); ylabel('amplitude'); %DC shift in the demodulated wave y_dc=mean(y); %amplitude of demodulated signal y_amp=max(y(500:1500))-mean(y); %maximum value in steady state is used display(y_dc);display(y_amp); %comparing message signal and demodulated signal figure(2) subplot(2,1,1),plot(m,'color','black','linewidth',2); title('Comparison of message signal and demodulated signal'); xlabel('samples'); ylabel('amplitude'); subplot(2,1,2),plot(y,'color','black','linewidth',2); xlabel('samples'); ylabel('amplitude');

RESULTS:
For =2:

## Carrier signal c(t) 1

amplitude amplitude

amplitude

0 -1

2000

8000

10000

20

80

2000

## 4000 6000 8000 samples Modulated signal S(f)

10000

5000
amplitude amplitude

1 0 -1
amplitude

4000 2000 0

## 40 60 80 frequency signal after multiplication with local carrier y1(t)

amplitude

20

4000 6000 8000 10000 samples signal after multiplication with local carrier Y1(f)
amplitude

2000

20

80

1
amplitude

2 20 0 -2

0 -1

2000

## 4000 6000 8000 samples Frequency translated signal Y2(f)

10000

0.4 0.6 0.8 1 1.2 frequency (kHz) Demodulated signal (after filtering) y(t)
amplitude

0.2

4000 6000 8000 10000 samples Demodulated signal (after filtering) Y(f)

2000

1
amplitude

1000 500 0

160 140 120 0 0.2 0.4 0.6 0.8 frequency (kHz) 1 1.2

amplitude

0 -1

2000

## 4000 6000 samples

8000

10000

10

20 frequency (kHz)

30

40

amplitude

0 -0.5 -1

1000

2000

3000

6000

7000

8000

9000

1 0.5

amplitude

0 -0.5 -1

1000

2000

3000

## 4000 5000 samples

6000

7000

8000

9000

For =5:
Comparison of message signal and demodulated signal 1 0.5

amplitude

0 -0.5 -1

1000

2000

3000

6000

7000

8000

9000

0.2 0.1

amplitude

0 -0.1 -0.2

1000

2000

3000

## 4000 5000 samples

6000

7000

8000

9000

For =10:
Comparison of message signal and demodulated signal 1 0.5

amplitude

0 -0.5 -1

1000

2000

3000

6000

7000

8000

9000

0.01 0.005

amplitude

0 -0.005 -0.01

1000

2000

3000

## 4000 5000 samples

6000

7000

8000

9000

Mathematical justification for the frequency component at 2fm when modulated signal is multiplied by local carrier:
The modulated signal is represented as follows: (referring Simon haykin, Communication Systems, pg 114, 115) ( ) ( ) ( ) ( ( ( )[ ( ( ) ( ) ( ( ( )) )]) )) ( ( ) )

## Multiplying s(t) by local carrier, ( ) ( ( ))

Multiplication in time domain is periodic convolution in frequency domain: ( ) ( ( ( )[ ( ) ( ( ) ( ( ) ( ( ) ( Let ( ) ( ) ( ) ( ) ( ) ( ) ( ) ) ( ) ( )) )]) ( [ ] [ ]))

For the low frequency components, ( ) Bessel function has the property: ( ) ( ) ( Expanding the summation, ( ) ( )( ) ( )) ( ) ( ) ( )

( ( ) )

( )

)(

)( )

)(

)( )

( ) ( )( )

( )

( )( )

( ) ( )( )

For odd values of n, ( ) ( )( ) and ( ) ( ) So the odd n terms cancel and Y1(f) contains only even n terms, ( ) [ ( ) ( ( ( ( ) ) ( ( )) )) ( ) ( ( ( ) ( ( ) ) ( ( )) )) ] ( ) ( )( )( )

Thus after multiplying the modulated signal by local carrier, the frequency spectrum of the resulting signal y1(t) contains impulses at 2fm, 4fm,6fm,8fm.. with magnitude decreasing with increasing n, which is due to the fact that the Bessel function n() value decreases for increasing n.