1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I need help in Matlab

  1. Dec 18, 2007 #1
    Hi,

    I need some help in matlab.
    I am required to take the FFT (fast fourier transform) of the data obtained from my experiment, however, I have some problem understanding the code written by other people, just wondering if anyone could help me with this.

    I also need to understand how to fit the response into a rational function. I have pasted a code below, but I dont understand what it means. What does those 1:50001 means? and how to find out the length of wt and f_norm (they are suppose to be of the same length, as mention in matlab help). also, what does it means by wt?

    % Fitting the response to a rational function
    wt(1:50001)=0.001;
    wt(1:501)=1.0;
    ff = f(1:50001);
    f_norm = ff / f(50001)*pi;
    [num,den]=invfreqz(tf(1:50001), f_norm,3,4,wt)
    [h2,w2] = freqz(num,den,50001); % compute approximated magnitude response
    % plot measured and approximated magnitude response
    figure(3);
    plot(ff(1:501), abs(tf(1:501)), 'r', ff(1:501), abs(h2(1:501)), 'b');
    xlabel('Frequency (Hz)'), ylabel('Magnitude')
    title('Magnitude Response')

    Also, I am told to pass my data through a 5th order low pass butterworth filter, which is limited to 5kHz, before performing the FFt.
    However, after writing the code, i realised that the waveform is not correct in term of the magnitude and the data point.
    May I know how am I suppose to work out on the butterworth?

    I had written the butterworth code as shown below, please take a look and advise me.

    %5th order lowpass butterworth filter,limited frequency 5kHz
    n = 5; Wn = 5000/250000; %n=order, 0<Wn<1, Wn= cutoff frequency=5kHz/sampling frequency
    [Vsec,Vpri] = butter(n,Wn, 'low');
    % perform FFT where Y=fft(yy,length) / (length/2)
    Vpri_FT = fft(Vpri,10000)/5000;
    Vsec_FT = fft(Vsec,10000)/5000;
    f = 250000*(0:5000) / 10000; % f=sampling frequency*(0:(length/2))/length;
    tf = Vsec_FT ./ Vpri_FT; % transfer function=FFT(secondary) / FFT(primary)

    Thank you very much .:)
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?
Draft saved Draft deleted