Thread Subject: Convert frequency response data to simulink block

Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 4 Sep, 2008 02:37:02

Message: 1 of 17

I am doing research in my college.

Now, I am trying to build a noise cancelling system for
headphone in simulink. There is a block which should use a
microphone's transfer function. I test the microphone's
transfer function and get the frequency response data from
150hz to 5k hz with 130 points. And now, I don't know how to
convert the data to simulink's block, so it can work as a
microphone's behavior. I tried system identification
toolbox. But it doesn't work by now. I am just confused how
to do it.

Subject: Convert frequency response data to simulink block

From: Rune Allnor

Date: 4 Sep, 2008 10:08:26

Message: 2 of 17

On 4 Sep, 04:37, "Ben Wu" <wushizh...@gmail.com> wrote:
> I am doing research in my college.
>
> Now, I am trying to build a noise cancelling system for
> headphone in simulink. There is a block which should use a
> microphone's transfer function.

You might get help if you state specifically what block
you try to use.

Rune

Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 4 Sep, 2008 14:10:20

Message: 3 of 17

Rune Allnor <allnor@tele.ntnu.no> wrote in message
<aa9087fa-066e-458f-b5b8-041c2ec73afd@z6g2000pre.googlegroups.com>...
> On 4 Sep, 04:37, "Ben Wu" <wushizh...@gmail.com> wrote:
> > I am doing research in my college.
> >
> > Now, I am trying to build a noise cancelling system for
> > headphone in simulink. There is a block which should use a
> > microphone's transfer function.
>
> You might get help if you state specifically what block
> you try to use.
>
> Rune

There is a block in my system that represent the microphone.
I want it to behavior like the microphone I use. Thus, I
test the microphone'r frequency response by a function
generator and a scope. Now, I want to convert the data I got
to the block.

Subject: Convert frequency response data to simulink block

From: David

Date: 4 Sep, 2008 14:43:02

Message: 4 of 17

"Ben Wu" <wushizhang@gmail.com> wrote in message
<g9oq8c$occ$1@fred.mathworks.com>...
> Rune Allnor <allnor@tele.ntnu.no> wrote in message
> <aa9087fa-066e-458f-b5b8-
041c2ec73afd@z6g2000pre.googlegroups.com>...
> > On 4 Sep, 04:37, "Ben Wu" <wushizh...@gmail.com> wrote:
> > > I am doing research in my college.
> > >
> > > Now, I am trying to build a noise cancelling system
for
> > > headphone in simulink. There is a block which should
use a
> > > microphone's transfer function.
> >
> > You might get help if you state specifically what block
> > you try to use.
> >
> > Rune
>
> There is a block in my system that represent the
microphone.
> I want it to behavior like the microphone I use. Thus, I
> test the microphone'r frequency response by a function
> generator and a scope. Now, I want to convert the data I
got
> to the block.

maybe firls could be of help

Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 4 Sep, 2008 16:03:02

Message: 5 of 17

> maybe firls could be of help

thanks.
you mean the function "firls"?

Subject: Convert frequency response data to simulink block

From: Rajiv Singh

Date: 4 Sep, 2008 16:14:59

Message: 6 of 17

Hi Ben,
Could you outline your steps with using System Identification Toolbox? It
should be possible to represent your data using IDFRD object and then create
a transfer function from it using functions such as PEM and OE.

Rajiv

"Ben Wu" <wushizhang@gmail.com> wrote in message
news:g9p0rm$o6j$1@fred.mathworks.com...
>> maybe firls could be of help
>
> thanks.
> you mean the function "firls"?


Subject: Convert frequency response data to simulink block

From: David

Date: 4 Sep, 2008 16:22:01

Message: 7 of 17

"Ben Wu" <wushizhang@gmail.com> wrote in message
<g9p0rm$o6j$1@fred.mathworks.com>...
> > maybe firls could be of help
>
> thanks.
> you mean the function "firls"?

yes, with that i think you could take your measured
response curve and get the coefficients for an fir filter
to pass the sound through to get the response of your mic.

Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 4 Sep, 2008 18:58:02

Message: 8 of 17

