what dose [1: equations : 0] means in MATLAB?

1 次查看(过去 30 天)
Hello;
I currently find a code to draw signal spectrogram of the signal, I got a quite good result from the signal using their given signal, but it cannot work for my own signal, I feel so confused about one code: f=[0:nhaf -nhaf+1-odvn:-1]/N; Can I ask what is that means and why it always be an empty mitrax when I try to use it for my own signal? The code and signal of the example are shows below:
SampFreq = 1000;
t = 0: 1/ SampFreq :1;
LFM_K0 = -50.34;
LFM_f0 =100.23;
LFM_A0 = exp(-0.5*t);
Sig = LFM_A0 .*cos(2*pi*(LFM_f0*t+(LFM_K0/2)*t.^2));
SNR0 =20;
ST = stran(Sig);
imagesc(t,SampFreq,abs(ST));
axis xy;
function ST=stran(h)
% Compute S-Transform without for loops
%%% Coded by Kalyan S. Dash %%%
%%% IIT Bhubaneswar, India %%%
[~,N]=size(h); % h is a 1xN one-dimensional series
nhaf=fix(N/2);
odvn=1;
if nhaf*2==N;
odvn=0;
end
f=[0:nhaf -nhaf+1-odvn:-1]/N;
Hft=fft(h);
%Compute all frequency domain Gaussians as one matrix
invfk=[1./f(2:nhaf+1)]';
W=2*pi*repmat(f,nhaf,1).*repmat(invfk,1,N);
G=exp((-W.^2)/2); %Gaussian in freq domain
% End of frequency domain Gaussian computation
% Compute Toeplitz matrix with the shifted fft(h)
HW=toeplitz(Hft(1:nhaf+1)',Hft);
% Exclude the first row, corresponding to zero frequency
HW=[HW(2:nhaf+1,:)];
% Compute Stockwell Transform
ST=ifft(HW.*G,[],2); %Compute voice
%Add the zero freq row
st0=mean(h)*ones(1,N);
ST=[st0;ST];
end
  4 个评论
Rik
Rik 2022-8-11
Let's make the sizes smaller so we can see what is happening:
signal=reshape(1:6,[],1);%create column vector
array=SomeFunctionWithImplicitExpansion(signal)
array = 6×3
1 2 3 2 4 6 3 6 9 4 8 12 5 10 15 6 12 18
function array=SomeFunctionWithImplicitExpansion(signal)
x=signal(1:(end/2)).';%select first half and transpose
array=signal.*x;%multiply element-wise
end
As you can see, the array size goes from 6 to 18, taking up tripple the space.
Now imagine doing that with your signal. You should rethink your strategy of whatever computation you're doing to split it up.
Jingyi Yuan
Jingyi Yuan 2022-8-11
That's so helpful thank you so much! And I was wondering if the downsample is an appoparate way to dectease the signal size?

请先登录,再进行评论。

采纳的回答

Rik
Rik 2022-8-11
In addition to the comment from Walter:
Your question can be answered by two searches in the documentation:
doc MATLAB Operators and Special Characters
Or (since I happen to know which specific page you need):
doc colon
: Colon. J:K is the same as [J, J+1, ..., J+m], where m = fix(K-J). In the case where both J and K are integers, this is simply [J, J+1, ..., K]. This syntax returns an empty matrix if J > K. J:I:K is the same as [J, J+I, ..., J+m*I], where m = fix((K-J)/I). This syntax returns an empty matrix when I == 0, I > 0 and J > K, or I < 0 and J < K. COLON(J,K) is the same as J:K and COLON(J,I,K) is the same as J:I:K. The colon notation can be used to pick out selected rows, columns and elements of vectors, matrices, and arrays. A(:) is all the elements of A, regarded as a single column. On the left side of an assignment statement, A(:) fills A, preserving its shape from before. A(:,J) is the J-th column of A. A(J:K) is [A(J),A(J+1),...,A(K)]. A(:,J:K) is [A(:,J),A(:,J+1),...,A(:,K)] and so on. The colon notation can be used with a cell array to produce a comma- separated list. C{:} is the same as C{1},C{2},...,C{end}. The comma separated list syntax is valid inside () for function calls, [] for concatenation and function return arguments, and inside {} to produce a cell array. Expressions such as S(:).name produce the comma separated list S(1).name,S(2).name,...,S(end).name for the structure S. For the use of the colon in the FOR statement, See FOR. For the use of the colon in a comma separated list, See VARARGIN. Documentation for colon doc colon Other functions named colon codistributor1d/colon distributed/colon gpuArray/colon codistributor2dbc/colon dlarray/colon sym/colon datetime/colon duration/colon
  2 个评论
Rik
Rik 2022-8-11
You're welcome. If this answered your question, please consider marking it as accepted answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by