Effacer les filtres
Effacer les filtres

Creating a matrix of sinusoids with frequency increasing over columns and time increasing over rows

2 vues (au cours des 30 derniers jours)
I need to create a matrix/array of sinusoids with time vector increasing along rows and frequency vector increasing along columns.
t = a:int:b
f = c:int:d
y(t, f) = sin(2*pi*f*t)
The desired result is as follows (column and row headings are added for clarity of the question here):
Y{} =
f0 f1 f2 ... fn
-- --
t0 |sin(2*pi*f0*t0) sin(2*pi*f1*t0) sin(2*pi*f2*t0) ... sin(2*pi*fn*t0)|
t1 |sin(2*pi*f0*t1) sin(2*pi*f1*t1) sin(2*pi*f2*t1) ... sin(2*pi*fn*t1)|
t2 |sin(2*pi*f0*t2) sin(2*pi*f1*t2) sin(2*pi*f2*t2) ... sin(2*pi*fn*t2)|
...| ... ... ... ... ... |
tn |sin(2*pi*f0*tn) sin(2*pi*f1*tn) sin(2*pi*f2*tn) ... sin(2*pi*fn*tn)|
-- --
Help is appreciated, thanks

Réponse acceptée

Mohammad Abouali
Mohammad Abouali le 3 Oct 2014
minT=0;
maxT=1;
dT=0.01;
minF=1;
maxF=4;
dF=1;
[Time,frequency]=ndgrid( minT:dT:maxT , minF:dF:maxF );
y=sin(2*pi*frequency.*Time);
plot(Time,y);axis tight
  2 commentaires
Matt J
Matt J le 3 Oct 2014
Rick's version is more efficient, however. The use of ndgrid consumes more time and memory than the simple outer product t*Fc.

Connectez-vous pour commenter.

Plus de réponses (1)

Rick Rosson
Rick Rosson le 3 Oct 2014
Modifié(e) : Rick Rosson le 3 Oct 2014
Fs = 48000;
dt = 1/Fs;
t = (0:dt:0.25-dt)';
Fc = 60*(1:2:15);
y = sin(2*pi*t*Fc);

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by