plot a sine wave of a vector
Afficher commentaires plus anciens
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 commentaires
KSSV
le 14 Juil 2020
Why it can't work??? What problem you are facing?
Rohit Anand
le 14 Juil 2020
Assuming that records is a vector and that you need to plot sin(records) vs. records you can easily do so using the plot command...
% For continuous plot
plot(records, sin(records));
% for discrete plot
stem(records, sin(records))
If this is not what you want, Please elaborate the issue further.
John Skinner
le 14 Juil 2020
Rohit Anand
le 15 Juil 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.
Réponses (1)
Star Strider
le 15 Juil 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 commentaires
John Skinner
le 15 Juil 2020
Star Strider
le 15 Juil 2020
Itt’s likely possible, however much depends on what you want from the data. One option would be to use the detrend function before doing any other analyses (such as I have done here). Much depends on what your signal is, how you obtained it, and what liberties you can take with it.
Try this:
y = load('Data.txt');
x = linspace(0, numel(y), numel(y));
L = numel(y);
ym = y-mean(y);
Fs = 1/mean(diff(x));
Fn = Fs/2;
FTy = fft(ym)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
loglog(Fv, abs(FTy(Iv))*2)
grid
That plots the Fourier transform of your signal, and from it, you can determine at least some of the information you want. (I used a loglog plot the make the low-frequency details more evident. Use plot to remove the logarithmic transformations.)
John Skinner
le 17 Juil 2020
Star Strider
le 17 Juil 2020
Great!
Waiting...
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!