So, this is complicated. First, if you have an impulse response, in the form of a vector of samples, then you can turn it into a FIR filter, and you can find the frequency response of that with any of the available Scilab tools. I'm not sure if there's a more direct way, but if you had an impulse response h = [1, 1/2, 1/4, 1/8], then you can turn that into H = 1 + 0.5*%z^(-1) + 0.25*%z^(-2) + 0.125*%z^(-3) (note that %z is a built-in: %z = poly(0, 'z')). Then you can use techniques surrounding repfreq to get the frequency response.
Assign a sampling rate to it (i.e., by setting H.dt = 0.001, for a 1kHz sampling rate) and you can just use the Bode plot function: bode(H). Second, you can take your impulse response, pad it with zeros, and then take the FFT of it -- i.e. H = fft([h zeros(1, 252)]). You need to pad it because the FFT is only exact for a periodic function in time -- padding it gives you an approximation of an actual impulse response (and before someone jumps in and says you need to window it -- no, you don't, windowing is for sample vectors of continuous signals, not impulse responses). But if you don't know WHY the method is approximate, you're going to have trouble correctly massaging the data before it's presented to the FFT, and with interpreting the results. On Sat, 2018-09-15 at 22:15 +0200, Claus Futtrup wrote: > Hi Samuel and Scilabers > > My problem with freq and repfreq is that they require a "sys" input, > which implies I need to describe a response function of some sort. > For example (from the Scilab web-help): > > https://help.scilab.org/docs/6.0.1/en_US/freq.html (example code) > s=poly(0,'s'); > sys=(s+1)/(s^3-5*s+4) > rep=freq(sys("num"),sys("den"),[0,0.9,1.1,2,3,10,20]) > > https://help.scilab.org/docs/6.0.1/en_US/repfreq.html (syntax) > [ [frq,] repf]=repfreq(sys,fmin,fmax [,step]) > [ [frq,] repf]=repfreq(sys [,frq]) > [ frq,repf,splitf]=repfreq(sys,fmin,fmax [,step]) > [ frq,repf,splitf]=repfreq(sys [,frq]) > > ... So, the thing with the matlab freqz (as the example repeated > below shows) is just a basic FFT with sampling, etc: > > h = rand(1,64); // impulse response (Matlab source code) > fs = 1000; > Nfft = 128; > [H,F] = freqz(h,1,Nfft,fs); > semilogx(F,mag2db(abs(H))); grid on; > xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)'); > > It may very well be that I just don't understand the help page of > repfreq. For example it says about sys: "A siso or simo linear > dynamical system, in state space, transfer function or zpk > representations, in continuous or discrete time." - al right then, it > seems pretty capable, but so, what's "zpk" for example? ... my > apologies for finding the Scilab help to be cryptic and the examples > insufficient for me to solve my problem, hence I ask if someone can > take above matlab code and make it work in Scilab. > > Best regards, > Claus > > On 15.09.2018 00:32, Samuel Gougeon wrote: > > Le 14/09/2018 à 20:57, Claus Futtrup a écrit : > > > Dear Scilabers > > > I have calculated an impulse response and wish to do an FFT to > > > achieve the frequency response. I know what to expect. In the > > > matlab forum someone asked the same question and was recommended > > > to use freqz ... I wonder what would be the equivalent function > > > in Scilab? > > > https://www.mathworks.com/matlabcentral/answers/350350-how-to-plo > > > t-loudspeaker-frequency-response-from-its-impulse-response > > > For example, to replicate the code snippet (second answer in > > > above link), how to do this in Scilab? > > > h = rand(1,64); // impulse response (Matlab source code) > > > fs = 1000; > > > Nfft = 128; > > > [H,F] = freqz(h,1,Nfft,fs); > > > > Did you have a look around freq() or repfreq()? > > > > We have somewhat the equivalence invfreqz(H,F,m,n,W) <=> > > frfit(F*2*%pi, H, n, W) // Scilab > > > > So you may look for the reciprocal of Scilab's frfit() > > > > HTH > > Samuel > > > > > > > > _______________________________________________ > > users mailing list > > users@lists.scilab.org > > http://lists.scilab.org/mailman/listinfo/users > > Virus-free. www.avast.com > _______________________________________________ > users mailing list > users@lists.scilab.org > http://lists.scilab.org/mailman/listinfo/users -- Tim Wescott www.wescottdesign.com Control & Communications systems, circuit & software design. Phone: 503.631.7815 Cell: 503.349.8432 _______________________________________________ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users