Request help with out of memory error tia sal22

Discussion in 'MATLAB' started by Rick T, Sep 2, 2010.

  1. Rick T

    Rick T Guest

    Greetings All

    I can get this matalb script to work and plot when I set
    x=linspace(0,1,100);
    But when I set x=linspace(0,1,44100); I get a mtimes out of memory
    which I narrowed down to the large array size in the C and S variables

    Can someone recommend a way for this code to work without running
    into memory errors? The plot looks great I just would like to:
    1) not have a memeory error issue if I put x=linspace(0,1,44100); or
    another large number in thier.
    2) Would like to compare the the y array to the ynew array and get a
    percentage of error is this possible?

    See working code below:

    clear
    clc
    t1 = tic; %start timer to see how long it takes to process

    %
    % DFT in a compact implementation using matrix math faster
    %
    % Enter Data in y
    x=linspace(0,1,100);
    wt=2*pi*x;
    y=sin(wt)+cos(2*wt);


    N=length(y);
    % Compute the matrices of trigonometric functions
    p=1:N/2+1;
    n=1:N;
    C=cos(2*pi*n'*(p-1)/N);
    S=sin(2*pi*n'*(p-1)/N);
    % Compute Fourier Coefficients
    An=2/N*y*C;
    Bn=2/N*y*S;

    An(N/2+1)=An(N/2+1)/2;
    % Reconstruct Signal - pmax is number of frequencies used in
    increasing order

    %pmax=5; %should be all the columns in C or S or less to decrease
    equation
    pmax=(size(An,2));

    ynew=An(1)/2+C:),2:pmax)*An(2:pmax)'+S:),2:pmax)*Bn(2:pmax)';


    % % Plot Data
    plot(x,y,'r')
    % Plot reconstruction over data
    hold on
    plot(x,ynew,'g*')
    hold off
    toc(t1) %stops timer and tells how long it took to run
     
    Rick T, Sep 2, 2010
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.