Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to scale

Subject: How to scale

From: kk KKsingh

Date: 4 Mar, 2010 08:47:03

Message: 1 of 15

Just a simple question ! Suppose my signal is linspace(0,4,512) if i want to scale it between -0.5 to 0.5 then what is the best way

kk

Subject: How to scale

From: us

Date: 4 Mar, 2010 09:00:21

Message: 2 of 15

"kk KKsingh" <akikumar1983@gmail.com> wrote in message <hmns27$ht2$1@fred.mathworks.com>...
> Just a simple question ! Suppose my signal is linspace(0,4,512) if i want to scale it between -0.5 to 0.5 then what is the best way
>
> kk

a hint:

     help plus;
     help minus;
     help rdivide;
     help times;

us

Subject: How to scale

From: Walter Roberson

Date: 4 Mar, 2010 09:08:42

Message: 3 of 15

kk KKsingh wrote:
> Just a simple question ! Suppose my signal is linspace(0,4,512) if i
> want to scale it between -0.5 to 0.5 then what is the best way

General case:

scaledsignal = (signal./(max(signal)-min(signal)) .*
  (newupperbound - newlowerbound)) - newlowerbound;

In your particular example, this simplifies considerably.

Subject: How to scale

From: kk KKsingh

Date: 5 Mar, 2010 07:03:10

Message: 4 of 15

Its not working for -0.5 to +0.5

suppose t=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
 scaledsignal = (t./(max(t)-min(t)).*(0.5 - (-0.5))) - (-0.5)
then
scaled signal is
Columns 1 through 9

    0.5667 0.6333 0.7000 0.7667 0.8333 0.9000 0.9667 1.0333 1.1000

  Columns 10 through 16

    1.1667 1.2333 1.3000 1.3667 1.4333 1.5000 1.5667


kk
Walter Roberson <roberson@hushmail.com> wrote in message <hmntar$rsc$1@canopus.cc.umanitoba.ca>...
> kk KKsingh wrote:
> > Just a simple question ! Suppose my signal is linspace(0,4,512) if i
> > want to scale it between -0.5 to 0.5 then what is the best way
>
> General case:
>
> scaledsignal = (signal./(max(signal)-min(signal)) .*
> (newupperbound - newlowerbound)) - newlowerbound;
>
> In your particular example, this simplifies considerably.

Subject: How to scale

From: Tim

Date: 5 Mar, 2010 07:18:33

Message: 5 of 15

For t it should be ((t-1)/15)-0.5

This is simplified because the range you are going to is 1.

For the above it is x = x/4-0.5

It simplifies greatly because you are going to a range of 1, and because you start at 0.

Alternatively, just x = linspace(-0.5, 0.5, 512) would surely work.

"kk KKsingh" <akikumar1983@gmail.com> wrote in message <hmqabe$56s$1@fred.mathworks.com>...
> Its not working for -0.5 to +0.5
>
> suppose t=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
> scaledsignal = (t./(max(t)-min(t)).*(0.5 - (-0.5))) - (-0.5)
> then
> scaled signal is
> Columns 1 through 9
>
> 0.5667 0.6333 0.7000 0.7667 0.8333 0.9000 0.9667 1.0333 1.1000
>
> Columns 10 through 16
>
> 1.1667 1.2333 1.3000 1.3667 1.4333 1.5000 1.5667
>
>
> kk
> Walter Roberson <roberson@hushmail.com> wrote in message <hmntar$rsc$1@canopus.cc.umanitoba.ca>...
> > kk KKsingh wrote:
> > > Just a simple question ! Suppose my signal is linspace(0,4,512) if i
> > > want to scale it between -0.5 to 0.5 then what is the best way
> >
> > General case:
> >
> > scaledsignal = (signal./(max(signal)-min(signal)) .*
> > (newupperbound - newlowerbound)) - newlowerbound;
> >
> > In your particular example, this simplifies considerably.

Subject: How to scale

From: kk KKsingh

Date: 5 Mar, 2010 07:37:18

Message: 6 of 15

well didnt get this
suppose
N=256
Ts=.001
t = 0:Ts:Ts*(N-1); %sampling period
the scaling trick you told me ! does not scale it between -0.5 to 0.5



