| Electronics > Beginners |
| FFT and Signals |
| (1/4) > >> |
| Langer:
Hello, I have a question regarding DFT/Fast Fourier Transformation and signal processing. I want to write a program (matlab in this case) which can calculate the reaction (current) on an arbitrary waveform (voltage). My idea was to take the arbitrary waveform, do FFT, devide the FFT coefficients with the impedance at the desired frequency: I(f)=U(f)/Z(f), and then do an inverse FFT I(f)->I(t). This is working fine for harmonic waveforms. But when I try to do this with a square wave it fails at the edges. The attached picture shows U(t), I(t) calculated with matlab and the same thing with ltspice. The rising current at the edge seems to be wrong comparing the result with ltspice. Thank you in advance for every hint and solution. matlab code: ====================== clear all; clc; %define measurement Fs = 10000; % Sampling frequency T = 1/Fs; % Sampling period L =Fs; % Length of signal t = T*(0:L-1); % Time vector f = Fs*(1:L-1)/L; %define input waveform U(t) U = 4*(1+square(10*t))/2; %U0=2; %U = U0*exp(i*2*pi*300*t)+U0*exp(i*2*pi*100*t) %do the fft of U(t)->U(f) Ufft = fft(U); %plot the FFT of U(t) fig_4=figure(4); ax_4=axes; semilogy(abs(Ufft)); %plot U(t) fig_1=figure(1); ax_1=axes; plot(ax_1,t,real(U)) title('Input U(t)') fig_1.Position = [0,343,560,420]; %define a frequency vector with rising and falling frequencies looking like %this: /\ because of the mirror coefficients. freq=Fs*(0:L/2-1)/L; freq=horzcat(freq,fliplr(freq)); %define the impedance (here only C and R in series) L=0; Cap=100e-6; R=1; res=1/(2*pi*sqrt(L*Cap)) %calculate resonance frequency Xl=i*2*pi*L.*freq; Xc=-i./(2*pi*Cap*freq); Z = R+Xl+Xc; %calculate impedance of the system fig_2=figure(2); ax_2=axes; semilogy(freq,abs(Z)) title('Impedance Spectrum of Z(f)') fig_2.Position = [560,343,560,420]; Ifft=Ufft./Z; %devide the Fourier coefficients by the impedance Z(f) fig_3=figure(3); ax_3=axes; current=ifft(Ifft); plot(ax_3,t,real(current)) fig_3.Position = [1120,343,560,420]; title('Output I(t)') max(current) ====================== |
| T3sl4co1l:
Without reviewing the code -- looks like it's just missing a U(t) (unit step function). Fourier is for all time so you need to check your conditions as far as events (zeroing negative time?) and such go. Tim |
| radiolistener:
At a glance it's because you're scaling frequency magnitudes with variable coefficient Z. May be something wrong with Z? PS: interesting approach for current simulation :) But I'm not sure, is it correct to do it in such way? |
| Langer:
--- Quote from: T3sl4co1l on March 15, 2019, 07:55:07 pm ---Without reviewing the code -- looks like it's just missing a U(t) (unit step function). Fourier is for all time so you need to check your conditions as far as events (zeroing negative time?) and such go. --- End quote --- Can you specify this? When i look at FFT I see the amplitudes twice ( matlab shows them only in positiv frequency direction and not negative). So i should delete the doubled/negative frequencies? |
| Langer:
--- Quote from: radiolistener on March 15, 2019, 08:15:03 pm ---At a glance it's because you're scaling frequency magnitudes with variable coefficient Z. May be something wrong with Z? PS: interesting approach for current simulation :) But I'm not sure, is it correct to do it in such way? --- End quote --- I'm pretty sure that Z is fine. Deivding the freq amplitude U by Z sounds reasonable for me. But if I'm wrong please correct me.... And it works for harmonic signals, so it seems correct. |
| Navigation |
| Message Index |
| Next page |