% MATLAB is frequently used to process signals % 1. Fourier transforms x = rand(1,10); y = fft(x); % Fast Fourier Transform of x iy = ifft(y); % inverse fft norm(x-iy) ans = 2.2645e-016 % 2. Waveform and Amplitude spectrum dt = 1/100; % sampling rate et = 4; % end time t = 0:dt:et; % defines sampling range y = 3*sin(4*2*pi*t) + 5*sin(2*2*pi*t); % now that we have our signal sampled, we plot it subplot(2,1,1); plot(t,y); grid on axis([0 et -8 8]); xlabel('Time (s)'); ylabel('Amplitude'); % with the fft we find the characteristics % of the signal Y = fft(y); % from the time to frequency domain n = size(y,2)/2; % number of samples/2 amp_spec = abs(Y)/n; subplot(2,1,2) freq = (0:79)/(2*n*dt); plot(freq,amp_spec(1:80)); grid on; xlabel('Frequency (Hz) '); ylabel('Amplitude'); % looking at the second plot, we see the % essential characteristics of the signal % 3. filtering noise noise = randn(1,size(y,2)); ey = y + noise; eY = fft(ey); n = size(ey,2)/2; figure subplot(2,1,1); plot(t,ey); grid on; axis([0 et -8 8]); xlabel('Time (s)'); ylabel('Amplitude'); subplot(2,1,2); freq = (0:79)/(2*n*dt); amp_spec = abs(eY)/n; plot(freq,amp_spec(1:80)); grid on xlabel('Frequency (Hz)'); ylabel('Amplitude'); % now we do the restoration of the signal, % by removal of the low amplitude noise figure plot(Y/n,'r+') hold on plot(eY/n,'bx'); fY = fix(eY/100)*100; % numbers < 100 are cut ifY = ifft(fY); cy = real(ifY); figure plot(t,cy); grid on xlabel('Time (s)'); ylabel('Amplitude'); % compare with the original signal figure plot(t,y); grid on xlabel('Time (s)'); ylabel('Amplitude'); diary off