Wrong output with MATLAB S Function (2024)

조회 수: 26 (최근 30일)

이전 댓글 표시

AYYAPPA RUDRASIMHA 2024년 8월 28일 13:06

  • 링크

    이 질문에 대한 바로 가기 링크

    https://kr.mathworks.com/matlabcentral/answers/2148404-wrong-output-with-matlab-s-function

  • 링크

    이 질문에 대한 바로 가기 링크

    https://kr.mathworks.com/matlabcentral/answers/2148404-wrong-output-with-matlab-s-function

답변: Divyajyoti Nayak 2024년 8월 30일 7:27

  • SOGI_S_Function.zip

When I implement simple SOGI block to generate quadrature signal for given sinusoidla input, output magnitude comming exactly half. SOGI will give two outputs one is alpha and another is beta component. Beta component magnitude and phase is correct but alpha component magnitude is comming exactly half. Same discrete equations when I implemented in matlab function or tf block in simulink its giving correct. Same equations and everything same but when I implemented in s function its giving wrong.

Correct output with MATLAB Function: (Valpha and vin both having same phase and maginitude)

Wrong output with MATLAB S Function (2)

Wrong output with S Function (C code): (Valpha and vin both having same phase and maginitude)

Wrong output with MATLAB S Function (3)

I attached the simulation files of s function, This error is only because of s function related issues. Please check and let me know.

Thanks in advance.

댓글 수: 0

이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

이 질문에 답변하려면 로그인하십시오.

답변 (1개)

Divyajyoti Nayak 2024년 8월 30일 7:27

  • 링크

    이 답변에 대한 바로 가기 링크

    https://kr.mathworks.com/matlabcentral/answers/2148404-wrong-output-with-matlab-s-function#answer_1507654

  • 링크

    이 답변에 대한 바로 가기 링크

    https://kr.mathworks.com/matlabcentral/answers/2148404-wrong-output-with-matlab-s-function#answer_1507654

MATLAB Online에서 열기

Hi @AYYAPPA RUDRASIMHA,

The simulation results using the MATLAB function block and S-function block are different because the C code you have written for the S-function block is not equivalent to the code in MATLAB function block due to a small difference.

In the MATLAB function block, the ‘err’ variable is given the value of the input variable ‘ref’ after the assignment of variables ‘err_n2’and ‘err_n1’.

err_n2 = err_n1 ; %Initially Zero

err_n1 = err ; %Initially Zero because err = 0

err = ref; %The input ref is assigned to err

While in the S-function block, the equivalent variables ‘SOGI_v.vin’, ‘SOGI_v.vin_n1’, and ‘SOGI_v.vin_n2’ are handled differently. SOGI_v.vin is assigned the input variable ‘vin’ before ‘SOGI_v.vin_n1’ and ‘SOGI_v.vin_n2’ have been assigned. This makes the initial state of the variables different and hence leading to the wrong result.

SOGI_v.vin = vin; %Assigned before SOGI_v.vin_n1 and SOGI_v.vin_n2

SOGI_v.d0 = (4 + 2 * K * Ts * w + (w * w * Ts * Ts));

d0 = (4 + (2 * K * Ts * w) + (w * w * Ts * Ts));

SOGI_v.b1 = (-8 + (2 * w * w * Ts * Ts)) / SOGI_v.d0;

SOGI_v.b2 = ((4 - (2 * K * Ts * w) + (w * w * Ts * Ts))) / SOGI_v.d0;

SOGI_v.a_alpha = (2 * K * Ts * w) / SOGI_v.d0;

SOGI_v.a_beta = (K * w * w * Ts * Ts) / SOGI_v.d0;

b1 = (-8 + (2 * w * w * Ts * Ts)) / (4 + (2 * K * Ts * w) + (w * w * Ts * Ts));

b2 = ((4 - (2 * K * Ts * w) + (w * w * Ts * Ts))) / (4 + (2 * K * Ts * w) + (w * w * Ts * Ts));

