plot a sine wave of a vector

18 views (last 30 days)
John Skinner
John Skinner on 14 Jul 2020
Commented: Star Strider on 17 Jul 2020
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
John Skinner
John Skinner on 14 Jul 2020
Hi and thanks for the response
Rohit, I did try to use the plot function but all I get is a straight line and I need to see the wave line. Sorry but I am not sure of the propper name for it.
This is the code that I have previously used which is that same as you suggested.
records = csvread("Data.txt");
plot(records, sin(records))
I have attached two jpg files with the output that I am getting and the output that I need.
If you look at straight.jpg then that is the result that I am getting.
If you look at wave.jpg then that is the result that I need
I have also attached the data file that I am using and also the script file that I have so far
Thanks again,
John
Rohit Anand
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.

Sign in to comment.

Answers (1)

Star Strider
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
John Skinner
John Skinner on 17 Jul 2020
Hi Star Strider,
I am now examining this. I will get back to you with the ewsults
Star Strider
Star Strider on 17 Jul 2020
Great!
Waiting...

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!