How To Create A Periodic Triangle Function?
9 ビュー (過去 30 日間)
古いコメントを表示
I have the task of creating a periodic triangular function that I then must calculate the Fourier transform with fft and plot the amplitude spectrum.
The curve should be symmetrical with respect to the origin in 1024 points. It should look like:
[0 1 2 3 4 3 2 1 0 -1 -2 -3 -4 -3 -2 -1 …]
I must also be able to test with different time periods and use more points.
1 件のコメント
Star Strider
2012 年 11 月 23 日
Does ‘symmetrical with respect to the origin’ mean that it's an even or odd function?
回答 (3 件)
Azzi Abdelmalek
2012 年 11 月 23 日
w=4; % signal width
Amp=4; % signal amplitude
tt=-w:w
t1=-2*w:0;
t2=0:2*w;
t=[t1 t2];
y1=Amp-Amp*abs(tt)/w ;
y=[y1 -y1]
plot(t,y)
for the fft you need just one period
0 件のコメント
Matt J
2012 年 11 月 23 日
f=@(x) mod(x-1,16)+1;
data=[0 1 2 3 4 3 2 1 0 -1 -2 -3 -4 -3 -2 -1];
signal=data(f(1:1024));
0 件のコメント
Image Analyst
2012 年 11 月 23 日
編集済み: Image Analyst
2012 年 11 月 23 日
You can try wavegen() here: http://daimi.au.dk/~pmn/Matlab/dochome/toolbox/commtbx (Thanks to Walter for the link. It also requires triangle there).
Or you can try my demo. It's longer than the others' code because it defines parameters to make it flexible and has code for making fancy plots.
clc; % Clear command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 15;
% Define some parameters that define the triangle wave.
elementsPerHalfPeriod = 30; % Number of elements in each rising or falling section.
amplitude = 5; % Peak-to-peak amplitude.
verticalOffset = -2; % Also acts as a phase shift.
numberOfPeriods = 4; % How many replicates of the triangle you want.
% Construct one cycle, up and down.
risingSignal = linspace(0, amplitude, elementsPerHalfPeriod);
fallingSignal = linspace(amplitude, 0, elementsPerHalfPeriod);
% Combine rising and falling sections into one single triangle.
oneCycle = [risingSignal, fallingSignal(2:end-1)] + verticalOffset;
x = 0 : length(oneCycle)-1;
% Now plot the triangle.
subplot(2, 1, 1);
plot(x, oneCycle, 'bo-');
grid on;
title('One Cycle of the Triangle', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Now replicate this cycle several (numberOfPeriods) times.
waveform = repmat(oneCycle, [1 numberOfPeriods]);
x = 0 : length(waveform)-1;
% Now plot the triangle wave.
subplot(2, 1, 2);
plot(x, waveform, 'bo-');
grid on;
title('Several Cycles of the Triangle', 'FontSize', fontSize);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Transforms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!