How to save the previous figure generated by function'step(H,x)'
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
When I use the function 'step' to generate multiple figures the most recent one will automatically covers the previous figure generated by 'step' the function 'figure(n)' doesn't seem to be working under this scenerio.
Note that in the following code 'step' to create figure was used twice but only one figure could be generated the usual function 'figure' doesn't seem to work.
clear all vars
clc
fs = (5/2)*1e6; % Symbol rate (Hz)
fc=8*1e6;% carrier frequency to modulate on
N_sample=8;;%sample rate for modulation
Ts=1/fs;
O_data=randi([0 1],1000,1);
mod=comm.BPSKModulator;%create the modulator object
O_P=step(mod,O_data);%modulate the data employing BPSK method
cd = comm.ConstellationDiagram(...
'ReferenceConstellation',constellation(mod), ...
'XLimits',[-5 5],'YLimits',[-5 5]);
Txraise=comm.RaisedCosineTransmitFilter('Shape','Square root','RolloffFactor',...
0.4,'OutputSamplesPerSymbol',N_sample,'Gain',1);%generate the raised cosin filter object
Txdata=step(Txraise,O_P);
Txdata1=modulate(Txdata,fc,N_sample*fs,'am');%modulate the transmitted signal onto the carrier frequency
[F1,P1]=tospec(Txdata1,fs,N_sample);
figure(1)
plot(F1,P1);
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Sectrum of the signal before transmission');
step(cd,Txdata1);
chan1=comm.AWGNChannel('NoiseMethod','Signal to noise ratio (SNR)','SNR',15);%create the AWGN channel object with specified SNR
Txdata2=step(chan1,Txdata1);%passing the signal through channel
step(cd,Txdata2);
figure(2)
[F2,P2]=tospec(Txdata2,fs,N_sample);
plot(F2,P2);
xlabel('Frequency(Hz)');
ylabel('Amplitude')
title('spectrum of the signal at the AWGN channel output');
0 comentarios
Respuestas (2)
Jon
el 9 de Oct. de 2019
Editada: Jon
el 9 de Oct. de 2019
You need to create a new figure just before calling step
clear all vars
clc
fs = (5/2)*1e6; % Symbol rate (Hz)
fc=8*1e6;% carrier frequency to modulate on
N_sample=8;;%sample rate for modulation
Ts=1/fs;
O_data=randi([0 1],1000,1);
mod=comm.BPSKModulator;%create the modulator object
O_P=step(mod,O_data);%modulate the data employing BPSK method
cd = comm.ConstellationDiagram(...
'ReferenceConstellation',constellation(mod), ...
'XLimits',[-5 5],'YLimits',[-5 5]);
Txraise=comm.RaisedCosineTransmitFilter('Shape','Square root','RolloffFactor',...
0.4,'OutputSamplesPerSymbol',N_sample,'Gain',1);%generate the raised cosin filter object
Txdata=step(Txraise,O_P);
Txdata1=modulate(Txdata,fc,N_sample*fs,'am');%modulate the transmitted signal onto the carrier frequency
[F1,P1]=tospec(Txdata1,fs,N_sample);
% make a new figure before plotting spectrum
figure(1)
plot(F1,P1);
xlabel('Frequency(Hz)');
ylabel('Amplitude');
title('Sectrum of the signal before transmission');
% make a new figure before plotting step response
figure(2)
step(cd,Txdata1);
chan1=comm.AWGNChannel('NoiseMethod','Signal to noise ratio (SNR)','SNR',15);%create the AWGN channel object with specified SNR
Txdata2=step(chan1,Txdata1);%passing the signal through channel
% make a new figure before plotting step response
figure(3)
step(cd,Txdata2);
% make a new figure before plotting spectrum
figure(4)
[F2,P2]=tospec(Txdata2,fs,N_sample);
plot(F2,P2);
xlabel('Frequency(Hz)');
ylabel('Amplitude')
title('spectrum of the signal at the AWGN channel output');
By the way, for future posts you can nicely format your code by using the code button in the MATLAB answers toolbar
0 comentarios
Honglei Chen
el 9 de Oct. de 2019
The constellation diagram is workig as expected. The object enables you to overwrite the plot over time so you can see how the constellation changes during simulation. If you want to plot static constellation diagrams, you can consider using scatterplot
Here is a reference page that may help
HTH
0 comentarios
Ver también
Categorías
Más información sobre Test and Measurement en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!