Sunday, January 29, 2012

Linear circuit investigation using FFT

The Fourier analysis is very powerful and useful instrument of investigation that is used widely in many scientific applications. It named after French mathematician Joseph Fourier who proved that arbitrary signal can be represented by sum of harmonic signals. Each harmonic signal (sinus or cosines) has own frequency, phase and amplitude. Нarmonic signal keeps its shape while passing through the linear circuit and change only amplitude and phase. This ability makes the Fourier analysis to become a power method of investigation. To perform Fourier analysis on computers in digital form the Discrete Fourier Transform (DFT) was developed. The fast optimized version of DFT is called Fast Fourier Transform (FFT).

We will use the FFT to investigate signal propagation through some circuit showed on Fig.1.
Fig. 1
We can extract some information about this circuit just sending known signal of required form on input and recording the result signal on the output of the circuit.
To program the model of this circuit we have to build the transfer function of the circuit:
How can we get output signal? The idea is to represent the transfer function in frequency domain ( get frequency response of circuit), find the spectrum of input signal then multiply them by each other to get the spectrum of output signal and make the inverse transform to get the output signal in time domain.

Input signal
The input signal is just rectangle impulse:
Fs = 200; % Sample frequency (Hz)
dT = 1/Fs; % Sample time (seconds)
N = 2^8; % number of samples
t = 1:N; % array of samples
t = dT*t; % array of discrete time (sec)
u = (1:N)*0; u(60:80) = 1; %create descrete signal

Plot our signal in time domain:
figure;
s = stem(t(1:128),u(1:128));
set(get(s,'BaseLine'),'LineStyle',':');
set(s,'MarkerFaceColor','red');
grid on;
xlabel('t, seconds');
ylabel('u, Volts');
title('Input disctere signal');



Make the forward FFT of input signal to find it spectrum:
U = fft(u); %FFT
L = length(u); %length u
U1 = [ U((L/2+1):end) U(1:L/2)];
f = ((-N/2:(N-1)/2)*Fs)/N;
Uabs = abs(U1);
UdB = 20*log10( Uabs/max(Uabs));

Plot the spectrum of input signal:
figure;
hold on;
plot(f,UdB,'--');
plot(f,UdB,'*r');
grid on;
title('FFT of input disctere signal');
xlabel('f, Hz');
ylabel('|U|, dB');

 Transfer function
Make the transfer function:
R1 = 2000; %Ohm
R2 = 1000; %Ohm
C = 5*10^(-6); %F
tau1 = R2*C;
tau2 = (R1+R2)*C;
j = sqrt(-1);
K = ( 1 + (tau1.*j.*2.*pi.*f))./ ( 1 + (tau2.*j.*2.*pi.*f));
Kabs = abs(K);
KdB = 20*log10(Kabs/max(Kabs));

Plot the frequency response of circuit:
figure;
hold on;
plot(f,KdB,'--');
plot(f,KdB,'*r');
grid on;
title('Transfer function');
xlabel('f, Hz');
ylabel('|K(j2pif)|, dB');


Get the output: multiply the spectrum of input signal and circuit frequency response
Y1 = U1.*K;
Yabs = abs(Y1);
YdB = 20*log10( Yabs/max(Yabs));
figure;hold on;
plot(f,YdB,'--');
plot(f,YdB,'*r');
grid on;title('Spectrum of signal after filtration');
xlabel('f, Hz');ylabel('|Y|, dB');

Transfer the output into the time domain:
Y = [ Y1((L/2+1):end) Y1(1:L/2)];
y = ifft(Y,N);
y = real(y);
figure;hold on;
s = stem(t(1:128),y(1:128));
set(get(s,'BaseLine'),'LineStyle',':');
set(s,'MarkerFaceColor','red');
grid on;xlabel('t, seconds');ylabel('y, Volts');
title('Output disctere signal');


We get the output signal in time domain. Even if we didn't know what circuit we have, the output response show as that circuit if suppresses the high frequencies and passes low frequencies (and the frequency response of circuit shows that). So our circuit is the low-pass filter. Using this method we can investigate the different circuits impact on various signals and get the desired characteristics of circuits and signals passed through. 

No comments:

Post a Comment