WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

convolution without conv. result is wrong amplitude&shif

 

zxzzxz
Forum-Newbie

Forum-Newbie


Beiträge: 2
Anmeldedatum: 02.05.16
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 02.05.2016, 19:26     Titel: convolution without conv. result is wrong amplitude&shif
  Antworten mit Zitat      
hello everyone , i just wrote my matlab code and it appears to be right (2 rectangles convoluted), the only problem i get is that i should have as a result : triangle centered at the 0 point width = 2 and amplitude of 4 . the result i get is shifted and has 4000 amplitude. i also implemented the ready to use conv. function , and it gives me the right answer . please help me correcting my code to match the resuld of the conv. function.
the matlab code is in the rar file .
thanks allot

Code:
clear all
    n=-5:0.001:5;
    m=-5:0.001:5;
    x = 2*rectangularPulse(n - 0.5);
    h = 2*rectangularPulse(m + 0.5);  
    y=0.001.*conv(x,h,'same');
    plot(n, y)
    axis([-2 4 0 5])
    title('Convolution with conv function');
    [Y,N] = convolution3(x,n,h,m);
    figure
    plot(n,x);
    axis([-2 4 0 5])
    title('x[n]');
    figure
    plot(m,h);
    axis([-2 4 0 5])
    title('h[n]');
    figure
    plot(N,Y);
    title('Y[n] Convolution without conv function');
  end


and this is the convolution function :

Code:
function [YY,NN] = convolution3(x,n,h,m)
  N = length(n);
  M = length(m);
    tstart = min(min(n), min(m));
    NN = tstart : tstart + N+M-2;
    for i= 0 : length(NN)-1
    YY(i+1) = 0;
    k=0;
    while i-k >=0
        if(k+1<=N)&&(i-k+1<=M)
           YY(i+1) = YY(i+1) + x(k+1)*h(i-k+1);
        end
        k = k+1;
    end
    end
    end
  end


[EDITED, Jan, Cross-posting: http://www.mathworks.com/matlabcent.....d-and-has-wrong-amplitude ]

matlab_conv.rar
 Beschreibung:

Download
 Dateiname:  matlab_conv.rar
 Dateigröße:  561 Bytes
 Heruntergeladen:  354 mal
Private Nachricht senden Benutzer-Profile anzeigen


Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 03.05.2016, 08:56     Titel: Re: convolution without conv. result is wrong amplitude&
  Antworten mit Zitat      
Dear zxzzxz,

Please do not cross-post a question in different forums, because this wastes the time of the vountary helpers, if they pos an answer which has given by someone else already.
If you have a good reason for cross-posting, meantion this at least and add links to the other thread. Thanks.

You can compare your result with many other published solutions for the same problem. Please ask your favorite search engine for "Matlab convolution without conv".

Kind regards, Jan
Private Nachricht senden Benutzer-Profile anzeigen
 
zxzzxz
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 2
Anmeldedatum: 02.05.16
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 09.05.2016, 21:33     Titel:
  Antworten mit Zitat      
Dear moderator , please delete my Question and code.

thanks allot.
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.