Can anybody tell me how can I plot a signal like that one represented in the figure below ? I just need the part of the signal from 10 to 15. I have the following code until now :
time = 0:0.1:15;
xArray = zeros(1,numel(time)); %numel gives the number of the elements that an array has
for index = 1:numel(time)
if(time(index)>5 && time(index)<7)
xArray(index) = (time(index)-5)/2;
elseif(time(index))>= 7 && (time(index))<10
xArray(index) = 1;
elseif ((time(index) >= 10 && time(index)<15))
xArray(index) = (15 - time(index))/5;
end
end
figure (2)
plot(time,xArray);
axis([0 15 0 5]);

 채택된 답변

Image Analyst
Image Analyst 2018년 10월 15일

1 개 추천

Try this:
numPoints = 1000;
times = linspace(0, 15, numPoints);
xArray = zeros(1,numel(times)); % numel gives the number of the elements that an array has
for index = 1 : numel(times)
if times(index) > 5 && times(index) < 7
xArray(index) = (times(index)-5)/2;
elseif times(index) >= 7 && times(index) < 10
xArray(index) = 1;
elseif ((times(index) >= 10 && times(index)<15))
a = 0.7; % Smaller for flatter, larger for steeper
xArray(index) = exp(-a * (times(index) - 10));
end
end
plot(times, xArray, 'b-', 'LineWidth', 2);
xlim([0, 15]);
ylim([0, 2]);
ax = gca;
ax.YTick = [0 1];
ax.XTick = [5 7 10 15];
ax.FontSize = 15;
grid on;
xlabel('f[Hz]', 'FontSize', 15);
ylabel('x', 'FontSize', 15);
title('xArray vs. Time', 'FontSize', 15);

댓글 수: 1

Biro Darius
Biro Darius 2018년 10월 16일
Thank you very much. I'm new in MATLAB and I'm still learning things. Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Akira Agata
Akira Agata 2018년 10월 15일

0 개 추천

How about the following?
figure
plot(time,xArray)
ax = gca;
ax.YTick = [0 1];
ax.XTick = [5 7 10 15];
Biro Darius
Biro Darius 2018년 10월 18일

0 개 추천

I've came back with another question related to this subject. Now I have to build a signal such that it's spectrum looks like that one represented in the picture attached above. I mean I must have a signal and if I want to obtain the spectrum of my signal, his spectrum should looks like that one in the picture. I hope I was pretty clear. Thanks.

댓글 수: 3

Image Analyst
Image Analyst 2018년 10월 18일
Call ifft() on the signal.
Biro Darius
Biro Darius 2018년 10월 25일
Hi, I've tried before but it's not what I needed. My teacher suggested that I should build a sum of sinusoids for each part of the figure ( a sum of sinusoids from 5 to 7, another sum from 7 to 10 and the last sum from 10 to 15). He also suggested to use some iterations for frequency and amplitude. After all of this I should be able to build a unique signal consisting of the sum of the three sums of sinusoides and after I will call fft() on the final signal I should obtain a spectrum which has almost the same pattern like that one from the image. I hope I was pretty clear. Thanks.
Image Analyst
Image Analyst 2018년 10월 25일
Yes, he wants you to do it "manually" instead of having the ifft() function do it for you.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

질문:

2018년 10월 15일

댓글:

2018년 10월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by