% Interval endpoints c = 0; d = 1; % Interpolation points n = 64; t = c+(d-c)*(0:n-1)/n; % "Continuous signal" w = 2*pi/(d-c); %f = @(t) 1 + cos(2*w*t) + 0.25*sin(10*w*t); f = @(t) 1 + cos(2*w*t) + 0.25*sin(10*w*t) + 0.2*randn(size(t)); x = f(t); y = fft(f(t))/sqrt(n); % Matlab uses different scaling than the textbook figure(1); plot(t,x,'b','LineWidth',3); xlabel('t'); ylabel('x'); figure(2); %plot(abs(y),'b','LineWidth',3); plot((1:n)-n/2-1,abs(fftshift(y)),'b','LineWidth',3); xlabel('k'); ylabel('y'); if 1, % Low pass filter: cut all waves starting from k_cut k_cut = 5; y_filt= zeros(size(y)); % Copy frequencies up to k_cut (remember, in Matlab indexing starts % from 1) y_filt(1:k_cut) = y(1:k_cut); % copy "negative frequencies": the ones from the second half of the % spectrum y_filt(n-k_cut+2:n) = y(n-k_cut+2:n); % recover the filtered signal x_filt = ifft(y_filt)*sqrt(n); % plot the original and filtered signals figure(1); plot(t,x,'b',... t,x_filt,'r'); xlabel('t'); ylabel('x'); end