## Copyright (C) 2009, 2010 Thomas Weidenfeller
## 
## This file is part of gds2000tools/gds-octave.
## 
## gds2000tools/gds-octave is free software: you can redistribute it
## and/or modify it under the terms of the GNU General Public License
## version 3 as published by the Free Software Foundation.
## 
## gds2000tools/gds-octave is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
## 
## You should have received a copy of the GNU General Public License
## along with gds2000tools/gds-octave.  If not,
## see <http://www.gnu.org/licenses/>.
##

## usage: [GDSSTRUCT_AM] = gds_am(GDSSTRUCT)
## usage: gds_am(GDSSTRUCT)
##
## Simple AM demodulator.
##
## Create a waveform GDSSTRUCT_AM, which contains the amplitude
## demodulation of the signal in GDSSTRUCT.
#
## NOTE: The demodulator is rather simple. It does not use octave's amdemod(),
## this function requires knowledge of the carrier frequency
## in advance. However, the used simple algorithm provides limited results.
##
## Example:
##
## gs = gds_csvread("DS0003.CSV");
## am = gds_am(gs);
## subplot (2,1,1);
## gds_plot(gs);
## subplot (2,1,2);
## gds_plot(am);
##
## See also: gds_plot(), gds_fm()
##

## Author: Thomas Weidenfeller
## Created: 2010-12-28
## Version: $Id: gds_am.m,v 1.3 2010/12/31 02:28:33 tw Exp $
## Keywords: Oscilloscope, GDS-2000, gds2000tools, AM, demodulator

function [gsam] = gds_am(gs)
	if(nargin != 1 || !isstruct(gs))
		print_usage();
	endif

	gs.Waveform_Data = abs(hilbert(gs.Waveform_Data));
	gs.Source = [ gs.Source " - AM Demod." ];
	## TODO: Need to correctly scale amplitude
	gs.Vertical_Units = "Amplitude";
	gs.Trigger_Level = 0;

	if(nargout < 1)
		gds_plot(gs);
	else
		gsam = gs;
	endif

endfunction