"Rajiv Singh" <rajiv_singh@msn.com> wrote in message
<g9p1i4$3ge$1@fred.mathworks.com>...
> Hi Ben,
> Could you outline your steps with using System
Identification Toolbox? It
> should be possible to represent your data using IDFRD
object and then create
> a transfer function from it using functions such as PEM
and OE.
>
> Rajiv
>
> "Ben Wu" <wushizhang@gmail.com> wrote in message
> news:g9p0rm$o6j$1@fred.mathworks.com...
> >> maybe firls could be of help
> >
> > thanks.
> > you mean the function "firls"?
>
>


Sure. Thanks for reply.
I have three vectors: magnitude, phase, frequency. I import
these data as freq.frequency(amp/phase). Then I estimate it
by using spectral model. Finally, I get IDFRD model and do
not what to do next.


Subject: Convert frequency response data to simulink block

From: Rajiv Singh

Date: 5 Sep, 2008 14:55:28

Message: 9 of 17

Suppose you have mag/phase/frequency data. First create an IDFRD object to
represent this data:

H = mag.*exp(j*phase);
G = idfrd(H,w); %w is fequency in rad/s
(make sure the phase is in rad.)

Then you may estimate paramteric models using G as data. If you want
continuous-time models, you can set the sample time to zero in G (G.Ts=0),
or use "process models" (see M4 below).

M1 = oe(G, [2 2 1]); %get output error model: y = B/F*u+e, with 2 poles and
one zero
M2 = pem(G,4); % 4th order state-space model
M3 = arx(G, [2 2 1]); %arx model: Ay = Bu+e
M4 = pem(G,'p2dz'); % get a continuous-time process model

Note:
1. Commands such as ARX, OE, PEM ordinarily create discrete-time models. If
you want continuous-time models, you can either set G.Ts to 0 or use D2C on
the discrete model after estimation.

2. The model M4 above is "process model" which is basically a
continuous-time transfer function. It has the advantage that it allows delay
estimation. Its limitation is that is only allows low-order transfer
function estimation (3 or fewer poles, one zero, input delay and
integrator). G.Ts must be non-zero for estimating this model. Look up help
for IDPROC for more information.

3. All of these models can be imported into Simulink using the IDMODEL block
that is part of System Identification Toolbox block library.

4. You can convert these models into LTI objects, such as a trasnfer
function by using "tf" command, as in: mod = tf(M1('m')); The LTI model can
be imported into SImulink using the LTI block of Control System Toolbox.

5. You can also extract numerator and denominator coefficients for any of
these models using "tfdata", as in: [num, den] = tfdata(M1, 'v'); The "num"
and "den" values can be used in core Simulink's "Transfer fcn" and "Discrete
transfer fcn" blocks. There are also continuous and discrete state space
blocks for representing a LTI system using state-space matrices. Use
"ssdata" function to extract state-space matrices from any estimated model.

So you have several options to estimate models and also several options for
importing results into Simulink.

Rajiv

"Ben Wu" <wushizhang@gmail.com> wrote in message
news:g9pb3q$pmi$1@fred.mathworks.com...
> "Rajiv Singh" <rajiv_singh@msn.com> wrote in message
> <g9p1i4$3ge$1@fred.mathworks.com>...
>> Hi Ben,
>> Could you outline your steps with using System
> Identification Toolbox? It
>> should be possible to represent your data using IDFRD
> object and then create
>> a transfer function from it using functions such as PEM
> and OE.
>>
>> Rajiv
>>
>> "Ben Wu" <wushizhang@gmail.com> wrote in message
>> news:g9p0rm$o6j$1@fred.mathworks.com...
>> >> maybe firls could be of help
>> >
>> > thanks.
>> > you mean the function "firls"?
>>
>>
>
>
> Sure. Thanks for reply.
> I have three vectors: magnitude, phase, frequency. I import
> these data as freq.frequency(amp/phase). Then I estimate it
> by using spectral model. Finally, I get IDFRD model and do
> not what to do next.
>
>


Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 11 Sep, 2008 02:26:02

Message: 10 of 17

