function [time,TT,tmax,dt,wtot,Wf,fx,pos_fx]=input_signal_generation(nnu,Nc,nsteps,ratiotime) % function [time,wtot,Wf,fx,pos_fx]=input_signal_generation(nnu,Nc,nsteps) % generates a harmonic signal with prescribed characteristic % frequency and number of cycles by using a sinusoidal function as the % smoothening function and calculates its frequency spectrum %-----INPUT---------------------------------------------------------------% % -nnu % (scalar) Frequency in Hz (cycles per second) % -Nc % (scalar) N. of oscillation cycles in the burst % -nsteps % (scalar) N. of intervals in the burst time window %-----OUTPUT--------------------------------------------------------------% % -time % (1 x nsteps+1) Time domain array % -wtot % (1 x nsteps+1) Signal time history % -fx % (1 x nsteps+1) Frequency domain array % -Wf % (1 x nsteps+1) Signal frequency spectrum % -pos_fx % (1 x nsteps/2) Positive frequencies %------------------------------------------------------------------------% %---------------------------BEGIN ROUTINE--------------------------------% %------------------------------------------------------------------------% TT=1/nnu; t1max=Nc/nnu; %ratiotime=1; tmax=t1max*ratiotime; dt=tmax/nsteps; time=0:dt:tmax; t1=0:dt:t1max; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% we=2*pi*nnu; %w1=sin(we*t1/(2*Nc)); %w1=ones(1,length(t1)); w1=rectwin(length(t1))'; w2=sin(we*t1); wtemp=w1.*w2; wtot=zeros(size(time)); wtot(1,1:length(t1))=wtemp'; % figure (11), hold on, plot(time,wtot,'ro-'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% PUT ratiotime=5 dt=tmax/1000 for smooth Fourier transform fsamp=1/(time(2)-time(1)); % fsamp=1/(t1(2)-t1(1)); fx=fsamp*(-length(time)/2:length(time)/2-1)/length(time); pos_fx=find(fx>=0); % fx=fsamp*(-length(t1)/2:length(t1)/2-1)/length(t1); % pos_fx=find(fx>=0); Wf=fft(wtot); Wf=fftshift(Wf); % Wf=find(Wf>=0); % w2 % figure, semilogx(fx(pos_fx),abs(Wf(pos_fx))/max(abs(Wf(pos_fx))),'LineWidth',2) % axis tight; grid on %------------------------------------------------------------------------% %----------------------------END ROUTINE---------------------------------% %------------------------------------------------------------------------%