Wrong output with MATLAB S Function (2024)

26 visualizzazioni (ultimi 30 giorni)

Mostra commenti meno recenti

AYYAPPA RUDRASIMHA il 28 Ago 2024 alle 13:06

  • Link

    Link diretto a questa domanda

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

  • Link

    Link diretto a questa domanda

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

Risposto: Divyajyoti Nayak il 30 Ago 2024 alle 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 Commenti

Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Accedi per rispondere a questa domanda.

Risposte (1)

Divyajyoti Nayak il 30 Ago 2024 alle 7:27

  • Link

    Link diretto a questa risposta

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

  • Link

    Link diretto a questa risposta

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

Apri in 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 Commenti

Mostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Accedi per rispondere a questa domanda.

Vedere anche

Categorie

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

Scopri di più su Texas Instruments C2000 Processors in Help Center e File Exchange

Tag

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

Prodotti

  • Simulink
  • Embedded Coder
  • MATLAB Coder

Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Si è verificato un errore

Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.


Translated by Wrong output with MATLAB S Function (5)

Wrong output with MATLAB S Function (6)

Seleziona un sito web

Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .

Puoi anche selezionare un sito web dal seguente elenco:

Americhe

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

Asia-Pacifico

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

Contatta l’ufficio locale

Wrong output with MATLAB S Function (2024)
Top Articles
Wo man in Los Angeles Stars begegnen kann!
Los Angeles: Sightseeing in der Stadt der Engel
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Dirt Devil Ud70181 Parts Diagram
Truist Bank Open Saturday
Water Leaks in Your Car When It Rains? Common Causes & Fixes
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
Drys Pharmacy
Ohio State Football Wiki
Find Words Containing Specific Letters | WordFinder®
FirstLight Power to Acquire Leading Canadian Renewable Operator and Developer Hydromega Services Inc. - FirstLight
Webmail.unt.edu
2024-25 ITH Season Preview: USC Trojans
Metro By T Mobile Sign In
Restored Republic December 1 2022
12 30 Pacific Time
Jami Lafay Gofundme
Greenbrier Bunker Tour Coupon
No Compromise in Maneuverability and Effectiveness
Black Adam Showtimes Near Cinemark Texarkana 14
Teamnet O'reilly Login
U-Haul Hitch Installation / Trailer Hitches for Towing (UPDATED) | RV and Playa
Minute Clinic Schedule 360
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 6311

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.