Modulation and Demodulation of Amplitude and Frequency matlab Code

Modulation and Demodulation of Amplitude and Frequency matlab Code

I tried my level best to make this project best, but it as some limitation. The user must enter the number of samples near about 10000, for better result. Otherwise the result are not accurate. User can only choose the message signal from the basic signals in matlab as square,sawtooth,sine, and cos.

The idea of the project is to do amplitude modulation and frequency modulation in matlab. We represent message signal, carrier signal, modulating signal, with their frequency spectrum, by using fft command and fft shift command. AM and FM Modulation and Demodulation Matlab Source Code :

 

Code:

close all; clear all;clc;
 
%************************************************%
%                Amplitude Modulation            %
%************************************************%
 
%********************Variables******************%
 
 fs=input('Enter sampling frequency= ');      % sampling frequency
 fm=2;          % Modulatig Signal Frequency
 fc=50;         % Carrier Frequency
 Am=1;          % Modulatig Signal Amplitude
 Ac=1;          % Carrier Signal Amplitude
 
 %*********************Signals*******************%
 
 Wc=2*pi*fc;
 Wm=2*pi*fm;
 t=0:1/(fs):1;
 choice = questdlg('Choose input for AM','Input','Sine','square', 'Sawtooth', '');
 switch choice
    case 'Sine'
         Modulating_Signal=Am*sin(Wm*t);
         case 'square'
         Modulating_Signal=Am*square(Wm*t);
    case 'Sawtooth'
         Modulating_Signal=Am*sawtooth(Wm*t);
end
 
 carrier_Signal = Ac*sin(Wc*t);
 
 %********************MODULATION*****************%
 
 AM_time= Modulating_Signal.*carrier_Signal;
 AM_Freq=fftshift(abs(fft(AM_time)));
 
 %**********************Plot*********************%
 figure(1);subplot(321);plot(t,carrier_Signal);
 title('AM carrier signal');xlabel('time'),ylabel('amplitude');grid on;
 
 car_Sig_freq=fftshift(abs(fft(carrier_Signal)));
 axiss=-fs/2:fs/(length(car_Sig_freq)-1):fs/2
 figure(1);subplot(322);plot(axiss,car_Sig_freq);axis([-1000 1000 0 6000])
 title('Carrier signal FREQ');xlabel('Frequency'), ylabel('amplitude');grid on;
 
 figure(1);subplot(323);plot(t,Modulating_Signal);
 title('AM modulating signal');
 xlabel('time'), ylabel('amplitude');grid on;
 
 Mod_Sig_freq=fftshift(abs(fft(Modulating_Signal)));
 axiss=-fs/2:fs/(length(Mod_Sig_freq)-1):fs/2
 figure(1);subplot(324);plot(axiss,Mod_Sig_freq);axis([-1000 1000 0 6000])
 title('Modulating signal FREQ');
 xlabel('Frequency'), ylabel('amplitude');grid on;
 
 figure(1);subplot(325);plot(t,AM_time);
 title('AM time-domain');
 xlabel('time'), ylabel('amplitude');grid on;
 
 axiss=-fs/2:fs/(length(AM_Freq)-1):fs/2;
 figure(1);subplot(326);plot(axiss,AM_Freq);axis([-1000 1000 0 6000])
 title('AM frequency-domain');xlabel('frequency'), ylabel('amplitude');grid on;
 
 %********************DEMODULATION****************%
 
 AM_DM_time=AM_time.*carrier_Signal;
 AM_DM_Freq=fftshift(abs(fft(AM_DM_time)));
 
  filter=fir1(200,fm/fs,'low');
  orignal_t_Signal=conv(filter,AM_DM_time);
  orignal_f_Signal=fftshift(abs(fft(orignal_t_Signal)));
 
 figure(2);subplot(221);plot(t,AM_DM_time);
 title('Demodulated Signal time-domain');xlabel('time'), ylabel('amplitude');grid on;
 
 axiss=-fs/2:fs/(length(AM_DM_Freq)-1):fs/2;
 figure(2);subplot(222);plot(axiss,AM_DM_Freq);axis([-1000 1000 0 6000])
 title('Demodulated Signal freq-domain');xlabel('frequency'), ylabel('amplitude');grid on;
 
 t1=0:1/(length(orignal_t_Signal)-1):1
 figure(2);subplot(223);plot(t1,orignal_t_Signal);
 title('Filterd Signal time-domain');xlabel('time'), ylabel('amplitude');grid on;
 
 axiss=-fs/2:fs/(length(orignal_f_Signal)-1):fs/2;
 figure(2);subplot(224);plot(axiss,orignal_f_Signal);axis([-1000 1000 0 6000])
 title('Filterd Signal freq-domain');
 xlabel('frequency'), ylabel('amplitude');grid on;clear all;
 
 
