git-svn-id: http://moon:8086/svn/matlab/trunk@100 801c6759-fa7c-4059-a304-17956f83a07c
99 lines
2.0 KiB
Objective-C
Executable File
99 lines
2.0 KiB
Objective-C
Executable File
## Copyright (C) 2018 Jens Ahrensfeld
|
|
##
|
|
## This program is free software; you can redistribute it and/or modify it
|
|
## under the terms of the GNU General Public License as published by
|
|
## the Free Software Foundation; either version 3 of the License, or
|
|
## (at your option) any later version.
|
|
##
|
|
## This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
## -*- texinfo -*-
|
|
## @deftypefn {Function File} {@var{retval} =} im_eval (@var{input1}, @var{input2})
|
|
##
|
|
## @seealso{}
|
|
## @end deftypefn
|
|
|
|
## Author: Jens Ahrensfeld <ahrensfeld@w2ess001vm>
|
|
## Created: 2018-10-22
|
|
|
|
function s = im_eval ()
|
|
|
|
s1 = sig_gen('lo', 'sine', [0 500], [0.0 1]);
|
|
s2 = sig_gen('s1', 'sine', [0 100 500 900 1400], [0.0 0.5 1.0 0.5 0.25]);
|
|
|
|
s = modulate(s1, s2);
|
|
|
|
close all;
|
|
plotSig(s);
|
|
function s = sig_gen(name, type, freq, amp)
|
|
|
|
peaks = [];
|
|
switch type
|
|
case 'sine'
|
|
f = freq;
|
|
a = amp;
|
|
case 'rect'
|
|
N = 10;
|
|
f = [];
|
|
a = [];
|
|
k = 1;
|
|
for n=1:N
|
|
f = [f k*freq];
|
|
a = [a amp/k];
|
|
k = k + 2;
|
|
end
|
|
endswitch
|
|
|
|
s = struct('name', name, 'f', f, 'a', a);
|
|
endfunction
|
|
|
|
function m = modulate(s1, s2)
|
|
|
|
m = struct('name', sprintf("%s x %s", s1.name, s2.name), 'f', [], 'a', []);
|
|
|
|
f = [];
|
|
a = [];
|
|
|
|
for i=1:length(s1.f)
|
|
for j=1:length(s2.f)
|
|
f1 = s1.f(i) - s2.f(j);
|
|
f2 = s1.f(i) + s2.f(j);
|
|
a = s1.a(i) * s2.a(j);
|
|
|
|
m = addFreq(m, f1, a);
|
|
m = addFreq(m, f2, a);
|
|
end
|
|
end
|
|
|
|
endfunction
|
|
|
|
function x = addFreq(x, f, a)
|
|
|
|
found = 0;
|
|
for i=1: length(x.f)
|
|
if (x.f(i) == f)
|
|
found = i;
|
|
break;
|
|
end
|
|
end
|
|
if (found > 0)
|
|
x.a(found) = x.a(found) + a;
|
|
elseif a ~= 0
|
|
x.f = [x.f f];
|
|
x.a = [x.a a];
|
|
end
|
|
|
|
endfunction
|
|
|
|
function plotSig(s)
|
|
stem(s.f, s.a, 'baseline', -10); grid; legend(s.name)
|
|
endfunction
|
|
|
|
endfunction
|