フィルターのクリア

How to save the previous figure generated by function'step(H,x)'

6 ビュー (過去 30 日間)
Yuqi Meng
Yuqi Meng 2019 年 10 月 9 日
回答済み: Honglei Chen 2019 年 10 月 9 日
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');

回答 (2 件)

Jon
Jon 2019 年 10 月 9 日
編集済み: Jon 2019 年 10 月 9 日
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

Honglei Chen
Honglei Chen 2019 年 10 月 9 日
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

カテゴリ

Help Center および File ExchangeTest and Measurement についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by