Creating a cosine oscillation ( cos(2 * pi * f * k * T) )
82 views (last 30 days)
Show older comments
Hello,
I need help wiht producing a cosine oscillation with sampling frequency = 10KHz and a signal length = 2000 samples. The frequency(f) is equal to 100 Hz and the amplitude is equal to 50. I can't figure out what k exactly is.
Can anyone please help me
Thank you in advance
0 Comments
Accepted Answer
Askic V
on 10 Apr 2023
Hi Ahmad,
you can can think of k*T as a time vector, one example is:
k = 1:2000; T = 1/Fs;
tf = k*T;
y = A*cos(2*pi*f*k*T);
plot(tf,y)
More Answers (1)
Image Analyst
on 10 Apr 2023
Edited: Image Analyst
on 10 Apr 2023
A cosine wave is of the form
y = Amplitude * cos(2 * pi * omega * time)
So for your formula
Amplitude = 50;
and I beleve T is your time vector.
omega is the frequency which is f*k for you. I believe f is the lowest frequency, and it's equal to 100, and is what you'll get when k = 1. If you increase k you get harmonics of f so you'll get waveforms at twice the frequency, 3 times the frequency, 4 times the frequency, etc.
If the sampling frequency is 100000 hz, the delta between time samples is 1/10000. So after 2000 samples your time value would be 2000/10000 = 0.2 seconds. So you can construct T, your time vector, using linspace like this:
T = linspace(0, 0.2, 2000);
So in all you get
f = 100;
k = 1;
y = Amplitude * cos(2 * pi * f * k * T);
% Now plot it.
plot(T, y, 'b-', 'LineWidth', 2);
grid on;
xlabel('T');
ylabel('y');
Note you get 20 oscillations (periods) in 0.2 seconds, so you'd get 100 of them in 1 second, as you should with k=1 and f=100. If you increase k you get more oscillations in the same time interval.
I hope this helps explain it better. If it does, could you Accept the answer and/or click the "Vote" icon?
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!