a1 = (2 * K * Ts * w) / (4 + (2 * K * Ts * w) + (w * w * Ts * Ts));

SOGI_v.vin_n2 = SOGI_v.vin_n1; %Initially zero

SOGI_v.vin_n1 = SOGI_v.vin; %Not initially zero as vin is already assigned

To fix the issue, just write the assignment of ‘SOGI_v.vin’ after assigning ‘SOGI_v.vin_n2’ and ‘SOGI_v.vin_n1’ and it should give the correct result.

댓글 수: 0

이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

이 질문에 답변하려면 로그인하십시오.

참고 항목

카테고리

Code GenerationEmbedded CoderDeployment, Integration, and Supported HardwareEmbedded Coder Supported HardwareTexas Instruments C2000 Processors

Help CenterFile Exchange에서 Texas Instruments C2000 Processors에 대해 자세히 알아보기

태그

  • s-function
  • simulink
  • code
  • matlab coder
  • matlab function
  • embedded coder

제품

  • Simulink
  • Embedded Coder
  • MATLAB Coder

릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

오류 발생

페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.


Translated by Wrong output with MATLAB S Function (5)

Wrong output with MATLAB S Function (6)

웹사이트 선택

번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:

또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.

미주

  • América Latina (Español)
  • Canada (English)
  • United States (English)

유럽

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

아시아 태평양

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

지역별 지사에 문의

Wrong output with MATLAB S Function (2024)
Top Articles
Arooj Aftab | Meet The First-Time GRAMMY Nominee | GRAMMY.com
Jetsonmade On Producing “Suge” With Dababy & What Makes A Great Record | Behind The Board | GRAMMY.com
Ilovepersuasian
Bad Moms 123Movies
Keanu Reeves cements his place in action genre with ‘John Wick: Chapter 4’
Coolmathgames.comool Math
Pa Pdmp Log In
Trey Yingst Parents Nationality
Culver's Flavor Of The Day Paducah Ky
Myhr North Memorial
Stellaris Mid Game
Sevita Sso Login
Tabdil Tarikh
Lesson 10 Homework 5.3
The Closest Dollar Store To My Location
Stephjc Forum
Craigslist Manhattan Ks Personals
SEBO (UK) Ltd on LinkedIn: #sebouk #commercialcleaning #cleaning #floorcleaning #carpetcleaning
Gcfysl
Watch The Lovely Bones Online Free 123Movies
Jeff Danker Net Worth
Missoula Jail Releases
Language levels - Dutch B1 / 2 –What do these language levels mean? - Learn Dutch Online
Women On Twitch Go Without Makeup To Support A Fellow Streamer
Game8 Genshin Impact
Poskes Parts
Does Iherb Accept Ebt
Myrtle Beach Armslist
Central Valley growers, undocumented farmworkers condemn Trump's 'emergency'
Basis Independent Brooklyn
فیلم 365 روز 1 نیکی مووی
Strange World Showtimes Near Amc Hoffman Center 22
631 West Skyline Parkway, Duluth, MN 55806 | Compass
9 best hotels in Atlanta to check out in 2023 - The Points Guy
Finastra Gfx
Miracle Child Brandon Lake Chords
Bloxburg Bedroom Ideas That Will Make Your Kid's Jaw Drop
Central Valley growers, undocumented farmworkers condemn Trump's 'emergency'
Limestone Bank Hillview
Erie Pa Craigslist
Trizzle Aarp
Optum Director Salary
Rockin That Orange Jumpsuit Columbia County
How Old Is Ted Williams Fox News Contributor
8 Common Things That are 7 Centimeters Long | Measuringly
Plusword 358
Russia Ukraine war live: Starmer meets Biden at White House but no decision on Ukraine missiles
Order Irs Tax Forms Online
Salons Open Near Me Today
Basketball Stars Unblocked Games Premium
Find Such That The Following Matrix Is Singular.
Penn Highlands Mon Valley | Penn Highlands Healthcare
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 6313

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.