Sim+ example : real signal low-pass filter.
The following screenshot shows two windows: in the left window is the simulated system block diagram (in this example - entered with MicroSim's schematics), the right window shows power-spectrum plots of the input and output signals of the filter. To generate spectrum plots, the raw (real) signals are saved to files "x.sig" and 'y.sig", then imported to Matlab, the actual power spectrum computation and plotting is done in Matlab.
Blocks used in this simulation
| Name | Description |
|---|---|
| rand_r | real random number generator. if the PDF pin is set to 'N' then normal
distribution is applied (with zero mean and var=1), otherwise this block
generates uniform distributed random variables in the range [-0.5,0.5] the values at the output of rand_r are statistically independent. |
| cheby1_r | chebyshev type 1 real signal filter. the user has to set type, cutoff frequency, sampling frequency, passband ripple (in dB), and filter order. |
| sink_r | this block is used to save raw signals to text file. files generated with this block are easily read by other software such as Matlab or other math / plot packages. |
Sample block definition : 'rand_r.df'
//
// RAND_R.DF
//
// if PDF='N' then normal (gaussian) distribution, otherwise uniform
//
%%Inputs
double HOLD
char PDF
%%Outputs
double Z (HOLD,PDF)
%%StateVars
double X1
double X2
double Za
double Zb
int n
%%Initialization
n = 0;
X1 = (1E-49+rand())/(2E-49+RAND_MAX);
X2 = (1E-49+rand())/(2E-49+RAND_MAX);
if(PDF=='N'){
Za = sqrt(-2*log(X1))*cos(2*PI*X2);
Zb = sqrt(-2*log(X1))*sin(2*PI*X2);
}
else{
Za = X1-0.5;
Zb = X2-0.5;
}
%%OutputEquations
Z = ( n==0 ? Za : Zb )
%%StateEquations
if(!(HOLD>0.0)){
if(n==1){ // since we have to
X1 = (1E-49+rand())/(2E-49+RAND_MAX); // use pairs of RVs
X2 = (1E-49+rand())/(2E-49+RAND_MAX); // to make single
if(PDF=='N'){ // RV each sample,
Za = sqrt(-2*log(X1))*cos(2*PI*X2); // the RV pair is
Zb = sqrt(-2*log(X1))*sin(2*PI*X2); // generated every other
} // sample.
else{
Za = X1-0.5;
Zb = X2-0.5;
}
n=-1;
}
++n;
}
%%Termination
%%End