generator_white_noise.m

来自「This program generates a input signal an」· M 代码 · 共 30 行

M
30
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                                         %
%  This program generates a input signal and a desired signal of the idetification plant  %
%                %
%                                                                                         %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [x,d,num]=generator_white_noise(K,snr,N,Fc);
%[x,d,num]=generator_white_noise(5000,40,32,0.5);
%[x,d,num]=generator_white_noise(5000,20,32,0.5);
%[x,d,num]=generator_white_noise(5000,15,32,0.5);

%----------------------------------------------------%
% Input parameters:
%            K    :   the length of the signal
%            N    :   the order plus 1
%            snr  :   ratio of the input signal to noise signal
%            Fc   :   the cut-off frequency of the plant
%----------------------------------------------------%

%---------------initialization-----------------------%
x=randn(1,K);                                              %  generate a random signal as input signal
d=zeros(1,K);                                              %  define the desired signal

%-----------signal generation------------------------%
num=fir1(N-1,Fc);                                          %  generate the numerator of the transforing function
den=[1];                                                   %  generate the denominator of the transforing function
d=filter(num,den,x);                                       %  get the desired signal by filtering the input signal
d=awgn(d,snr);                                             %  add the noise signal to the desired ignal

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?