forked from wozy13/DIAMOND
-
Notifications
You must be signed in to change notification settings - Fork 0
/
impsig.m
29 lines (22 loc) · 900 Bytes
/
impsig.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
% Generate an user-specified impulse function
%
%This routine will generate a user specified, half sine wave impulse. The
function [x,time]=impsig(T,td,f,t,nt);
%user will specify %the pulse duration, t, the peak amplitude, F, the time
%delay, td, for the start of the %pulse, and the number of points used to
%describe the impulse, nt, and the total length of the signal,T. Since
%the signal is equally spaced, be sure to choose a large enough number
%of points to capture the impulse. The signal is designed to be
%equally spaced to allow simulation.
%round delay time and duration time to nearest dt
dt=T/nt;
tdn=round(td/dt)*dt;
tn=round(t/dt)*dt;
%define the impulse
ttemp=linspace(0,tn,round(t/dt));
fr=1/(2*tn);
sig=f*sin(2*pi*fr*ttemp);
%insert the impulse in the correct position in the signal
x=zeros(1,nt);
x(round(td/dt)+1:round(td/dt)+round(t/dt))=sig;
time=linspace(0,T,nt);