plot a sine wave of a vector
18 views (last 30 days)
Show older comments
Hi,
I am new to Matlab and I am trying to plot a sine wave. All of the examples I have read don't seem to fit what I want to do so I thought I would ask for help here.
I am reading into a vector 1000 decinal numbers from a csv file. E.g. 1.23456,1.78987,1.04589 etc
Each number in the file represents the cumulation of 1 minute's worth of data so the whole file spans 1,000 minutes.
I am reading the file with the following command which populates the vector as expected.
records = csvread("data.txt");
I am now trying to plot a sinewave of these values but unfortunately I can't work it out so any help you can give would be very much appreciated
I need to end up with the following information. Amplitude, wavelength and frequency
Thanks,
John
4 Comments
Rohit Anand
on 15 Jul 2020
From what I can figure out is that You are trying to plot a sin of data that are too close to each other. Because of that you are not getting a sin curve per se. As There are not enough radians for si to complete a full cycle and it's value remains close to 0.9, hence the straight line.
As far as amplitude of the wave is concerned, plotiing this way you'll get the amplitude as 1.
As you're plotting sin(x) B It's max value will depend on range of x provided, for pi/2, it will be one.
And Frequency and Wavelength will also be constant in this case, based on the infromation you have provided.
One way like suggested below would be to use a fourier transform to extract information about different frequency components present in your line. But then again if it is a pure sine function that will not help you.
Answers (1)
Star Strider
on 15 Jul 2020
Try this:
y = load('Data.txt');
x = linspace(0, numel(y), numel(y));
figure
plot(x, y)
grid
It does not look a lot like a sine curve, however it is close enough. What information do you want from it?
.
4 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!