Dealing with large matrices in compressive sensing
14 次查看(过去 30 天)
显示 更早的评论
Following code demonstrates compressive sensing. The length of the input signal x used is N =1024 samples. The size of the DFT matrix B would be N^2. But once the signal length is large, say 214688, the DFT matrix (B = dftmtx (N)) becomes too large and the system runs out of memory. Is there a efficient way to generate this matrix and manipulate it? I need this matrix to generate the measurement matrix A by randomly selecting K number of rows from B and also to take time measurements y = (A * fft(x)).
%Author: Osama Ullah Khan,
% Phd Student, University of Michigan-Ann Arbor.
% Email: oukhan@umich.edu
% Version: 1.0
%
%This code demonstrate compressive sensing example. In this
%example the signal is sparse in frequency domain and random samples
%are taken in time domain.
close all;
clear all;
%length of the signal
N=1024;
%Number of random observations to take
K=256;
%Discrete frequency of two sinusoids in the input signal
k1=29;
k2=100;
n=0:N-1;
%Sparse signal in frequency domain.
x=sin(2*pi*(k1/N)*n)+sin(2*pi*(k2/N)*n);
figure;
subplot(2,1,1);
plot(x)
grid on;
xlabel('Samples');
ylabel('Amplitude');
title('Original Signal,1024 samples with two different frequency sinsuoids');
xf=fft(x);
subplot(2,1,2);
plot(abs(xf))
grid on;
xlabel('Samples');
ylabel('Amplitude');
title('Frequency domain, 1024 coefficients with 4-non zero coefficients');
%creating dft matrix
B=dftmtx(N);
Binv=inv(B);
%Selecting random rows of the DFT matrix
q=randperm(N);
%creating measurement matrix
A=Binv(q(1:K),:);
%taking random time measurements
y=(A*xf);
% %Calculating Initial guess
% x0=A'*y;
%
% %Running the recovery Algorithm
% tic
% xp=l1eq_pd(x0,A,[],y,1e-5);
% toc
% cvx_begin
% variable xp(N)
% minimize( norm( xp, 1 ) )
% subject to
% y == A * xp;
% cvx_end
% [xp,r,g,info] = spg_bp(A,y );
%
% %recovered signal in time domain
% xprec=real(Binv*xp);
%
% figure;
% subplot(2,1,1)
% plot(abs(xf))
% grid on;
% xlabel('Samples');
% ylabel('Amplitude');
% title('Original Signal, Discrete Fourier Transform');
%
% subplot(2,1,2)
% plot(abs(xp),'r')
% grid on;
% xlabel('Samples');
% ylabel('Amplitude');
% title(sprintf('Recovered Signal, Discrete Fourier Transform sampled with %d samples',K));
%
% figure;
% subplot(2,1,1);
% plot(x)
% grid on;
% xlabel('Samples');
% ylabel('Amplitude');
% title('Original Signal,1024 samples with two different frequency sinsuoids');
%
% subplot(2,1,2)
% plot(xprec,'r')
% grid on;
% xlabel('Samples');
% ylabel('Amplitude');
% title(sprintf('Recovered Signal in Time Domain'));
%
0 个评论
回答(1 个)
ahmed nebli
2018-9-1
u need to store your matrices in a .mat file, then call that .mat file using function called matfile, this function access and change variables directly in MAT-files, without loading into memory.
this would make you not loose the memory. for further informations see this link: https://www.mathworks.com/help/matlab/ref/matfile.html
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!