%% conv1demo1 %% show a signal and convolution pair %% show dft of convolving mask % define signal, sample rate, sample domain N = 128; t = (0:1:(N-1))/N; I = sqrt(-1); %sig = 2*cos(5*2*pi*t)+0.5*sin(60*2*pi*t); %sig = cos(5*2*pi*t); sig = sin(30*2*pi*t); %sig = sin(60*2*pi*t); %k = 96; sig = [ones(1,k),zeros(1,N-k)]*(N/k); %sig = rand(1,N); %sig = 2*rand(1,N)-1; %k =50, sig = exp(k*2*I*pi*t); SD = 0:(N-1); FD = SD-N/2; % define convolving mask %f = [1/2,1/2], f = [f,zeros(1,N-length(f))]; f = [1/2,-1/2], f = [f,zeros(1,N-length(f))]; %f1 = [3,2,1]/9, f2 = [1,2]/9, f = [f1,zeros(1,N-length(f1)-length(f2)),f2]; % compute convolution and dft fsig =circconv(sig,f); sff =fftshift(fft(f)); % display results figure(1) subplot(2,1,1) plot(SD, real(sig),'r',SD, imag(sig),'g') title('sampled signal'); axis tight subplot(2,1,2) plot(SD, real(fsig),'r',SD, imag(fsig),'g') title('filtered signal') axis tight figure(2) subplot(2,1,1) plot(FD, abs(sff),'r-' ) title('magnitude of shifted DFT of mask') axis tight subplot(2,1,2) plot(FD, angle(sff),'g-' ) title('phase of shifted DFT of mask') axis tight