image thumbnail

Study of AM Modulation and Demodulation

by

 

This demo helps to study and analyze AM MOD and DEMOD.

AMModDemod_Demo(varargin)
function varargout = AMModDemod_Demo(varargin)
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%% Developed By  Mr.Gajanan B. and  Ms.Mansi S.
%
%%%%%%%%%%%%%%%%%%%
%%
% AMMODDEMOD_DEMO M-file for AMModDemod_Demo.fig
%      AMMODDEMOD_DEMO, by itself, creates a new AMMODDEMOD_DEMO or raises the existing
%      singleton*.
%
%      H = AMMODDEMOD_DEMO returns the handle to a new AMMODDEMOD_DEMO or the handle to
%      the existing singleton*.
%
%      AMMODDEMOD_DEMO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in AMMODDEMOD_DEMO.M with the given input arguments.
%
%      AMMODDEMOD_DEMO('Property','Value',...) creates a new AMMODDEMOD_DEMO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before AMModDemod_Demo_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to AMModDemod_Demo_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help AMModDemod_Demo

% Last Modified by GUIDE v2.5 31-Mar-2011 11:38:54

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @AMModDemod_Demo_OpeningFcn, ...
                   'gui_OutputFcn',  @AMModDemod_Demo_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before AMModDemod_Demo is made visible.
function AMModDemod_Demo_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to AMModDemod_Demo (see VARARGIN)

% Choose default command line output for AMModDemod_Demo
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes AMModDemod_Demo wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = AMModDemod_Demo_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

vm=get(handles.slider1,'value'); % Amplitude of Modulating Signal

fm=get(handles.slider2,'value'); % Frequency of Modulating Signal

handles.ejex=0:1/1000:1;
axes(handles.axes1)
set(handles.text3,'string',vm);

set(handles.text4,'string',fm);

% axes(handles.axes1)
v_m=vm*cos(2*pi*fm*handles.ejex); % Modulating Signal Waveform

plot(handles.ejex,v_m,'-','Color',[0 1 0]);
%y_c=cos(2*pi*100*handles.ejex);
% title('MOD SIGNAL');
ylabel('Amplitude'); 
xlabel('Time (s)'); % Display Modulating Signal

% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject    handle to slider2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

vm=get(handles.slider1,'value');

fm=get(handles.slider2,'value');

handles.ejex=0:1/1000:1;
axes(handles.axes1)
set(handles.text3,'string',vm);

set(handles.text4,'string',fm);

% axes(handles.axes1)
v_m=vm*cos(2*pi*fm*handles.ejex);

plot(handles.ejex,v_m,'-','Color',[0 1 0]);
%y_c=cos(2*pi*100*handles.ejex);
% title('Mod SIGNAL');
ylabel('Amplitude');
xlabel('Time (s)');

% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function slider3_Callback(hObject, eventdata, handles)
% hObject    handle to slider3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

vc=get(handles.slider3,'value'); % Carrier Signal Amplitude
fc=get(handles.slider4,'value');  % Carrier Signal Frequency

handles.ejex=0:1/1000:1;
axes(handles.axes2)
set(handles.text12,'string',vc);
set(handles.text14,'string',fc);
% axes(handles.axes1)
v_c=vc*cos(2*pi*fc*handles.ejex); % Carrier signal Waveform

plot(handles.ejex,v_c,'-','Color',[0 1 0]);
%y_c=cos(2*pi*100*handles.ejex);
% title('CARRIER SIGNAL');
ylabel('Amplitude');
xlabel('Time (s)');
% --- Executes during object creation, after setting all properties.
function slider3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function slider4_Callback(hObject, eventdata, handles)
% hObject    handle to slider4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

vc=get(handles.slider3,'value');
fc=get(handles.slider4,'value');

handles.ejex=0:1/1000:1;
axes(handles.axes2)
set(handles.text12,'string',vc);
set(handles.text14,'string',fc);
% axes(handles.axes1)
v_c=vc*cos(2*pi*fc*handles.ejex); %Carrier Signal Waveform

plot(handles.ejex,v_c,'-','Color',[0 1 0]);
%y_c=cos(2*pi*100*handles.ejex);
% title('CARRIER SIGNAL');
ylabel('Amplitude');
xlabel('Time (s)'); %Display Carrier Signal
% --- Executes during object creation, after setting all properties.
function slider4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
vm=get(handles.slider1,'value');
fm=get(handles.slider2,'value');

handles.ejex=0:1/1000:1;

v_m=vm*cos(2*pi*fm*handles.ejex);

vc=get(handles.slider3,'value');
fc=get(handles.slider4,'value');
v_c=vc*cos(2*pi*fc*handles.ejex);

v_am=v_m.*v_c; %  AM Signal Generation

axes(handles.axes3)

plot(handles.ejex,v_am);


title('AM Envelope');
ylabel('Amplitude'); % Time Domain Representation Of AM Signal 
xlabel('Time (s)');
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
vm=get(handles.slider1,'value');
fm=get(handles.slider2,'value');

handles.ejex=0:1/1000:1;

v_m=vm*cos(2*pi*fm*handles.ejex);

vc=get(handles.slider3,'value');
fc=get(handles.slider4,'value');
v_c=vc*cos(2*pi*fc*handles.ejex);

v_am=v_m.*v_c; % AM Signal Generation

w=v_am;
Ts=1/1000;
N=256;
y = fft(w(1:N)); % y contains 256 complex amplitudes

m = abs(y); % m = magnitude of sinusoids
%
% plot spectrum 0....fs/2
ff=(-N/2:N/2-1)/(Ts*N);
fws=fftshift(m);
%n=floor(log(length(w))/log(2)); 
% N=2^n; 
% fw=abs(fft (w(1:N)));
% ssf=(-N/2:N/2-1)/(Ts*N);
% % fws=fftshift(fw); %
axes(handles.axes4)
plot(ff,fws);
xlabel('Frequency')
ylabel('Magnitude');

title('Spectrum of AM signal'); % Freqency Domain Representation of AM Signal


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
vm=get(handles.slider1,'value');
fm=get(handles.slider2,'value');

handles.ejex=0:1/1000:1;

v_m=vm*cos(2*pi*fm*handles.ejex);

vc=get(handles.slider3,'value');
fc=get(handles.slider4,'value');
v_c=vc*cos(2*pi*fc*handles.ejex);

v_am=v_m.*v_c;

% filt_ord = 5 ;         % filter order
% fc_filt=500;
% Fs_filt=1000;
% fcut = fc_filt /2; 
% s=v_am;
% % absolute value of the modulated signal
% s_abs = abs(s); 
% 
% % filtering with butterworth
% [b, a] = butter(filt_ord, 2*fcut / Fs_filt, 'low'); 
% %freqz(b,a,fcut,fs),title('frequency responce of the LPF');
% % s_filt = filter(b, a, s_abs);
% 
% s_filt = filtfilt(b, a, s_abs);
% % remove the means
% s_rmvmn = (s_filt - mean(s_filt));
% 
% %biasing the signal aroung -1 and 1 V
% s_demod = s_rmvmn / max(abs(s_rmvmn));

y=v_am;
fs=1000; % Specify Sampling Freqency
x_out = demod(y,fc,fs,'am'); % Demodulate AM Signal

axes(handles.axes5)

plot(handles.ejex,x_out); % Dispaly AM Demodulator Output

Contact us