%% WINDOWSINE_DEMO5 %% %% This Matlab m-file prompts the user to define a signal consisting %% of a sum of sinewaves. The user is then prompted for window %% parameters and DFT length parameters for the analysis. %% The windowed signal and its corresponding DFT are plotted. %% %% Difference between windowsine_demo4.m and windowsine_demo5.m %% is that #4 takes DT frequencies in rad/sec and assumes fs=1. %% %% #5 takes CT frequencies in Hz, and allows user to set sample %% frequency. %------------------------------------------------------------------- %%% Get the signal parameters and compute the signal disp(' ') disp('Signal parameters') disp('-----------------') f=input('Enter frequencies of sinewaves (Hz): '); amp=input('Enter amplitudes of sinewaves [DEFAULT=1]: '); if isempty(amp) amp=ones(size(f)); end phi=input('Enter phases of sinewaves [DEFAULT=0]: '); Tinterv=input('Enter length of time interval: '); fs=input('Enter sampling frequency (Hz): '); %%% Get the signal x(t) which is a sum of sinewaves [x,t]=sum_sine(f,Tinterv,fs,phi,amp); %%% Display the number of samples in signal disp(' ') str=sprintf(' X(t): contains %i samples',length(x)); disp(str); %------------------------------------------------------------------- %%% Get the window parameters and window the signal disp(' ') disp('Window parameters') disp('-----------------') win_length=input('Enter window length (number of samples): '); win_type=input('Enter window type [DEFAULT=''boxcar'']: '); if isempty(win_type) win_type='boxcar'; end %%% Window that signal ind=1:win_length; window=feval(win_type,win_length)'; v=x(ind).*window; t=t(ind); %%% Display the length of the window in seconds win_secs=(win_length-1)/fs; disp(' ') str=sprintf(' WINDOW: %s window is %0.2f seconds long',win_type,win_secs); disp(str); %------------------------------------------------------------------- %%% Get the DFT parameters and compute the sampled spectrum disp(' ') disp('DFT parameters') disp('--------------') dft_length=input('Enter DFT length [DEFAULT=8192]: '); if isempty(dft_length) dft_length=8192; end %%% Find the DFT [Vk,fk]=fr_resp(v,dft_length,fs); disp(' ') str=sprintf(' DFT size: %i points',dft_length); disp(str); %------------------------------------------------------------------- %%% Plots subplot(311) plot(t,v) axis([min(t) max(t) min(v) max(v)]) xlabel('Time (seconds)') ylabel('v(t)'); title('Windowed sinusoid') fixfont(14,14,14) subplot(212) maxdbVk=max(10*log10(abs(Vk))); plot(fk,10*log10(abs(Vk))) xlabel('Frequency (Hz)') ylabel('10*log10|V[k]|'); title('Results of DFT analysis') fixfont(14,14,14) axis([min(fk) max(fk) maxdbVk-60 maxdbVk])