[Scilab-users] Frequency response

Claus Futtrup cfuttrup at gmail.com
Tue Sep 18 17:23:07 CEST 2018


Hi Tan, et al.

Thank you for the complete response to my initial request.

This is very helpful for me to understand ... but if this is indeed the 
equivalent of the matlab script, I wonder about if the help I found in 
the matlab forum is helpful or not. The reason I'm still wondering is 
because the matlab forum question is exactly like mine - I wish to find 
the fft of a loudspeaker impulse response and I expect a loudspeaker 
frequency response with roll-off at low frequencies, but now that I see 
the result of the below script with random data for the impulse response 
... I see that the generated output is a "filter" - which is not at all 
what I expected and I think the similar response in the matlab forum was 
also not helpful (I do not have access to matlab / cannot test and or 
verify). Sorry for this. The entire concept may not be useful in my 
case, but Scilab supports advanced FFT routines (FFTW) and it should be 
possible to do what I need.

Rafael is right that the previously attached stepresponse script 
explains in detail my situation. If I take the "H" vector (the impulse 
response) in the script and apply a basic fft(H), it looks like this:

Added script code:

Resp  =  fft(H);
[db,phi]  =  dbphi(Resp);  // convert frequency response into magnitude and phase
f_max  =  1/tau_step;  // Hz
f  =  f_max  *  (0:length(H)-1)/length(H);  //associated frequency vector
scf();
plot(f'(2:nt/2),db(2:nt/2));  // Transpose X to prevent WARNING
re  =  gca();
re.log_flags  =  "lnn";
xgrid(color("grey70"));
xlabel("Frequency (Hz)");
ylabel("Magnitude (dB)");

RESULT :

This is not exactly what I had in mind, the "shape" of the curve isn't 
right, but then again - there are some inner-workings I don't know about 
(like, is the dbphi function doing what I think it does?). Maybe I 
cannot use dbphi(), or maybe I just have an error somewhere in the 
calculation of the impulse response. I expected a level of approx. 86 dB 
with a roll-off towards the lower frequencies. Here's the expected 
response (from simulation based on the input response function, i.e. not 
based on impulse response and not by fft):



Best regards,
Claus

On 18.09.2018 04:25, Tan Chin Luh wrote:
> On 18/9/2018 5:15 AM, Rafael Guerra wrote:
>> Chin Luh:  good to know but how does that solve Claus Futtrup specific problem?
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> http://lists.scilab.org/mailman/listinfo/users
>>
> just notice that the answer similar as the one Tim provided, just a 
> bit confused on Claus' comment on the "random" data:
>
> On 17/9/2018 1:13 AM, Claus Futtrup wrote:
>> What I like about the Matlab example is that random data is generated 
>> to represent the impulse response, so this represents "any data" ... 
>> I need that. If Scilab cannot do it, it's OK. 
>
> Do you refer this "random" data to the example provided?
>
> h = rand(1,64); % impulse response <-- This?
> fs  =  1000;
> Nfft  =  128;
> [H,F]  =  freqz(h,1,Nfft,fs);
> plot(F,H);  grid  on;
>
> If so, the equivalent scilab code would be as below:
>
> h  =  rand(1,64);
> fs  =  1000;
> b  =  poly(h($:-1:1),"z","coeff");
> a  =  %z^(length(h)-1);
> Gz  =  syslin('d',b,a);
> Gz.dt  =  1/fs;
> [F,H]=repfreq(Gz,0,500,0.01);
> plot(F,H); Do note that I replace the last part of semilogx plot and 
> replace with plot for more simple codes.
> -- 
> Tan Chin Luh
> Trity Technologies Sdn Bhd
> Tel : +603 80637737
> HP : +6013 3691728
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20180918/70517f6d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ikjflngodaplolmh.png
Type: image/png
Size: 10991 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20180918/70517f6d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hlhbjdcpfapmmdag.png
Type: image/png
Size: 13414 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20180918/70517f6d/attachment-0001.png>


More information about the users mailing list