
function [recSig, peakFreqs, peakLocs]=signalReconstruction_(signal,param,iteration)

    if ~exist('iteration','var')
     % third parameter does not exist, so default it to something
        iter = 2;
    else
        iter = iteration;
    end
    
    signal = signal';
    N = param.samplerange;
    K = N; %round(2/3 * N);
    n = 0:N-1;
    t = linspace(param.startsec,param.endsec,N);
    Fs = param.Fs;
    f = (0:N-1)*Fs/N;
   
    %Representation basis
    Psi = dftmtx(N);
    Psi_inv = conj(Psi)/N;
    signal_fft = Psi*signal;

    % Obtain K measurements
    sig_m = zeros(N,1);
    q = randperm(N);
    q = q(1:K);
    sig_m(q) = signal(q);
   
    % sensing matrix
    A = Psi_inv(q,:);
    y = A*signal_fft;           %measured values

    [FFT_recSig] = OMP_(A,y,iter);
    
    recSig = real(Psi_inv*FFT_recSig); %IFFT of FFT_recSig

    signal_fft = signal_fft(1:N/2+1);
    FFT_recSig = FFT_recSig(1:N/2+1);
    f = f(1:N/2+1);

    [peakFreqs, peakLocs] = findpeaks(abs(FFT_recSig),f);

    figure;
    subplot(4,1,1)
    plot(t,signal)
    title("Original Signal")
    xlabel("time(s)")

    subplot(4,1,2)
    plot(f,abs(signal_fft))
    title("Original Signal FFT")
   % xlim([0 param.Fs/2])
    xlabel("Frequency(Hz)")
    
    subplot(4,1,3)
    plot(f,abs(FFT_recSig))
    title("Reconstructed Signal FFT")
   % xlim([0 Fs/2])
    xlabel("Frequency(Hz)")
    
    subplot(4,1,4)
    plot(t,recSig)
    title("Reconstructed Time Signal")
    xlabel("time(s)")

    figure
    title("Signal Reconstruction CS-OMP")
    subplot(2,1,1)
    plot(t,signal,"b")
    hold on
    plot(t,recSig,'r',LineWidth=1)
    legend("Original Signal","CS-OMP Reconstructed Signal")
    xlabel("time(s)")
    hold off
    subplot(2,1,2)
    plot(f,abs(signal_fft),'b')
    hold on
    plot(f,abs(FFT_recSig),'r',LineWidth=1)
    legend("Original Signal FFT","CS-OMP Reconstructed Signal FFT")
    xlabel("Frequency(Hz)")
    
    
end
