Signal Processin1
Signal Processin1
EXP 7
% Clear workspace, close all figures, and clear command window
clear all, close all, clc
% Define parameters
n = 120;
f1 = 10; % Signal frequency
t = 1/n * (0:1:119); % Time vector
x = 10 * cos(2*pi*f1.*t); % Signal
xf = fft(x); % Fourier Transform of the signal
freq = -n/2 : n/2-1; % Frequency vector
fs = 40; % Sampling Frequency
y = zeros(size(t));
y(1:n/fs:end) = 1; %Sampling Function
yf = fft(y); % Fourier Transform of the Sampling Function
z = y .* x; % Multiplication of the Signal with Sampling signal the in time domain
(Sampled Signal)
zf = fft(z); % Fourier Transform of the Sampled Signal
%% Low Pass Filter with cutoff frequency fs/2
flf = [zeros(1, 0.5*(length(t)-fs)) ones(1,fs+1) zeros(1,0.5*(length(t)-fs)-1)]; %
Low pass filter in Frequency domain
figure(1)
subplot(2,1,1)
plot(freq, flf)
grid on, xlabel('Frequency, Hz'), ylabel('Magnitude, fft(LPF)')
title('Frequency response of filter')
flf_t = real(fftshift(ifft(fftshift(flf)))); % Low pass filter in Time domain
subplot(2,1,2)
plot(freq, flf_t)
grid on, xlabel('Time, t'), ylabel('Time domain Response')
title('Time Domain Response of Filter')
%% Multiplication in Frequency Domain
kf = fftshift(flf) .* zf; % Multiplication in frequency domain
k = ifft(kf); %Reconstructed signal in Time domain
figure(2)
subplot(3,1,1)
plot(t, x)
grid on, xlabel('Time, t'), ylabel('x(t)'), title('Original signal')
subplot(3,1,2)
plot(t, k)
grid on, xlabel('Time, t'), ylabel('x(t)'), title('Reconstructed signal')
subplot(3,1,3)
plot(freq, abs(fftshift(kf))) % Plot the Spectrum of the reconstructed Signal
grid on, xlabel('Frequency, Hz')
ylabel('|fft (x)|'), title('Magnitude response of XF')
x = 10 * cos(2*pi*f1.*t)+ 5 * cos(2*pi*f2.*t); where f1=10 Hz and f2=20 Hz