"Tim " <tim.bate@gmail.com> wrote in message <hmqb89$t84$1@fred.mathworks.com>...
> For t it should be ((t-1)/15)-0.5
>
> This is simplified because the range you are going to is 1.
>
> For the above it is x = x/4-0.5
>
> It simplifies greatly because you are going to a range of 1, and because you start at 0.
>
> Alternatively, just x = linspace(-0.5, 0.5, 512) would surely work.
>
> "kk KKsingh" <akikumar1983@gmail.com> wrote in message <hmqabe$56s$1@fred.mathworks.com>...
> > Its not working for -0.5 to +0.5
> >
> > suppose t=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
> > scaledsignal = (t./(max(t)-min(t)).*(0.5 - (-0.5))) - (-0.5)
> > then
> > scaled signal is
> > Columns 1 through 9
> >
> > 0.5667 0.6333 0.7000 0.7667 0.8333 0.9000 0.9667 1.0333 1.1000
> >
> > Columns 10 through 16
> >
> > 1.1667 1.2333 1.3000 1.3667 1.4333 1.5000 1.5667
> >
> >
> > kk
> > Walter Roberson <roberson@hushmail.com> wrote in message <hmntar$rsc$1@canopus.cc.umanitoba.ca>...
> > > kk KKsingh wrote:
> > > > Just a simple question ! Suppose my signal is linspace(0,4,512) if i
> > > > want to scale it between -0.5 to 0.5 then what is the best way
> > >
> > > General case:
> > >
> > > scaledsignal = (signal./(max(signal)-min(signal)) .*
> > > (newupperbound - newlowerbound)) - newlowerbound;
> > >
> > > In your particular example, this simplifies considerably.

Subject: How to scale

From: Walter Roberson

Date: 5 Mar, 2010 16:27:36

Message: 7 of 15

kk KKsingh wrote:
> Its not working for -0.5 to +0.5
>
> suppose t=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
> scaledsignal = (t./(max(t)-min(t)).*(0.5 - (-0.5))) - (-0.5)

Sorry, should have been + newlowerbound instead of - newlowerbound

Subject: How to scale

From: Walter Roberson

Date: 5 Mar, 2010 16:40:12

Message: 8 of 15

kk KKsingh wrote:
> well didnt get this suppose
> N=256
> Ts=.001 t = 0:Ts:Ts*(N-1); %sampling period
> the scaling trick you told me ! does not scale it between -0.5 to 0.5

That's because you changed the problem along the way. In the original
problem, you had 0 to 4. In this new problem, your endpoint is 0.255, so
the x/4-0.5 expression would have to be changed to x/Ts/(N-1)-0.5 .

Subject: How to scale

From: kk KKsingh

Date: 5 Mar, 2010 20:18:24

Message: 9 of 15

Its not working ......i am getting samples between -1.8 to 0.3 ..not between -0.5 to +0.5 and that lower bound formula also not works on this.....i need some thing general which can scale any signal between -0,5 and +0.5 and after i apply fft and apply some signal processing things i come back and i again rescale it to plot it......will it effect my signal in any case

Thanks

kk


Walter Roberson <roberson@hushmail.com> wrote in message <hmrc5d$nbm$1@canopus.cc.umanitoba.ca>...
> kk KKsingh wrote:
> > well didnt get this suppose
> > N=256
> > Ts=.001 t = 0:Ts:Ts*(N-1); %sampling period
> > the scaling trick you told me ! does not scale it between -0.5 to 0.5
>
> That's because you changed the problem along the way. In the original
> problem, you had 0 to 4. In this new problem, your endpoint is 0.255, so
> the x/4-0.5 expression would have to be changed to x/Ts/(N-1)-0.5 .

Subject: How to scale

From: Matt Fig

Date: 5 Mar, 2010 20:50:19

Message: 10 of 15

% Data
mn = 0; % Given minimum.
mx = 4; % Given maximum.
A = linspace(mn,mx,12) % Given A.

% Engine to scale between mns and mxs
mns = -.5; % The scaled minimum.
mxs = .5; % The scaled maximum.
As = (A - mn) * ((mxs-mns)/(mx-mn)) + mns % Scaled A


but notice, as Tim did, that As is just linspace(-.5,.5,12)