%************************************************%
%                Frequency Modulation            %
%************************************************%
 
%***************Variables************************%
 
 Ac=1;      %carrier signal amplitude
 Am=1;      %Modulation signal amplitude
 fm=2;    %Modulating signal frequncy
 fc=50;   %carrier signal frequncy
 m=10;      % index of FM
 
 %********************Signal********************%
 fs=10000;
 Wc=2*pi*fc;
 Wm=2*pi*fm;
 t=0:1/(fs-1):1;
 choice1 = questdlg('Choose input for FM','Input','Sine','cosine',  '');
 switch choice1
    case 'Sine'
         Modulating_Signal=Am*sin(Wm*t);
         case 'cosine'
         Modulating_Signal=Am*cos(Wm*t);
  end
 
 
 Carrier_Signal_fm = Ac*cos(Wc*t);
 
 
 %********************Modulation****************%
 m=10; %modulating index
 FM_time= Ac*cos((Wc*t)+m*Modulating_Signal);
 FM_Freq=fftshift(abs(fft(FM_time)));
 %Demodulation
 FM_DEM_T= 100*demod(FM_time,fc,fs,'fm'); %Hilbert transform gives 90 phase shift
 FM_DEM_F=fftshift(abs(fft(FM_DEM_T)));
 axisx=-fs/2:fs/(length(FM_DEM_F)-1):fs/2
 %*****************Plot*************************%
 
 figure(3);subplot(221);plot(t, Modulating_Signal);
 title('FM modulating signal');
 
 mod_Sig_fre=fftshift(abs(fft(Modulating_Signal)));
 axiss=-fs/2:fs/(length(mod_Sig_fre)-1):fs/2
 figure(3);subplot(222);plot(axiss,mod_Sig_fre);axis([-1000 1000 0 6000])
 title('Mod signal Freq');xlabel('Frequncy'), ylabel('amplitude');grid on;
 
 figure(3);subplot(223);plot(t, Carrier_Signal_fm);
 title('FM Carrier signal');
 
 Carrier_Signal_freq=fftshift(abs(fft( Carrier_Signal_fm)));
 axiss=-fs/2:fs/(length( Carrier_Signal_freq)-1):fs/2
 figure(3);subplot(224);plot(axiss,Carrier_Signal_freq);axis([-1000 1000 0 6000])
 title('Carrier signal Freq');xlabel('Frequency'), ylabel('amplitude');grid on;
 
 figure(4);subplot(221);plot(t,FM_time);
 xlabel('time(second)'),ylabel('amplitude');title('FM Modulated time-domain');grid on;
 
 FM_Sig_freq=fftshift(abs(fft(FM_time)));
 axiss=-fs/2:fs/(length(FM_Sig_freq)-1):fs/2
 figure(4);subplot(222);plot(axiss, FM_Sig_freq);
 title('FM signal Freq');xlabel('Frequncy'), ylabel('amplitude');grid on;
 
 figure(4);subplot(223);plot(t,FM_DEM_T);
 title('FM DEmodulated signal Time');
 
 figure(4);subplot(224);plot(axiss,FM_DEM_F);
 title('FM DEmodulated signal Freq');
 
_______________________________________________________________


6 Comments

  1. null May 2, 2013
  2. cheap mens suits April 29, 2013
  3. ugg April 28, 2013
  4. flUectChooche April 23, 2013
  5. anonymous April 6, 2013
  6. Steve Richard March 27, 2013

laanoversikt.com