Thursday, November 5, 2009

More frequencies in FFT

Hi Transmogrifox, thank you very much for your help. We have this blog to interact and to help ourselves.

The Transmogrifox's code is given following:


//Frequency components of a signal
//----------------------------------
// build a noides signal sampled at 1000hz containing to pure frequencies
// at 50 and 70 Hz
sample_rate=1000;
t = 0:1/sample_rate:0.6;
N=size(t,'*'); //number of samples
s=sin(2*%pi*50*t)+ 0.3*sin(2*%pi*70*t+%pi/4)+ 0.2*grand(1,N,'nor',0,1);

y=fft(s);
//the fft response is symetric we retain only the first N/2 points
f=sample_rate*(0:(N/2))/N; //associated frequency vector
n=size(f,'*')
yy = y*2/N;
clf()
plot2d(f,abs(yy(1:n)))


And the following picture is the result.



So, if anyone has any question, I think I and Transmogrifox are ready for help.

Tuesday, October 27, 2009

Response in frequency

Hi Cek, I saw your comment (here), and I'd like to say that I never worked with these functions before. But we can learn about the functions.

Let's start with the freq(.) function.

This code is the example in Scilab's help.


s = poly(0, 's');
sys = (s+1)/(s^3-5*s+4);
rep = freq(sys("num"), sys("den"), [0,0.9,1.1,2,3,10,20]);
[horner(sys, 0), horner(sys, 20)]
//
Sys = tf2ss(sys);
[A, B, C, D] = abcd(Sys);
freq(A, B, C, [0, 0.9, 1.1, 2, 3, 10, 20])


In the code, we see the function freq(.) is used with polynomials (in the Space of Laplace). The last argument (the vector [0, 0.9, 1.1, 2, 3, 10, 20]) represents the calculated frequencies for the polynomial sys.

The function tf2ss(.) means time/frequency to state-space.

The function refreq(.) does the same things of the function freq(.), but it uses other arguments.

Look the function's description, in Scilab's help.

[ [frq,] repf] = repfreq(sys, fmin, fmax [, step])
[ [frq,] repf] = repfreq(sys [, frq])
[ frq, repf, splitf] = repfreq(sys, fmin, fmax [, step])
[ frq, repf, splitf] = repfreq(sys [, frq])

Parameters

sys: syslin list : SIMO linear system
fmin, fmax: two real numbers (lower and upper frequency bounds)
frq: real vector of frequencies (Hz)
step: logarithmic discretization step
splitf: vector of indexes of critical frequencies.
repf: vector of the complex frequency response



The function horner(.) evaluates a polynomial in a specific point, for example:

s = poly(0,'s');
M = [s, 1/s]; // M is the polynomial in analysis
x1 = horner(M,1)
x1
x1 =

1. 1.

x2 = horner(M,%i)
x2 =

i - i

x3 = horner(M,1/s)
x3 =

1 s
- -
s 1



If you want, then we can try to learn anything about the others functions: bode, syslin and csim.

Friday, October 23, 2009

Operations element by element, again

Hi Jackmatze, how are you? I think you are just as old as me, but it's other thing.
About your question, I made a post that answers you: it's here.

So, let me show an example:

-->matrix1 = [1 2 1;
-->2 1 2;
-->1 2 3]
matrix1 =

1. 2. 1.
2. 1. 2.
1. 2. 3.

-->matrix2 = [1 1 2;
-->0 2 1;
-->1 3 1]
matrix2 =

1. 1. 2.
0. 2. 1.
1. 3. 1.

-->matrix_t = matrix1*matrix2
matrix_t =

2. 8. 5.
4. 10. 7.
4. 14. 7.

-->matrix_dott = matrix1.*matrix2
matrix_dott =

1. 2. 2.
0. 2. 2.
1. 6. 3.


Now, what's the difference of matrix1^2 and matrix1.^2?

matrix1^2 = matrix1*matrix1

matrix1.^2 = matrix1.*matrix1


Ok, Jack? Anything more, I'll try to help you.