How to make a nonperiodic signal periodic?

42 ビュー (過去 30 日間)
Matthew
Matthew 2023 年 9 月 18 日
コメント済み: William Rose 2023 年 9 月 21 日
I have the below code. If you run it, you'll see a graph that runs from t = 0 to t = 7. What I'd like to do is make this signal continuous, as in it runs forever from t -∞, +∞. Of course I looked it up and I see many users use stem or syms functions to make signals but they never have signals with this many piece wise components.
Thanks so much!
clc
close all
%
t=linspace(-1,8,2356);
v_t=-2*t.*fun_unit_step_gen(t,0);
v_t= v_t+2*(t-1).*fun_unit_step_gen(t,1);
v_t= v_t+3*fun_unit_step_gen(t,2);
v_t= v_t+(t-2).*fun_unit_step_gen(t,2);
v_t= v_t-5*(t-3).*fun_unit_step_gen(t,3);
v_t= v_t+3*(t-4).*fun_unit_step_gen(t,4);
v_t= v_t+5*(t-5).*fun_unit_step_gen(t,5);
v_t= v_t-4*(t-6).*fun_unit_step_gen(t,6);
v_t= v_t-fun_unit_step_gen(t,7);
%
plot(t,v_t,'r','LineWidth',2);
axis([-1 9 -4 4])
grid
title('Function f1(t)')
hold on
px=[0,.001];py=[-5,5];
plot(px,py,'-.k','LineWidth',1)
py=[0,.001];px=[0,9];
plot(px,py,'-.k','LineWidth',1)
hold off
  3 件のコメント
William Rose
William Rose 2023 年 9 月 19 日
Since you did not provide the function fun_unit_step_gen(), I made a guess. Is my guess correct?
t=linspace(-1,8,2356);
v_t=-2*t.*(t>=0);
v_t= v_t+2*(t-1).*(t>=1);
v_t= v_t+3*(t>=2);
v_t= v_t+(t-2).*(t>=2);
v_t= v_t-5*(t-3).*(t>=3);
v_t= v_t+3*(t-4).*(t>=4);
v_t= v_t+5*(t-5).*(t>=5);
v_t= v_t-4*(t-6).*(t>=6);
v_t= v_t-(t>=7);
%
plot(t,v_t,'r','LineWidth',2);
axis([-1 9 -4 4])
grid
title('Function f1(t)')
hold on
px=[0,.001];py=[-5,5];
plot(px,py,'-.k','LineWidth',1)
py=[0,.001];px=[0,9];
plot(px,py,'-.k','LineWidth',1)
hold off
The funciton as plotted will be discontinuous at t=0, 7, 14,..., if you repeat it at those intervals. Is that OK?
William Rose
William Rose 2023 年 9 月 19 日
If you want dot-dash lines along the axes, you can do it more simply with xline() and yline():
plot(-1:8,-3+6*rand(1,10),'-r');
xline(0,'-.k'); yline(0,'-.k'); grid on

サインインしてコメントする。

採用された回答

Fabio Freschi
Fabio Freschi 2023 年 9 月 19 日
編集済み: Fabio Freschi 2023 年 9 月 19 日
I had the same idea of @William Rose, here is a possible implementation
clear variables, close all
% anonymous function
v_t = @(t)-2*t.*(t>=0)+...
2*(t-1).*(t>=1)+...
3*(t>=2)+...
(t-2).*(t>=2)+...
-5*(t-3).*(t>=3)+...
3*(t-4).*(t>=4)+...
5*(t-5).*(t>=5)+...
-4*(t-6).*(t>=6)+...
-(t>=7);
% anonymous function with period T using mod
T = 8;
v_t_per = @(t,T)v_t(mod(t,T));
% time axis
t=linspace(-8,16,2356*3);
% plot
figure, hold on, grid on
plot(t,v_t(t),'r','LineWidth',2);
plot(t,v_t_per(t,T),'b:','LineWidth',2);
  11 件のコメント
Paul
Paul 2023 年 9 月 20 日
編集済み: Paul 2023 年 9 月 21 日
There is also the Discrete Time Fourier Transform (DTFT) that can be applied to either finite duration or infinite duration signals (periodic or not), and the DTFT is a function of continuous frequency with a "continuous spectrum" in the sense that you're interpreting that phrase, i.e., delta-F -> 0, which is different than what I assumed the OP meant by that phrase. Further clarification needed from the OP as to what the goal of the problem actually is.
If you want to analyze continuous-time signals that can be expressed in closed form, as is the case with v_t, then fourier is a good place to start. If you want to analyze discrete-time signals, then fft and/or freqz are useful for finite duration signals, and fft is useful for periodic signals. As always one has to pick the right tool for the job and interpret the outputs correctly based on the problem statement.
William Rose
William Rose 2023 年 9 月 21 日
@Paul, thank you.

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2023 年 9 月 19 日
How about making it for one chunk, and then using repmat to make copies of it? You can't go from t → -∞, +∞ but you can go for some finite number of elements (indexes).

William Rose
William Rose 2023 年 9 月 19 日
If your goal is for the signal to repeat so that x(7...14)=x(0...7), and x(-7...0)=x(0...7), then I recommend using modulo division by 7 of the time argument.

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by