[Scilab-users] Generation of linear frequency
Lester Anderson
arctica1963 at gmail.com
Sun Mar 10 10:55:26 CET 2013
On 10 March 2013 09:49, Lester Anderson <arctica1963 at gmail.com> wrote:
> On 10 March 2013 09:02, TViT <tvitklg at rambler.ru> wrote:
>
>> Hello!
>>
>> In Matlab there is a function chirp, and what is in Scilab?
>>
>> And why Scilab can not transform a simple example from Matlab of a file?
>>
>> //-----------------------------------------------------
>> t = 0:0.001:2; % 2 secs @ 1kHz sample rate
>> y = chirp(t,0,1,150); % Start @ DC,
>> % cross 150Hz at t=1 sec
>> spectrogram(y,256,250,256,1E3,'yaxis')
>> //-----------------------------------------------------
>>
>> !--error 37
>> at line 190 of function mfile2sci called by :
>> at line 142 of function cb_m2sci_gui called by :
>> cbo = getcallbackobject("-6ebf8d73:13d5388519a:-7f72");cb_m2sci_gui;if
>> exists("%oldgcbo") then gcbo = %oldgcbo;
>> while executing a callback
>>
>>
>>
>> --
>> View this message in context:
>> http://mailinglists.scilab.org/Generation-of-linear-frequency-tp4026202.html
>> Sent from the Scilab users - Mailing Lists Archives mailing list archive
>> at Nabble.com.
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> http://lists.scilab.org/mailman/listinfo/users
>>
>
> Google the function as chirp.m and you will get the code:
>
> function x = chirp( T, W, p )
> %CHIRP generate a sampled chirp signal
> %----- exp(j(W/T)pi*t^2) -T/2 <= t < +T/2
> %
> % Usage: X = chirp( T, W, <P> )
> %
> % X : N=pTW samples of a "chirp" signal
> % T : time duration from -T/2 to +T/2
> % W : swept bandwidth from -W/2 to +W/2
> %
> % optional (default is P = 1)
> % P : samples at P times the Nyquist rate (W)
> % i.e., sampling interval is 1/(PW)
>
> %---------------------------------------------------------------
> % copyright 1994, by C.S. Burrus, J.H. McClellan, A.V. Oppenheim,
> % T.W. Parks, R.W. Schafer, & H.W. Schussler. For use with the book
> % "Computer-Based Exercises for Signal Processing Using MATLAB"
> % (Prentice-Hall, 1994).
> %---------------------------------------------------------------
>
> if nargin < 3
> p = 1; end
> J = sqrt(-1);
> %--------------
> delta_t = 1/(p*W);
> N = round( p*T*W ); %--- same as T/delta_t
> nn = [0:N-1]';
> x = exp( J*pi*W/T * (delta_t*nn - T/2).^2 );
>
> Just recode in Scilab and place in your main source code or set in a
> functions libarry to be called.
> May be different versions of this so best to check around
>
Another more detailed version;
function y = chirp(t,f0,t1,f1,method,phi)
%CHIRP Swept-frequency cosine generator.
% Y = CHIRP(T,F0,T1,F1) generates samples of a linear swept-frequency
% signal at the time instances defined in array T. The instantaneous
% frequency at time 0 is F0 Hertz. The instantaneous frequency F1
% is achieved at time T1. By default, F0=0, T1=1, and F1=100.
%
% Y = CHIRP(T,F0,T1,F1,method) specifies alternate sweep methods.
% Available methods are 'linear','quadratic', and 'logarithmic'; the
% default is 'linear'. Note that for a log-sweep, F1>F0 is required.
%
% Y = CHIRP(T,F0,T1,F1,method, PHI) allows an initial phase PHI to
% be specified in degrees. By default, PHI=0.
%
% Y = CHIRP(T,P) specifies a polynomial vector P for the
% instantaneous frequency trajectory of the chirp. P may not be
% a scalar value.
%
% Default values are substituted for empty or omitted trailing input
% arguments.
%
% EXAMPLE 1: Compute the spectrogram of a linear chirp.
% t=0:0.001:2; % 2 secs @ 1kHz sample rate
% y=chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1sec
% specgram(y,256,1E3,256,250); % Display the spectrogram
%
% EXAMPLE 2: Compute the spectrogram of a quadratic chirp.
% t=-2:0.001:2; % +/-2 secs @ 1kHz sample rate
% y=chirp(t,100,1,200,'q'); % Start @ 100Hz, cross 200Hz at t=1sec
% specgram(y,128,1E3,128,120); % Display the spectrogram
%
% EXAMPLE 3: Compute the spectrogram of a polynomial chirp.
% t=[0 0.5 1.0 1.5 2.0]; % time breakpoints
% f=[0 200 100 150 300]; % instantaneous frequency breakpoints
% p=polyfit(t,f,4); % fit 4th order polynomial over time
% t=0:0.001:2; % 2 secs @ 1kHz sample rate
% y=chirp(t,p);
% subplot(211); plot(t,polyval(p,t)); set(gca,'ylim',[0 500]);
% subplot(212); specgram(y,128,1E3,128,120);
%
% See also GAUSPULS, SAWTOOTH, SINC, SQUARE.
% Author(s): D. Orofino, T. Krauss, 3/96
% Copyright 1988-2000 The MathWorks, Inc.
% $Revision: 1.7 $ $Date: 2000/06/09 22:03:53 $
% Parse inputs, and substitute for defaults:
error(nargchk(1,6,nargin));
if nargin<6, phi=[]; end
if nargin<5, method=[]; end
if nargin<4, f1=[]; end
if nargin<3, t1=[]; end
if nargin<2, f0=[]; end
if isempty(phi), phi=0; end
if isempty(method), method='linear'; end
if isempty(f1), f1=100; end
if isempty(t1), t1=1; end
if isempty(f0), f0=0; end
% Parse the method string:
if length(f0)>1,
method='polynomial';
else
% Set p=1 for linear, 2 for quadratic, 3 for logarithmic
strs = {'linear','quadratic','logarithmic'};
p = strmatch(lower(method),strs);
if isempty(p),
error('Unknown method selected.');
elseif length(p)>1,
error('Ambiguous method selected.');
end
method = strs{p};
end
switch method
case 'polynomial'
% Polynomial chirp
y = cos( 2*pi * polyval(polyint(f0),t) );
case {'linear','quadratic'},
% Polynomial chirp: p is the polynomial order
beta = (f1-f0).*(t1.^(-p));
y = cos(2*pi * ( beta./(1+p).*(t.^(1+p)) + f0.*t + phi/360));
case 'logarithmic',
% Logarithmic chirp:
if f1<f0, error('F1>F0 is required for a log-sweep.'); end
beta = log10(f1-f0)/t1;
y = cos(2*pi * ( (10.^(beta.*t)-1)./(beta.*log(10)) + f0.*t + phi/360));
end
% [EOF] chirp.m
Not familiar with the function myself but I am sure others can guide you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20130310/08950905/attachment.htm>
More information about the users
mailing list