clear all; %% Create a gaussian % Params: freq=logspace; % frequency of the sine wave (Hz) sampRate=1000; % sampling rate % Centered time vector time = -2:1/sampRate:2; % make a Gaussian c = logspace; s = c/(2*pi*freq); gaussian_win = exp(-time.^2./(2*s^2)); for 1:length(vetor) wavelet = sinewave .* gaussian_win; end figure, clf ; set(gcf, 'color','w', 'WindowState', 'maximize'); plot( time,gaussian_win ,LineWidth=5,Color='#b31084'); box off;grid on ax = gca; % Get current axes handle ax.LineWidth = 4; ax.FontSize = 20; ax.GridLineWidth = 1; %% Create a sine wave % make a sine wave sinewave = exp( 1i*2*pi*freq*time); figure, clf ; set(gcf, 'color','w', 'WindowState', 'maximize'); plot(time, sinewave, 'b-',LineWidth=7,Color='#b31084'); box off ax = gca; % Get current axes handle ax.LineWidth = 4; ax.FontSize = 20; %% create a morlet wavelet wavelet = sinewave .* gaussian_win; figure, clf ; set(gcf, 'color','w', 'WindowState', 'maximize'); plot( time,wavelet ,LineWidth=5,Color='#b31084'); box off;grid on ax = gca; % Get current axes handle ax.LineWidth = 4; ax.FontSize = 20; %% FFT numPoints=sampRate*2; all_size = round(size(wavelet,2)/4); long_nfft = numPoints; hann_all = .5 - cos(2*pi*linspace(0,1,size(wavelet,2)))./2; [cmx_welch,welch_hz] = pwelch(wavelet,hann_all,all_size,long_nfft,sampRate); [bsd_welch,welch_hz] = pwelch(sinewave,hann_all,all_size,long_nfft,sampRate); figure(1), clf set(gcf, 'color','w', 'Position', get(0, 'Screensize')) subplot(1,1,1) plot(welch_hz,10*log10(cmx_welch(1:length(welch_hz))),'linew',2),hold on plot(welch_hz,10*log10(bsd_welch(1:length(welch_hz))),'linew',2) xlabel('Frequency (Hz)'), ylabel('Power(dB)') title ('Wavelet vs. Sine ') set(gca,'xlim',[1 30]) legend('wavelet','sine wave') axis square box off grid on