I have a big problem to solve fast but I couldn't find anything about how to do that. I have a vector of amplitudes $1 \times n$, they are simple integers. I want to multiply these amplitudes individually by $\cos(2 \pi f t)$, where the time $t$ is defined as the vector t=0:1/(10*f):1/f in Matlab. I couldn't find any solutions and I need help. Any help will be appreciated, thanks.


closed as off-topic by MBaz, Peter K. Dec 3 '17 at 19:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – MBaz, Peter K.
If this question can be reworded to fit the rules in the help center, please edit the question.


Your time $t$ is a vector with multiple values and $\cos(2\pi ft)$ is a function of $t$ which means that $\cos(2 \pi ft)$ will also be a vector that changes with your $t$. To multiply your signal with your amplitude vector the vectors must have the same dimensions. For example:

f = 50; %frequency
amp = 1:11; %amplitude vector 1x11
t=0:1/(10*f):1/f; %time vector 1x11
x = cos(2*pi*f*t); %signal with same dimensions as the time vector
y = amp.*x; %multiplication with .* operator

Not the answer you're looking for? Browse other questions tagged or ask your own question.