Thread Subject: Frequency & phase shift

Subject: Frequency & phase shift

From: Prashant Sandhi

Date: 23 Feb, 2011 13:27:33

Message: 1 of 5

How to generate each frequency with different phases while simulation is continuously running using simulink blocks

Example:
Output with 1Hz and with phase shifts 0° for 1sec,10° for 1sec,20° for 1sec....360°
Output 1.1Hz and with phase shifts 0° for 1sec, 10° for 1sec,20° for 1sec....360°
  '
  '
  '
Output 50Hz and with phase shifts 0° for 1sec,10° for 1sec,20° for 1sec....360°

                         

                             Or algorithm is as follows:


F=1Hz; Phase=0°;

Step 1: Start Sine wave with 0.8V F=1Hz, Phase =0° Phase shift
Step 2: Counter=1, counter =Counter+1,
Step 3: If counter>100 or time=1sec then
           Phase=Phase+10°;
Step 4 : If Phase>360° Then
           F=(F+0.1) Hz
           Repeat Step 1 to Step 3
step 5: Repeat Steps 1 to 4 untill F=50Hz

I will be very glad if any one can help me with this.
I will be very happy if there is a model doing this in Simulink

Thanking you
Prashant

                                       

Subject: Frequency & phase shift

From: Prashant Sandhi

Date: 23 Feb, 2011 14:49:26

Message: 2 of 5

Till now I am able to achieve only 1Hz 0° signal only which does not make sense as my 1.1Hz signal goes only for a fraction of a sec.. don't understand how to extend it for complete 1sec..

more over 1Hz is not even exactly till 1sec...


"Prashant Sandhi" wrote in message <ik3205$jjb$1@fred.mathworks.com>...
> How to generate each frequency with different phases while simulation is continuously running using simulink blocks
>
> Example:
> Output with 1Hz and with phase shifts 0° for 1sec,10° for 1sec,20° for 1sec....360°
> Output 1.1Hz and with phase shifts 0° for 1sec, 10° for 1sec,20° for 1sec....360°
> '
> '
> '
> Output 50Hz and with phase shifts 0° for 1sec,10° for 1sec,20° for 1sec....360°
>
>
>
> Or algorithm is as follows:
>
>
> F=1Hz; Phase=0°;
>
> Step 1: Start Sine wave with 0.8V F=1Hz, Phase =0° Phase shift
> Step 2: Counter=1, counter =Counter+1,
> Step 3: If counter>100 or time=1sec then
> Phase=Phase+10°;
> Step 4 : If Phase>360° Then
> F=(F+0.1) Hz
> Repeat Step 1 to Step 3
> step 5: Repeat Steps 1 to 4 untill F=50Hz
>
> I will be very glad if any one can help me with this.
> I will be very happy if there is a model doing this in Simulink
>
> Thanking you
> Prashant
>
>

Subject: Frequency & phase shift

From: Punit

Date: 23 Feb, 2011 14:52:04

Message: 3 of 5

for ii=1:37
Phase=(ii-1)*10;
sim('Model')
%out{ii}= output from ToWorkspace block
end

Put this in M file, write 'Phase' in the field -Phase of sine wave generator in simulink model. This code is for 1 freq. write another for loop for all the frequencies.
-Punit

Subject: Frequency & phase shift

From: Prashant Sandhi

Date: 24 Feb, 2011 08:38:05

Message: 4 of 5

"Punit" wrote in message <ik36uk$6if$1@fred.mathworks.com>...
> for ii=1:37
> Phase=(ii-1)*10;
> sim('Model')
> %out{ii}= output from ToWorkspace block
> end
>
> Put this in M file, write 'Phase' in the field -Phase of sine wave generator in simulink model. This code is for 1 freq. write another for loop for all the frequencies.
> -Punit


Thank you Punit for your precious reply.
I have implemented different frequencies in the code but I am not sure if it is giving all the phases 0°-360° for each frequency


1Hz-0°,1Hz-10°,1Hz-20°.........1Hz-360°
1.1Hz-0°, 1.1Hz-10°, 1.1Hz-20°.........1.1Hz-360°
1.2Hz-0°, 1.2Hz-10°, 1.2Hz-20°.........1.1Hz-360°
'
'
5KHz-0°, 5KHz-10°, 5KHz-20°.........5KHz-360°
'
'
10KHz-0°, 10KHz-10°, 10KHz-20°.........10KHz-360°
My simulation does not stop, How can I make the code to exit when 10KHz-360° is acheived?


This is what I did to the code:
for ii=1:37
    for f=1:0.1:10e3
Phase=(ii-1)*10;
sim('Complete_V7.mdl')
%out{ii}= output from ToWorkspace block
    end
end

Subject: Frequency & phase shift

From: Prashant Sandhi

Date: 24 Feb, 2011 10:31:22

Message: 5 of 5

"Prashant Sandhi" wrote in message <ik55dd$oh6$1@fred.mathworks.com>...
> "Punit" wrote in message <ik36uk$6if$1@fred.mathworks.com>...
> > for ii=1:37
> > Phase=(ii-1)*10;
> > sim('Model')
> > %out{ii}= output from ToWorkspace block
> > end
> >
> > Put this in M file, write 'Phase' in the field -Phase of sine wave generator in simulink model. This code is for 1 freq. write another for loop for all the frequencies.
> > -Punit
>
>
> Thank you Punit for your precious reply.
> I have implemented different frequencies in the code but I am not sure if it is giving all the phases 0°-360° for each frequency
>
>
> 1Hz-0°,1Hz-10°,1Hz-20°.........1Hz-360°
> 1.1Hz-0°, 1.1Hz-10°, 1.1Hz-20°.........1.1Hz-360°
> 1.2Hz-0°, 1.2Hz-10°, 1.2Hz-20°.........1.1Hz-360°
> '
> '
> 5KHz-0°, 5KHz-10°, 5KHz-20°.........5KHz-360°
> '
> '
> 10KHz-0°, 10KHz-10°, 10KHz-20°.........10KHz-360°
> My simulation does not stop, How can I make the code to exit when 10KHz-360° is acheived?
>
>
> This is what I did to the code:
> for ii=1:37
> for f=1:0.1:10e3
> Phase=(ii-1)*10;
> sim('Complete_V7.mdl')
> %out{ii}= output from ToWorkspace block
> end
> end


Dear Punit
This code is perfectly working in FreqnPhase.m file:

for f=1:10:20
    for ii=1:2
Phase=(ii-1)*10;
sim('Complete_V7.mdl')
%out{ii}= output from ToWorkspace block
    end
end

Explanation: f=1:10:20 means 3 frequencies (1Hz, 11Hz, 21Hz)
                 ii=1:2,Phase=(ii-1)*10; means two phases only 0° and 10°
 This means I am getting 2*3 outputs=6 outputs.

More over I also get the outputs like this:
1st output: with 1Hz 0° Phase shift
2nd output: with 1Hz 10° Phase shift
3rd output: with 11Hz 0° Phase shift
4th output: with 11Hz 10° Phase shift
5th output: with 21Hz 0° Phase shift
6th output: with 21Hz 10° Phase shift
It works perfectly the way I was looking for.

I have another question.
In simulink model I have output Min value and Max Value for each above output.

How can I plot Frequency Vs Min value and Max Value
Example plot: 1Hz, min=2, Max = 8 then continue plotting for all frequencies...

Once again Thank you very much for your previous advise. It was very useful.


Prashant



             

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com