"Rajiv Singh" <rajiv_singh@msn.com> wrote in message <g9rh90$sh0$1@fred.mathworks.com>...
> Suppose you have mag/phase/frequency data. First create an IDFRD object to
> represent this data:
>
> H = mag.*exp(j*phase);
> G = idfrd(H,w); %w is fequency in rad/s
> (make sure the phase is in rad.)
>
> Then you may estimate paramteric models using G as data. If you want
> continuous-time models, you can set the sample time to zero in G (G.Ts=0),
> or use "process models" (see M4 below).
>
> M1 = oe(G, [2 2 1]); %get output error model: y = B/F*u+e, with 2 poles and
> one zero
> M2 = pem(G,4); % 4th order state-space model
> M3 = arx(G, [2 2 1]); %arx model: Ay = Bu+e
> M4 = pem(G,'p2dz'); % get a continuous-time process model
>
> Note:
> 1. Commands such as ARX, OE, PEM ordinarily create discrete-time models. If
> you want continuous-time models, you can either set G.Ts to 0 or use D2C on
> the discrete model after estimation.
>
> 2. The model M4 above is "process model" which is basically a
> continuous-time transfer function. It has the advantage that it allows delay
> estimation. Its limitation is that is only allows low-order transfer
> function estimation (3 or fewer poles, one zero, input delay and
> integrator). G.Ts must be non-zero for estimating this model. Look up help
> for IDPROC for more information.
>
> 3. All of these models can be imported into Simulink using the IDMODEL block
> that is part of System Identification Toolbox block library.
>
> 4. You can convert these models into LTI objects, such as a trasnfer
> function by using "tf" command, as in: mod = tf(M1('m')); The LTI model can
> be imported into SImulink using the LTI block of Control System Toolbox.
>
> 5. You can also extract numerator and denominator coefficients for any of
> these models using "tfdata", as in: [num, den] = tfdata(M1, 'v'); The "num"
> and "den" values can be used in core Simulink's "Transfer fcn" and "Discrete
> transfer fcn" blocks. There are also continuous and discrete state space
> blocks for representing a LTI system using state-space matrices. Use
> "ssdata" function to extract state-space matrices from any estimated model.
>
> So you have several options to estimate models and also several options for
> importing results into Simulink.
>
> Rajiv
>
> "Ben Wu" <wushizhang@gmail.com> wrote in message
> news:g9pb3q$pmi$1@fred.mathworks.com...
> > "Rajiv Singh" <rajiv_singh@msn.com> wrote in message
> > <g9p1i4$3ge$1@fred.mathworks.com>...
> >> Hi Ben,
> >> Could you outline your steps with using System
> > Identification Toolbox? It
> >> should be possible to represent your data using IDFRD
> > object and then create
> >> a transfer function from it using functions such as PEM
> > and OE.
> >>
> >> Rajiv
> >>
> >> "Ben Wu" <wushizhang@gmail.com> wrote in message
> >> news:g9p0rm$o6j$1@fred.mathworks.com...
> >> >> maybe firls could be of help
> >> >
> >> > thanks.
> >> > you mean the function "firls"?
> >>
> >>
> >
> >
> > Sure. Thanks for reply.
> > I have three vectors: magnitude, phase, frequency. I import
> > these data as freq.frequency(amp/phase). Then I estimate it
> > by using spectral model. Finally, I get IDFRD model and do
> > not what to do next.
> >
> >
>
>

Thanks so much.But the transfer function I got all have poles>0. So, they are unstable.For example, I got Continuous-time IDPOLY model:
y(t) = [B(s)/F(s)]u(t) + e(t)
B(s) = 355.2 s + 3.487e006
F(s) = s^2 - 7283 s + 5.451e008
I tried other orders and got poles>0.

Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 11 Sep, 2008 03:14:02

Message: 11 of 17

I find out there is a toolbox in matlab called Frequency Domain System Identification Toolbox(FDIDENT).

http://www.mathworks.com/products/connections/product_main.html?prod_id=309

http://matlab.gamax.hu/english/products/?article_hid=219

but it is not free.

Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 11 Sep, 2008 03:14:02

Message: 12 of 17

I find out there is a toolbox in matlab called Frequency Domain System Identification Toolbox(FDIDENT).

http://www.mathworks.com/products/connections/product_main.html?prod_id=309

http://matlab.gamax.hu/english/products/?article_hid=219

but it is not free.

