Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear;
- warning off;
- %
- % A sinusoid base signal (optionally with a gaussian envelope) and a freq sweep in a dot product plot
- %
- % multiply base signal with gaussian bell or not
- gaussian_envelope = false
- % sample rate, time base
- srate = 500;
- time = -1:1/srate:1-1/srate;
- % base signal
- freq = 5;
- phase = 0*pi/4;
- base = sin(2 * pi * freq * time + phase);
- % multiplied by gaussian envelope
- if gaussian_envelope
- envelope = exp((-time .** 2) / .1);
- else
- envelope = ones(1, length(time)); % identity
- end
- signal = base .* envelope;
- % plot base signal (and gaussian)
- subplot(211);
- hold on, grid on
- plot(time, envelope, 'g', 'linew', 2);
- plot(time, signal, 'k', 'linew', 3);
- hold off;
- title('Signal with envelope');
- % not required because of autoscale later
- % set(gca, 'xlim', [-1 1]);
- % dot product with signal and frequency sweep
- sweep_freqs = 2:.2:8; % 2Hz to 8Hz with step of .2Hz
- dot_prods = zeros(length(sweep_freqs));
- for sweep_freq_index = 1:length(sweep_freqs)
- sweep_signal = sin(2 * pi * sweep_freqs(sweep_freq_index) * time);
- dot_prods(sweep_freq_index) = dot(sweep_signal, signal); % / length(time);
- endfor
- % stem plot for dot prod / sweep frequencies
- subplot(212);
- hold on, grid on
- stem(sweep_freqs, dot_prods, 'k', 'linew', 3, 'markersize', 10, 'markerfacecolor', 'b');
- hold off
- title('Dot products by sweep frequency');
- % not required because of autoscale later
- % set(gca, 'ylim', [sweep_freqs(1)-.5 sweep_freqs(end)+.5], 'ylim', [-2 2]);
- % autoscale now
- axis("auto");
- % print('dot_prod_w_gaussian_envelope.svg', '-dsvg', '-S1280,1024');
- waitforbuttonpress();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement