MATLAB Answers

Applying phase selection on chirp

1 view (last 30 days)
hello,
I am trying to create a swept-frequency cosine, and I want to be able to set the phase as I please. I tried that code, but I get an error. I want to create a vector mat(1:40), where I can manually set its phase.
Fs = 32000; %Sampling Frequency
t = 0: 1/Fs: 10 -1/Fs; %Time
tt = 10; %Time when the chance occurs
f1 = 20; %Starting Frequency
f2 = 250; %Ending Frequency
cosineph = zeros(1,40); %Phase of sines
for iMat= 1:40
k=iMat/2;
mat(iMat) = chirp(t,k*f1,tt,k*f2,'linear',cosineph(iMat));
end
The error that I am getting is " In an assignment A(I) = B, the number of elements in B and I must be the same."
Now, I am guessing it refers to variable t, so I tried implementing that into an embedded for, but didn't get the results I wanted.
Any advice?
Thanks

  0 Comments

Sign in to comment.

Accepted Answer

tony karamp
tony karamp on 1 Apr 2013
it seems that the way to go is to replace the vector, with a cell. So the code alters like that:
for iMat= 1:40
k=iMat/2;
mat{iMat} = chirp(t,k*f1,tt,k*f2,'linear',cosineph(iMat));
end

  0 Comments

Sign in to comment.

More Answers (0)