Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- close all
- clc
- Fs = 1000; % Sampling frequency
- T = 1/Fs; % Sampling period
- L = 128; % Length of signal
- t = (0:L-1)*T; % Time vector
- S = sin(2*pi*10*t) + sin(2*pi*20*t) + sin(2*pi*40*t) + sin(2*pi*80*t);
- X = S + 2*randn(size(t));
- plot(1000*t(1:50),X(1:50))
- title('Signal Corrupted with Zero-Mean Random Noise')
- xlabel('t (milliseconds)')
- ylabel('X(t)')
- Y = fft(X);
- P2 = abs(Y/L);
- P1 = P2(1:L/2+1);
- P1(2:end-1) = 2*P1(2:end-1);
- f = Fs*(0:(L/2))/L;
- plot(f,P1)
- title('Single-Sided Amplitude Spectrum of X(t)')
- xlabel('f (Hz)')
- ylabel('|P1(f)|')
- Y = fft(S);
- P2 = abs(Y/L);
- P1 = P2(1:L/2+1);
- P1(2:end-1) = 2*P1(2:end-1);
- plot(f,P1)
- title('Single-Sided Amplitude Spectrum of S(t)')
- xlabel('f (Hz)')
- ylabel('|P1(f)|')
- N = 2048; fpr=100; fx1=10; fx2=20; fx3=40;fx4=80;
- nx = 0:N-1; dt = 1/fpr; t = dt*nx;
- x1 = cos(2*pi*fx1*t);
- x2 = cos(2*pi*fx2*t);
- x3 = cos(2*pi*fx3*t);
- x4 = cos(2*pi*fx4*t);
- x = x1 + x2 + x3 + x4;
- M = 7; fg = 20;
- h = fir1(M-1,2*fg/fpr);
- subplot(311); stem(f,'filled'); grid;
- title('Sygnał filtrowany');
- subplot(312); stem(Y,'filled'); grid;
- title('Odp impulsowa filtru FIR');
- subplot(313)
- splot = conv(S,h,'same');
- plot(splot)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement