Filter löschen
Filter löschen

Plotting multi-component signals

2 Ansichten (letzte 30 Tage)
Hugo Espiritu
Hugo Espiritu am 21 Jun. 2015
Beantwortet: Star Strider am 21 Jun. 2015
I'm trying to plot a multi-component signal composed of the following segments in the following order:
epoch1 = 0.5*cos(pi*t) + 1.5*cos(4*pi*t) + 4*cos(5*pi*t);
epoch2 = 0.7*cos(pi*t) + 2.1*cos(4*pi*t) + 5.6*cos(5*pi*t);
epoch3 = 1.5*cos(2*pi*t) + 4*cos(8*pi*t);
epoch4 = 1.5*cos(pi*t) + 4*cos(4*pi*t);
epoch5 = 0.5*cos(pi*t) + 1.7*cos(2*pi*t) + 3.7*cos(5*pi*t);
epoch6 = 2.3*cos(3*pi*t) + 7.8*cos(8*pi*t);
epoch7 = 0.8*cos(pi*t) + cos(3*pi*t) + 3*cos(5*pi*t);
It should look like this:
I tried this:
t = [0:0.0001:50];
epoch1 = 0.5*cos(pi*t) + 1.5*cos(4*pi*t) + 4*cos(5*pi*t);
epoch2 = 0.7*cos(pi*t) + 2.1*cos(4*pi*t) + 5.6*cos(5*pi*t);
epoch3 = 1.5*cos(2*pi*t) + 4*cos(8*pi*t);
epoch4 = 1.5*cos(pi*t) + 4*cos(4*pi*t);
epoch5 = 0.5*cos(pi*t) + 1.7*cos(2*pi*t) + 3.7*cos(5*pi*t);
epoch6 = 2.3*cos(3*pi*t) + 7.8*cos(8*pi*t);
epoch7 = 0.8*cos(pi*t) + cos(3*pi*t) + 3*cos(5*pi*t);
figure;
hold
plot(t, epoch1);
plot(t, epoch2);
plot(t, epoch3);
plot(t, epoch4);
plot(t, epoch5);
plot(t, epoch6);
plot(t, epoch7);
The paper I'm reading says that it's using 50 synthetic multi-component data, which makes me think that it is sampling data points from these functions and then plotting the data points, but I'm not sure how to do that. Any help on how to to do this is appreciated.

Akzeptierte Antwort

Romil Shah
Romil Shah am 21 Jun. 2015
t = [1:0.1:7];
epoch1 = 0.5*cos(pi*t) + 1.5*cos(4*pi*t) + 4*cos(5*pi*t);
epoch2 = 0.7*cos(pi*t) + 2.1*cos(4*pi*t) + 5.6*cos(5*pi*t);
epoch3 = 1.5*cos(2*pi*t) + 4*cos(8*pi*t);
epoch4 = 1.5*cos(pi*t) + 4*cos(4*pi*t);
epoch5 = 0.5*cos(pi*t) + 1.7*cos(2*pi*t) + 3.7*cos(5*pi*t);
epoch6 = 2.3*cos(3*pi*t) + 7.8*cos(8*pi*t);
epoch7 = 0.8*cos(pi*t) + cos(3*pi*t) + 3*cos(5*pi*t);
y=[epoch1 epoch2 epoch3 epoch4 epoch5 epoch6 epoch7];
figure;
plot([1:length(y)]*0.1,y)
Hope this solves your query. MATLABhelper.com
  1 Kommentar
dpb
dpb am 21 Jun. 2015
Not well I think...the resolution of 0.1 isn't above Nyquist; try plotting just one section of the above and see what it appears like...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

dpb
dpb am 21 Jun. 2015
Bearbeitet: dpb am 21 Jun. 2015
You've plotted all of them against the same time vector instead of concatenating them; hence they're all overlaying each other.
y=[epoch1 epoch2 epoch3 epoch4 epoch5 epoch6 epoch7];
plot([1:length(y)]*0.0001,y)
will give you the plot of your constructed total vector versus you're sampling time (which turns out to be 350+ units). This will still look pretty ugly owing to visual aliasing in the window (actually, it'll probably just show up as solid banded line owing to far more points in the plot than are possible to show on a monitor owing to limited number of pixels).

Star Strider
Star Strider am 21 Jun. 2015
Another option that uses your original ‘t’ vector and then divides it for each section of the plot, plots each section and plots the vertical separator lines:
t = [0:0.0001:50];
inc = fix(length(t)/7); % Segments Of ‘t’
epoch1 = 0.5*cos(pi*t) + 1.5*cos(4*pi*t) + 4*cos(5*pi*t);
epoch2 = 0.7*cos(pi*t) + 2.1*cos(4*pi*t) + 5.6*cos(5*pi*t);
epoch3 = 1.5*cos(2*pi*t) + 4*cos(8*pi*t);
epoch4 = 1.5*cos(pi*t) + 4*cos(4*pi*t);
epoch5 = 0.5*cos(pi*t) + 1.7*cos(2*pi*t) + 3.7*cos(5*pi*t);
epoch6 = 2.3*cos(3*pi*t) + 7.8*cos(8*pi*t);
epoch7 = 0.8*cos(pi*t) + cos(3*pi*t) + 3*cos(5*pi*t);
epoch = [epoch1; epoch2; epoch3; epoch4; epoch5; epoch6; epoch7]; % Matrix of ‘epoch1’...‘epoch7’
figure(1)
plot(t(1:inc), epoch(1,1:inc), '-b') % Plot First Epoch
hold on
plot([1 1]*t(inc), [min(epoch(:)) max(epoch(:))], 'Color',[0.6 0.6 0.6], 'LineWidth',1)
for k1 = 2:6
span = [1:inc] + inc*(k1-1);
plot(t(span), epoch(k1,span), '-b')
plot([1 1]*t(span(end)), [min(epoch(:)) max(epoch(:))], 'Color',[0.6 0.6 0.6], 'LineWidth',1)
end
plot(t(inc*k1+1:end), epoch(7,inc*k1+1:end), '-b') % Plot Last Epoch
hold off
axis tight
produces this plot:
Note that it does not look like the plot you initially posted (your desired signal) because you defined your signals differently.

Kategorien

Mehr zu Geographic Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by