Subject: Convert frequency response data to simulink block

From: David

Date: 11 Sep, 2008 10:04:02

Message: 13 of 17

"Ben Wu" <wushizhang@gmail.com> wrote in message <gaa2dq$fm6$1@fred.mathworks.com>...
> I find out there is a toolbox in matlab called Frequency Domain System Identification Toolbox(FDIDENT).
>
> http://www.mathworks.com/products/connections/product_main.html?prod_id=309
>
> http://matlab.gamax.hu/english/products/?article_hid=219
>
> but it is not free.

unfortunately many of the good things in life aren't free.

Subject: Convert frequency response data to simulink block

From: Rajiv Singh

Date: 11 Sep, 2008 13:13:47

Message: 14 of 17

I don't know about the nature of your data (you may want to verify the units
of magnitude and phase data), but you may try using Focus='stability' during
estimation which forces the returned model to be stable:

model = oe(G,[2 2 1],'foc','stab');

The process models (idproc) are always stable.

Rajiv

"Ben Wu" <wushizhang@gmail.com> wrote in message
news:ga9vjq$fko$1@fred.mathworks.com...
> "Rajiv Singh" <rajiv_singh@msn.com> wrote in message
> <g9rh90$sh0$1@fred.mathworks.com>...
>> Suppose you have mag/phase/frequency data. First create an IDFRD object
>> to
>> represent this data:
>>
>> H = mag.*exp(j*phase);
>> G = idfrd(H,w); %w is fequency in rad/s
>> (make sure the phase is in rad.)
>>
>> Then you may estimate paramteric models using G as data. If you want
>> continuous-time models, you can set the sample time to zero in G
>> (G.Ts=0),
>> or use "process models" (see M4 below).
>>
>> M1 = oe(G, [2 2 1]); %get output error model: y = B/F*u+e, with 2 poles
>> and
>> one zero
>> M2 = pem(G,4); % 4th order state-space model
>> M3 = arx(G, [2 2 1]); %arx model: Ay = Bu+e
>> M4 = pem(G,'p2dz'); % get a continuous-time process model
>>
>> Note:
>> 1. Commands such as ARX, OE, PEM ordinarily create discrete-time models.
>> If
>> you want continuous-time models, you can either set G.Ts to 0 or use D2C
>> on
>> the discrete model after estimation.
>>
>> 2. The model M4 above is "process model" which is basically a
>> continuous-time transfer function. It has the advantage that it allows
>> delay
>> estimation. Its limitation is that is only allows low-order transfer
>> function estimation (3 or fewer poles, one zero, input delay and
>> integrator). G.Ts must be non-zero for estimating this model. Look up
>> help
>> for IDPROC for more information.
>>
>> 3. All of these models can be imported into Simulink using the IDMODEL
>> block
>> that is part of System Identification Toolbox block library.
>>
>> 4. You can convert these models into LTI objects, such as a trasnfer
>> function by using "tf" command, as in: mod = tf(M1('m')); The LTI model
>> can
>> be imported into SImulink using the LTI block of Control System Toolbox.
>>
>> 5. You can also extract numerator and denominator coefficients for any of
>> these models using "tfdata", as in: [num, den] = tfdata(M1, 'v'); The
>> "num"
>> and "den" values can be used in core Simulink's "Transfer fcn" and
>> "Discrete
>> transfer fcn" blocks. There are also continuous and discrete state space
>> blocks for representing a LTI system using state-space matrices. Use
>> "ssdata" function to extract state-space matrices from any estimated
>> model.
>>
>> So you have several options to estimate models and also several options
>> for
>> importing results into Simulink.
>>
>> Rajiv
>>
>> "Ben Wu" <wushizhang@gmail.com> wrote in message
>> news:g9pb3q$pmi$1@fred.mathworks.com...
>> > "Rajiv Singh" <rajiv_singh@msn.com> wrote in message
>> > <g9p1i4$3ge$1@fred.mathworks.com>...
>> >> Hi Ben,
>> >> Could you outline your steps with using System
>> > Identification Toolbox? It
>> >> should be possible to represent your data using IDFRD
>> > object and then create
>> >> a transfer function from it using functions such as PEM
>> > and OE.
>> >>
>> >> Rajiv
>> >>
>> >> "Ben Wu" <wushizhang@gmail.com> wrote in message
>> >> news:g9p0rm$o6j$1@fred.mathworks.com...
>> >> >> maybe firls could be of help
>> >> >
>> >> > thanks.
>> >> > you mean the function "firls"?
>> >>
>> >>
>> >
>> >
>> > Sure. Thanks for reply.
>> > I have three vectors: magnitude, phase, frequency. I import
>> > these data as freq.frequency(amp/phase). Then I estimate it
>> > by using spectral model. Finally, I get IDFRD model and do
>> > not what to do next.
>> >
>> >
>>
>>
>
> Thanks so much.But the transfer function I got all have poles>0. So, they
> are unstable.For example, I got Continuous-time IDPOLY model:
> y(t) = [B(s)/F(s)]u(t) + e(t)
> B(s) = 355.2 s + 3.487e006
> F(s) = s^2 - 7283 s + 5.451e008
> I tried other orders and got poles>0.


