Sunteți pe pagina 1din 13

MATLAB CODE For Amplitude Modulation

fs = 100;

t = (0:1/fs:100)';

fc = 10;

x = sin(2*pi*t);

ydouble = ammod(x,fc,fs);

ysingle = ssbmod(x,fc,fs);

sa = dsp.SpectrumAnalyzer('SampleRate',fs, ...

'PlotAsTwoSidedSpectrum',false, ...

'YLimits',[-60 40]);

step(sa,ydouble)

MATLAB OUTPUT :

AMPLITUDE MODULATION
MATLAB CODE for Amplitude Demodulation

fc = 10e3;

fs = 80e3;

t = (0:1/fs:0.01)';

s = sin(2*pi*300*t)+2*sin(2*pi*600*t);

[num,den] = butter(10,fc*2/fs);

y = ammod(s,fc,fs);

z = amdemod(y,fc,fs,0,0,num,den);

plot(t,s,'c',t,z,'b--')

legend('Original Signal','Demodulated Signal')

xlabel('Time (s)')

ylabel

MATLAB Output :

AMPLITUDE DEMODULATION
MATLAB CODE For Frequency Modulation

clear all;

close all;

clc;

%% Frequency MODULATION of Triangular Signal

t = -0.04:1.e-4:0.04;

Ta = 0.01;

fc = 200;

msg = msg1(t,Ta);

%% MODULATION

kf = 160*pi;

m_int = kf*1.e-4*cumsum(msg);

fm = cos(2*fc*pi*t + m_int);

%% DEMODULATION (Using Differentiator)

dem = diff(fm);

dem = [0,dem];

rect_dem = abs(dem);

%% Filtering out High Frequencies

N = 80;

Wn = 1.e-2;

a = fir1(N,Wn);

b = 1;

rec = filter(a,b,rect_dem);
%% Finding frequency Response of Signals

fl = length(t);

fl = 2^ceil(log2(fl));

f = (-fl/2:fl/2-1)/(fl*1.e-4);

mF = fftshift(fft(msg,fl));

fmF = fftshift(fft(fm,fl));

rect_demF = fftshift(fft(rect_dem,fl));

recF = fftshift(fft(rec,fl));

%% Plotting signal in time domain

figure;

subplot(2,1,1);

plot(t,msg);

title('Message Signal');

xlabel('{\it t} (sec)');

ylabel('m(t)');

grid;
MATLAB OUTPUT :

FRQUENCY MODULATION
MATLAB CODE For Frequency Demodulation

fs = 1000;

fc = 200;

t = (0:1/fs:0.2)';

x = sin(2*pi*30*t)+2*sin(2*pi*60*t);

fDev = 50;

y = fmmod(x,fc,fs,fDev);

z = fmdemod(y,fc,fs,fDev);

plot(t,x,'c',t,z,'b--');

xlabel('Time (s)')

ylabel('Amplitude')

legend('Original Signal','Demodulated Signal')

MATLAB OUTPUT :

FREQUENCY DEMODULATION
MATLAB CODE For Phase Modulation

fs = 50;
t = (0:2*fs+1)'/fs;
Create a sinusoidal input signal.
x = sin(2*pi*t) + sin(4*pi*t);
Set the carrier frequency and phase deviation.
fc = 10;
phasedev = pi/2;
Modulate the input signal.
tx = pmmod(x,fc,fs,phasedev);
Pass the signal through an AWGN channel.
rx = awgn(tx,10,'measured');
Demodulate the noisy signal.
y = pmdemod(rx,fc,fs,phasedev);
Plot the original and recovered signals.
figure; plot(t,[x y]);
legend('Original signal','Recovered signal');
xlabel('Time (s)')
ylabel('Amplitude (V)')

MATLAB OUTPUT

PHASE MODULATION
MATLAB CODE For Phase Demodulation

fs = 50;

t = (0:2*fs+1)'/fs;

x = sin(2*pi*t) + sin(4*pi*t);

fc = 10;

phasedev = pi/2;

tx = pmmod(x,fc,fs,phasedev);

rx = awgn(tx,10,'measured');

y = pmdemod(rx,fc,fs,phasedev);

figure; plot(t,[x y]);

legend('Original signal','Recovered signal');

xlabel('Time (s)')

ylabel('Amplitude (V)')

MATLAB OUTPUT :

PHASE DEMODULATION
MATLAB CODE For Pre-Emphasis

clear; clc; close all;

%frequency response of a filter with differencial equation y[n]=x[n]-0.95*x[x-1]

h=[1 -0.95];

freqz(h); zoom on; grid on;

title('frequency response')

%attenuation of a LOW frequency signal

t=0:1:500;

f1=0.01;

x=sin(2*pi*f1*t);

y=filter(h,1,x);

figure;

plot(x,'-b'); hold on;

plot(y, '-r'); zoom on; grid on;

legend('input', 'output');

title('attenuation of a LOW frequency signal')

%enhancement of a HIGH frequency signal

t=0:1:100;

f1=0.3;

x=sin(2*pi*f1*t);

y=filter(h,1,x);

figure;

plot(x,'-b'); hold on;

plot(y, '-r'); zoom on; grid on;


legend('input', 'output');

title('enhancement of a HIGH frequency signal');

MATLAB OUTPUT :
MATLAB CODE For De-Emphasis
close all

clear all

clc

num_samples = 2^13;

fs=5000;

Ts=1/fs;

fm1=20;

fm2=30;

fc=200;

t=(0:num_samples-1)*Ts;

f=(-num_samples/2:num_samples/2-1)*fs/num_samples;

mt=sin(2*pi*fm1*t);

Mf=fftshift(abs(fft(mt)));

f_cutoff_pe=10;

Wn_pe=f_cutoff_pe/(fs/2)

[b_pe,a_pe]=butter(1,Wn_pe);

[H_pe,W]=freqz(a_pe,b_pe);

a_de=b_pe;

b_de=a_pe;

[H_de,W]=freqz(a_de,b_de);

mt_pe=filter(a_pe,b_pe,mt);

Mf_pe=fftshift(abs(fft(mt_pe)));

subplot(211);

plot(t,mt)
axis([0 .6 min(mt)-1 max(mt)+1])

grid on;title('Modulating Signal (Time Domain)')

subplot(212);

plot(f,Mf)

grid on;axis([-50 50 0 max(Mf)+100])

title('Modulating Signal (timeDomain)')

figure(2)

subplot(211)

semilogx(W*pi*(fs/2),abs(H_pe),'m','linewidth',2)

axis([0 fs/2 0 50])

grid on;

subplot(212)

semilogx(W*pi*(fs/2),abs(H_de),'m','linewidth',2)

axis([0 fs/2 0 1])

grid on;

title('De-emphasis Filter Magnitude Response')


MATLAB OUTPUT :

Modulating Signal (Time Domain)

De-Emphasis Filter Magnitutde Response

S-ar putea să vă placă și