Subject: How to scale

From: kk KKsingh

Date: 12 Mar, 2010 22:02:05

Message: 11 of 15

And what is best way to scale it back avoiding any round off errors

Thanks


"Matt Fig" <spamanon@yahoo.com> wrote in message <hmrqqb$20b$1@fred.mathworks.com>...
> % Data
> mn = 0; % Given minimum.
> mx = 4; % Given maximum.
> A = linspace(mn,mx,12) % Given A.
>
> % Engine to scale between mns and mxs
> mns = -.5; % The scaled minimum.
> mxs = .5; % The scaled maximum.
> As = (A - mn) * ((mxs-mns)/(mx-mn)) + mns % Scaled A
>
>
> but notice, as Tim did, that As is just linspace(-.5,.5,12)

Subject: How to scale

From: Greg Heath

Date: 13 Mar, 2010 00:02:02

Message: 12 of 15

On Mar 12, 5:02 pm, "kk KKsingh" <akikumar1...@gmail.com> wrote:
> And what is best way to scale it back avoiding any round off errors
>
> "Matt Fig" <spama...@yahoo.com> wrote in message <hmrqqb$20...@fred.mathworks.com>...
> > % Data
> > mn = 0;  % Given minimum.
> > mx = 4;  % Given maximum.
> > A = linspace(mn,mx,12) % Given A.
>
> > % Engine to scale between mns and mxs
> > mns = -.5;  % The scaled minimum.
> > mxs = .5;  % The scaled maximum.
> > As = (A - mn) * ((mxs-mns)/(mx-mn)) + mns  % Scaled A
>
> > but notice, as Tim did, that As is just linspace(-.5,.5,12)- Hide quoted text -
>
> - Show quoted text -

If this is for FFT/IFFT,

dt = 1/Fs
T = N*dt % temporal period x(t+T) = x(t)
t = dt*(0:N-1)
t = 0:dt:T-dt % max(t) = T-dt
t = linspace(0,T-dt,N)

df = 1/T = Fs/N
Fs = N*df % spectral period X(f+Fs) = X(f)
f = df*(0:N-1);
f = 0:df:Fs-df; % max(f) = Fs-df
f = linspace(0,Fs-df,N);

Scaling ( General formula valid for time, frequency, temporal
signal and complex spectrum X = fft(x) )

For time,

(u-umin)/(umax-umin) = (t-tmin)/(tmax-tmin)
u = umin+(umax-umin)*(t-tmin)/(tmax-tmin)
u = -0.5 +(0.5 +0.5)*(t-0)/(4-0)
u = -0.5 + t/4

The formula is symmetric to an interchange of u and t.
Therefore

t = 0+(4-0)*(u+0.5)/(0.5+0.5)
t = 4*u + 2

Please explain what you plan do to with this information.
Are you scaling time or signal?

Hope this helps.

Greg

Subject: How to scale

From: kk KKsingh

Date: 13 Mar, 2010 06:27:02

Message: 13 of 15

Yes I am trying to scale a signal , basically i am scaling a time axis

kk
Greg Heath <heath@alumni.brown.edu> wrote in message <e8b95d64-04cd-418a-b751-d8adaf5329e5@k17g2000yqb.googlegroups.com>...
> On Mar 12, 5:02 pm, "kk KKsingh" <akikumar1...@gmail.com> wrote:
> > And what is best way to scale it back avoiding any round off errors
> >
> > "Matt Fig" <spama...@yahoo.com> wrote in message <hmrqqb$20...@fred.mathworks.com>...
> > > % Data
> > > mn = 0;  % Given minimum.
> > > mx = 4;  % Given maximum.
> > > A = linspace(mn,mx,12) % Given A.
> >
> > > % Engine to scale between mns and mxs
> > > mns = -.5;  % The scaled minimum.
> > > mxs = .5;  % The scaled maximum.
> > > As = (A - mn) * ((mxs-mns)/(mx-mn)) + mns  % Scaled A
> >
> > > but notice, as Tim did, that As is just linspace(-.5,.5,12)- Hide quoted text -
> >
> > - Show quoted text -
>
> If this is for FFT/IFFT,
>
> dt = 1/Fs
> T = N*dt % temporal period x(t+T) = x(t)
> t = dt*(0:N-1)
> t = 0:dt:T-dt % max(t) = T-dt
> t = linspace(0,T-dt,N)
>
> df = 1/T = Fs/N
> Fs = N*df % spectral period X(f+Fs) = X(f)
> f = df*(0:N-1);
> f = 0:df:Fs-df; % max(f) = Fs-df
> f = linspace(0,Fs-df,N);
>
> Scaling ( General formula valid for time, frequency, temporal
> signal and complex spectrum X = fft(x) )
>
> For time,
>
> (u-umin)/(umax-umin) = (t-tmin)/(tmax-tmin)
> u = umin+(umax-umin)*(t-tmin)/(tmax-tmin)
> u = -0.5 +(0.5 +0.5)*(t-0)/(4-0)
> u = -0.5 + t/4
>
> The formula is symmetric to an interchange of u and t.
> Therefore
>
> t = 0+(4-0)*(u+0.5)/(0.5+0.5)
> t = 4*u + 2
>
> Please explain what you plan do to with this information.
> Are you scaling time or signal?
>
> Hope this helps.
>
> Greg

