filtering - Fourier transform and LTI filter and frequency response in Matlab -
filtering - Fourier transform and LTI filter and frequency response in Matlab -
i'm new matlab lti signal processing , wondering if can help i'm sure meant basic. i've spent hours , hours researching , obtaining background info , still cannot obtain clear path tackle these problems. far, scratch, have generated signal required , managed utilize fft function produce signal's dft:
function x = fourier_rikki(a,t,o) fs = 1000; t = 0:(1/fs):1; = [0.5,0,0.5]; n = (length(a) - 1)/2; x = zeros(size(t)); f1 = 85; o1 = 2*pi*f1; k = 1:length(a) x1 = x + a(k)*exp(1i*o1*t*(k-n-1)); end f2 = 150; o2 = 2*pi*f2; k = 1:length(a); x2 = x + a(k)*exp(1i*o2*t*(k-n-1)); end f3 = 330; o3 = 2*pi*f3; k = 1:length(a); x3 = x + a(k)*exp(1i*o3*t*(k-n-1)); end signal = x1 + x2 + x3; figure(1); subplot(3,1,1); plot(t, signal); title('signal x(t) in time domain'); xlabel('time (seconds)'); ylabel('x(t)'); x = fft(signal); %dft of signal subplot(3,1,2); plot(t, x); title('power spectrum of discrete fourier transform of x(t)'); xlabel('time (seconds)'); ylabel('power'); f = linspace(0, 1000, length(x)); %? subplot(3,1,3); plot(f, abs(x)); %only want positive values title('spectral frequency'); xlabel('frequency (hz)'); ylabel('power'); end
at stage, i'm assuming right for:
"generate signal frequencies 85,150,330hz using sampling frequency of 1000hz - plot 1seconds worth of signal , discrete fourier transform."
the next step "find frequency response of lti scheme filters out higher , lower frequencies using fourier transform". i'm stuck trying create lti scheme that! have left 150hz signal, , i'm guessing perform filtering on fft, perhaps using conv.
my course of study not programming course of study - not assessed on our programming skills , have minimal matlab experience - have been left our own devices struggle through, help appreciated! sifting through tonnes of different examples , searching matlab functions using 'help' etc, since each 1 different , not have break downwards of variables used, explaining why parameters/values chosen etc. adding confusion.
among many (many) others have looked at: http://www.ee.columbia.edu/~ronw/adst-spring2010/lectures/matlab/lecture1.html http://gribblelab.org/scicomp/09_signals_and_sampling.html section 10.4 especially. matlab geeks examples , mathworks matlab function explanations. guess worst can happen nobody answers , go on burning eyeballs out until manage come :) in advance.
i found bandpass filter code mathworks example, needs applied fft signal, don't understand attenuation values ast or amount of ripple ap.
n = 0:159; x = cos(pi/8*n)+cos(pi/2*n)+sin(3*pi/4*n); d = fdesign.bandpass('fst1,fp1,fp2,fst2,ast1,ap,ast2',1/4,3/8,5/8,6/8,60,1,60); hd = design(d,'equiripple'); y = filter(hd,x); freq = 0:(2*pi)/length(x):pi; xdft = fft(x); ydft = fft(y); plot(freq,abs(xdft(1:length(x)/2+1))); hold on; plot(freq,abs(ydft(1:length(x)/2+1)),'r','linewidth',2); legend('original signal','bandpass signal');
here can utilize reference. think got gist of trying do. allow me know if have questions.
clear close fs = 1000; t = 0:(1/fs):1; n = length(t); % 85, 150, , 330 hz converted radian frequency w1 = 2*pi*85; w2 = 2*pi*150; w3 = 2*pi*330; % amplitudes a1 = 1; a2 = 1.5; a3 = .75; % build time-domain signals x1 = a1*cos(w1*t); x2 = a2*cos(w2*t); x3 = a3*cos(w3*t); % superposition of 85, 150, , 330 hz component signals x = x1 + x2 + x3; figure plot(t(1:100), x(1:100)); title('unfiltered time-domain signal, amplitude vs. time'); ylabel('amplitude'); xlabel('time (seconds)'); % compute discrete fourier transform of time-domain signal x = fft(x); xmag = 20*log10(abs(x)); % magnitude spectrum xphase = 180*unwrap(angle(x))./pi; % phase spectrum (degrees) w = 2*pi*(0:n-1)./n; % normalized radian frequency f = w./(2*pi)*fs; % radian frequency hz k = 1:n; % bin indices % plot magnitude spectrum figure plot(f, xmag) title('frequency-domain signal, magnitude vs. frequency'); xlabel('frequency (hz)'); ylabel('magnitude (db)'); % frequency vector of filter. attenuates undesired frequency components % , keeps desired components. h = 1e-3*ones(1, length(k)); h(97:223) = 1; h((end-223):(end-97)) = 1; % plot magnitude spectrum of signal , filter figure plot(k, xmag) hold on plot(k, 20*log10(h), 'r') title('frequency-domain signal (blue) , filter (red), magnitude vs. bin index'); xlabel('bin index'); ylabel('magnitude (db)'); % filtering in frequency domain multiplication y = x.*h; % plot magnitude spectrum of filtered signal figure plot(f, 20*log10(abs(y))) title('filtered frequency-domain signal, magnitude vs. frequency'); xlabel('frequency (hz)'); ylabel('magnitude (db)'); % utilize inverse discrete fourier transform obtain filtered time-domain % signal. signal complex due imperfect symmetry in % frequency-domain, imaginary components zero. y = ifft(y); % plot overlay of filtered signal , desired signal figure plot(t(1:100), x(1:100), 'r') hold on plot(t(1:100), x2(1:100), 'linewidth', 2) plot(t(1:100), real(y(1:100)), 'g') title('input signal (red), desired signal (blue), signal extracted via filtering (green)'); ylabel('amplitude'); xlabel('time (seconds)');
here end result...
matlab filtering signal-processing fft
Comments
Post a Comment