Subject: Convert frequency response data to simulink block

From: Ben Wu

Date: 11 Sep, 2008 14:51:02

Message: 15 of 17

"Rajiv Singh" <rajiv_singh@msn.com> wrote in message <gab5ib$pt2$1@fred.mathworks.com>...

Yes, that makes transfer function stable. But the thing is that the phase response is not correct now.

Subject: Convert frequency response data to simulink block

From: Gary Pratt

Date: 17 Nov, 2008 22:45:04

Message: 16 of 17


> H = mag.*exp(j*phase);
> G = idfrd(H,w); %w is fequency in rad/s
> (make sure the phase is in rad.)
>
> Then you may estimate paramteric models using G as data. If you want
> continuous-time models, you can set the sample time to zero in G (G.Ts=0),
> or use "process models" (see M4 below).
>
> M1 = oe(G, [2 2 1]); %get output error model: y = B/F*u+e, with 2 poles and
> one zero
> M2 = pem(G,4); % 4th order state-space model
> M3 = arx(G, [2 2 1]); %arx model: Ay = Bu+e
> M4 = pem(G,'p2dz'); % get a continuous-time process model

My version of Matlab doesn't seem to accept IDFRD objects for oe, pem, or arx. I'm using version MatLab 6.5 and the system identification toolbox version 5.0. pem() complains that OutputData must be a 2D matrix. arx() complains that NN must be the same number of columns as inputs. Am I missing a step, or do I need to user a newer version matlab?

Subject: Convert frequency response data to simulink block

From: Rajiv Singh

Date: 19 Nov, 2008 17:18:06

Message: 17 of 17

Version 6.0 of System Identification Toolbox introduced frequency domain
identification. So it will not work with version 5.0

Rajiv


"Gary Pratt" <gp_removethis_@wi.rr.com> wrote in message
news:gfss5g$ja$1@fred.mathworks.com...
>
>> H = mag.*exp(j*phase);
>> G = idfrd(H,w); %w is fequency in rad/s
>> (make sure the phase is in rad.)
>>
>> Then you may estimate paramteric models using G as data. If you want
>> continuous-time models, you can set the sample time to zero in G
>> (G.Ts=0),
>> or use "process models" (see M4 below).
>>
>> M1 = oe(G, [2 2 1]); %get output error model: y = B/F*u+e, with 2 poles
>> and
>> one zero
>> M2 = pem(G,4); % 4th order state-space model
>> M3 = arx(G, [2 2 1]); %arx model: Ay = Bu+e
>> M4 = pem(G,'p2dz'); % get a continuous-time process model
>
> My version of Matlab doesn't seem to accept IDFRD objects for oe, pem, or
> arx. I'm using version MatLab 6.5 and the system identification toolbox
> version 5.0. pem() complains that OutputData must be a 2D matrix. arx()
> complains that NN must be the same number of columns as inputs. Am I
> missing a step, or do I need to user a newer version matlab?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
simulink Ben Wu 3 Sep, 2008 22:40:20
frequency response Ben Wu 3 Sep, 2008 22:40:20
data Ben Wu 3 Sep, 2008 22:40:20
convert Ben Wu 3 Sep, 2008 22:40:20
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com