不能在 OCTAVE 中做 amdemod
Cannot do amdemod in OCTAVE
我找到了以下代码来做 AM mod 和 demod 的实验。但是我不能 运行 它在八度音阶上,因为我卡在过滤 demod 上,因为 Octave 说格式不同......我如何将它们绘制到频率域中?
代码如下
% Parameters
Fs = 44100;
T = 1;
Fc = 15000;
Fm = 10;
% Low-pass filter design
[num,den] = butter(10,1.2*Fc/Fs);
% Signals
t = 0:1/Fs:T;
x = cos(2*pi*Fm*t);
y = ammod(x,Fc,Fs);
z = amdemod(y,Fc,Fs);
w = amdemod(y,Fc,Fs,0,0,num,den);
% Plot
figure('Name','AM Modulation');
subplot(4,1,1); plot(t,x); title('Modulating signal');
subplot(4,1,2); plot(t,y); title('Modulated signal');
subplot(4,1,3); plot(t,z); title('Demodulated signal');
subplot(4,1,4); plot(t,w); title('Demodulated signal (filtered)');
条件(https://octave.sourceforge.io/communications/function/ammod.html) is in a Octave package "communications" that you may have to install or load. You find the package on https://octave.sourceforge.io/communications/index.html and the instructions to install any package on https://octave.org/doc/interpreter/Installing-and-Removing-Packages.html
在 Octave 中,包 communications
中的 amdemod
只允许正好三个输入参数,当您使用 type amdemod
:
时可以查看
## Copyright (C) 2007 Sylvain Pelissier <sylvain.pelissier@gmail.com>
##
## 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{m} =} amdemod (@var{s}, @var{fc}, @var{fs})
## Compute the amplitude demodulation of the signal @var{s} with a carrier
## frequency of @var{fc} and a sample frequency of @var{fs}.
## @seealso{ammod}
## @end deftypefn
function m = amdemod (s, fc, fs)
if (nargin != 3)
print_usage ();
endif
t = 0:1./fs:(length (s) - 1)./fs;
e = s .* cos (2.*pi.*fc.*t);
[b a] = butter (5, fc.*2./fs);
m = filtfilt (b, a, e).*2;
endfunction
%% Test input validation
%!error amdemod ()
%!error amdemod (1)
%!error amdemod (1, 2)
%!error amdemod (1, 2, 3, 4)
从这个意义上说,w = amdemod(y,Fc,Fs,0,0,num,den)
行没有通过,因为输入参数的数量不是3
。
我找到了以下代码来做 AM mod 和 demod 的实验。但是我不能 运行 它在八度音阶上,因为我卡在过滤 demod 上,因为 Octave 说格式不同......我如何将它们绘制到频率域中?
代码如下
% Parameters
Fs = 44100;
T = 1;
Fc = 15000;
Fm = 10;
% Low-pass filter design
[num,den] = butter(10,1.2*Fc/Fs);
% Signals
t = 0:1/Fs:T;
x = cos(2*pi*Fm*t);
y = ammod(x,Fc,Fs);
z = amdemod(y,Fc,Fs);
w = amdemod(y,Fc,Fs,0,0,num,den);
% Plot
figure('Name','AM Modulation');
subplot(4,1,1); plot(t,x); title('Modulating signal');
subplot(4,1,2); plot(t,y); title('Modulated signal');
subplot(4,1,3); plot(t,z); title('Demodulated signal');
subplot(4,1,4); plot(t,w); title('Demodulated signal (filtered)');
条件(https://octave.sourceforge.io/communications/function/ammod.html) is in a Octave package "communications" that you may have to install or load. You find the package on https://octave.sourceforge.io/communications/index.html and the instructions to install any package on https://octave.org/doc/interpreter/Installing-and-Removing-Packages.html
在 Octave 中,包 communications
中的 amdemod
只允许正好三个输入参数,当您使用 type amdemod
:
## Copyright (C) 2007 Sylvain Pelissier <sylvain.pelissier@gmail.com>
##
## 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{m} =} amdemod (@var{s}, @var{fc}, @var{fs})
## Compute the amplitude demodulation of the signal @var{s} with a carrier
## frequency of @var{fc} and a sample frequency of @var{fs}.
## @seealso{ammod}
## @end deftypefn
function m = amdemod (s, fc, fs)
if (nargin != 3)
print_usage ();
endif
t = 0:1./fs:(length (s) - 1)./fs;
e = s .* cos (2.*pi.*fc.*t);
[b a] = butter (5, fc.*2./fs);
m = filtfilt (b, a, e).*2;
endfunction
%% Test input validation
%!error amdemod ()
%!error amdemod (1)
%!error amdemod (1, 2)
%!error amdemod (1, 2, 3, 4)
从这个意义上说,w = amdemod(y,Fc,Fs,0,0,num,den)
行没有通过,因为输入参数的数量不是3
。