Wrong output with MATLAB S Function (2024)

26 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

AYYAPPA RUDRASIMHA am 28 Aug. 2024 um 13:06

  • Verknüpfen

    Direkter Link zu dieser Frage

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

  • Verknüpfen

    Direkter Link zu dieser Frage

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

Beantwortet: Divyajyoti Nayak am 30 Aug. 2024 um 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 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Antworten (1)

Divyajyoti Nayak vor etwa 24 Stunden

  • Verknüpfen

    Direkter Link zu dieser Antwort

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

  • Verknüpfen

    Direkter Link zu dieser Antwort

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

In MATLAB Online öffnen

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 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

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

Mehr zu Texas Instruments C2000 Processors finden Sie in Help Center und File Exchange

Tags

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

Produkte

  • Simulink
  • Embedded Coder
  • MATLAB Coder

Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Wrong output with MATLAB S Function (5)

Wrong output with MATLAB S Function (6)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

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

Europa

  • 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)

Asien-Pazifik

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

Kontakt zu Ihrer lokalen Niederlassung

Wrong output with MATLAB S Function (2024)
Top Articles
Las Vegas NV Real Estate - Las Vegas NV Homes For Sale | Zillow
Coin Master Links und Belohnungen für Spins und Münzen!
Bolongaro Trevor Backpack
Tears Of The Fallen Moon Bdo
Climate change, eroding shorelines and the race to save Indigenous history - The Weather Network
Elektrisch koffiezetapparaat Philips CSA240/61 1450 W Zwart 1450 W | bol
Academic Calendar Biola
Iapd Lookup
Financial Literacy for Students | EVERFI
Hudson River Regional Conference Inc. · 112-14 107th ave., South Richmond Hill, NY 11419
Lucio Surf Code
Anchoring in Masonry Structures – Types, Installation, Anchorage Length and Strength
My Scheduler Hca Cloud
Premier Auto Works-- The House Of Cash Car Deals
Central Nj Craiglist
60 Days From May 31
Army Dlc 1 Cheat
Kuronime List
Fk Jones Obituary
Does Publix Have Sephora Gift Cards
Her Triplet Alphas Chapter 22
Eurail Pass Review: Is It Worth the Price?
Hartford Healthcare Employee Tools
Bay State Neurology
Importing Songs into Clone Hero: A Comprehensive Tutorial
About Us - Carrols Corporation
Fingerhut Teleflora Promo Code
The Anthem Tonight
Myhr North Memorial
Ridgid Pro Tool Storage System
Blairsville Online Yard Sale
Petco Clinic Hours
Wells Fargo Hiring Hundreds to Develop New Tech Hub in the Columbus Region
How To Create A Top Uber Boss Killer In POE 3.25 League?
Flixtor The Meg
Dvax Message Board
Rwby Crossover Fanfiction Archive
80 For Brady Showtimes Near Brenden Theatres Kingman 4
Brgeneral Patient Portal
Ups Store.near Me
Hood County Buy Sell And Trade
600 Aviator Court Vandalia Oh 45377
Dinar Guru Recaps Updates
Pge Set Up Service
Parx Entries For Today
Ts Massage San Jose Ca
168 Bus Schedule Pdf 2022
manhattan cars & trucks - by owner - craigslist
Car Hire in Romania from £4/day - Search for car rentals on KAYAK
Perolamartinezts
Lharkies
What stores are open on Labor Day 2024? A full list of where to shop
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6305

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.