Subject: How to scale

From: kk KKsingh

Date: 13 Mar, 2010 06:27:03

Message: 14 of 15

Yes I am trying to scale a signal , basically i am scaling a time axis

kk
Greg Heath <heath@alumni.brown.edu> wrote in message <e8b95d64-04cd-418a-b751-d8adaf5329e5@k17g2000yqb.googlegroups.com>...
> On Mar 12, 5:02 pm, "kk KKsingh" <akikumar1...@gmail.com> wrote:
> > And what is best way to scale it back avoiding any round off errors
> >
> > "Matt Fig" <spama...@yahoo.com> wrote in message <hmrqqb$20...@fred.mathworks.com>...
> > > % Data
> > > mn = 0;  % Given minimum.
> > > mx = 4;  % Given maximum.
> > > A = linspace(mn,mx,12) % Given A.
> >
> > > % Engine to scale between mns and mxs
> > > mns = -.5;  % The scaled minimum.
> > > mxs = .5;  % The scaled maximum.
> > > As = (A - mn) * ((mxs-mns)/(mx-mn)) + mns  % Scaled A
> >
> > > but notice, as Tim did, that As is just linspace(-.5,.5,12)- Hide quoted text -
> >
> > - Show quoted text -
>
> If this is for FFT/IFFT,
>
> dt = 1/Fs
> T = N*dt % temporal period x(t+T) = x(t)
> t = dt*(0:N-1)
> t = 0:dt:T-dt % max(t) = T-dt
> t = linspace(0,T-dt,N)
>
> df = 1/T = Fs/N
> Fs = N*df % spectral period X(f+Fs) = X(f)
> f = df*(0:N-1);
> f = 0:df:Fs-df; % max(f) = Fs-df
> f = linspace(0,Fs-df,N);
>
> Scaling ( General formula valid for time, frequency, temporal
> signal and complex spectrum X = fft(x) )
>
> For time,
>
> (u-umin)/(umax-umin) = (t-tmin)/(tmax-tmin)
> u = umin+(umax-umin)*(t-tmin)/(tmax-tmin)
> u = -0.5 +(0.5 +0.5)*(t-0)/(4-0)
> u = -0.5 + t/4
>
> The formula is symmetric to an interchange of u and t.
> Therefore
>
> t = 0+(4-0)*(u+0.5)/(0.5+0.5)
> t = 4*u + 2
>
> Please explain what you plan do to with this information.
> Are you scaling time or signal?
>
> Hope this helps.
>
> Greg

Subject: How to scale

From: Greg Heath

Date: 13 Mar, 2010 09:14:16

Message: 15 of 15

On Mar 13, 1:27 am, "kk KKsingh" <akikumar1...@gmail.com> wrote:
> Yes I am trying to scale a signal , basically i am scaling a time axis

Please do not top-post.


If you look at a plot of signal vs time, scaling the signal implies
changing the vertical scale. Scaling the time axis implies
changing the horizontal scale and either stretching or dilating
(but not scaling) the signal.


Hope this helps.

Greg

Tags for this Thread

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.

Contact us